I have a Ruby on Rails app that is using a Postgresql database. I've noticed that my database performance has huge spikes every 5-7 minutes.
I'm seeing 1+ second response times for simple queries like:
UPDATE users SET last_seen_at = ? where id = ?
or
INSERT INTO emails (email, created_at, updated_at) VALUES (?, ?, ?)
The VPS is an AWS EC2 instance (m2.2xlarge) with a 4 core Xeon 2.4ghz and 34gb of memory.
I made to following changes to the conf to try to figure it out (like reducing the # of checkpoint timeouts) to no avail.
root:/etc/postgresql/9.2/main# diff postgresql.conf.bck postgresql.conf
176,178c176,178
< #checkpoint_segments = 3 # in logfile segments, min 1, 16MB each
< #checkpoint_timeout = 5min # range 30s-1h
< #checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
---
> checkpoint_segments = 10 # in logfile segments, min 1, 16MB each
> checkpoint_timeout = 30min # range 30s-1h
> checkpoint_completion_target = 0.9 # checkpoint target duration, 0.0 - 1.0
361c361
< #log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements
---
> log_min_duration_statement = 2s # -1 is disabled, 0 logs all statements
370,371c370,371
< #debug_print_rewritten = off
< #debug_print_plan = off
---
> #debug_print_rewritten = on
> #debug_print_plan = on
376c376
< #log_duration = off
---
> #log_duration = on
378c378
< #log_hostname = off
---
> #log_hostname = on
399c399
< #log_lock_waits = off # log lock waits >= deadlock_timeout
---
> log_lock_waits = on # log lock waits >= deadlock_timeout
log_checkpoints=on
, lowerlog_min_duration_statement=250ms
or something like that, and compare when the occurrence of slow statements to the occurrence of checkpoints. Also, see what the time taken to sync the files on checkpoint is.