Here are some setting recommendations about checkpoints, some values to set in postgresql.conf. A checkpoint consists of a complete flush of dirty buffers to disk, so it potentially generates a lot of I/O. The performance of your system will be impacted in those cases:
- A particular number of WAL segments have been written
- Timeout occurs
Here are some settings.
wal_buffers = 16MB checkpoint_completion_target = 0.9 checkpoint_timeout = 10m-30m # Depends on restart time checkpoint_segments = 32 # As a start value
Then, as a setting refinement, check if checkpoints happen more often than checkpoint_timeout,
adjust checkpoint_segments so that checkpoints happen due to timeouts rather filling segments.
Also, do not forget that WAL can take up to 3 * 16MB * checkpoint_segments on disk, and that restarting
PostgreSQL can take up to checkpoint_timeout (but usually less).
General
Logging has little impact on the system, so even large values are OK. Good source of information to find
performance bottlenecks and tune the system. Preferential settings for logging information in postgresql.conf.
Place where to log, they depend on the system and external tools you are using with your system.
- syslog
- standard format to files, you might be using tools for standard formats
- CVS format to files
Some parameters to use.
log_destination = 'csvlog'
log_directory = 'pg_log'
logging_collector = on
log_filename = 'postgres-%Y-%m-%d_%H%M%S'
log_rotation_age = 1d
log_rotation_size = 1GB
log_min_duration_statement = 200ms
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
syslog
When using syslog-ng, set up those parameters in /etc/syslog-ng/syslog-ng.conf.
destination postgres { file("/var/log/pgsql"); };
filter f_postgres { facility(local0); };
log { source(src); filter(f_postgres); destination(postgres); };
Then set those parameters in postgresql.conf.
log_destination = 'stderr,syslog' # Can specify multiple destinations
syslog_facility='LOCAL0'
syslog_ident='postgres'
Then reload parameters (no restart necessary).
pg_ctl reload -D $PGDATA
Here is a list of recommended parameters for memory management in PostgreSQL.
You should take into account mainly the following parameters.
shared_buffers
work_mem
maintenance_work_mem
effective_cache_size
About shared_buffers:
- Below 2GB, set to 20% of total system memory.
- Below 32GB, set to 25% of total system memory.
- Above 32GB, set to 8GB
About work_mem, this parameter can cause a huge speed-up if set properly,
however it can use that amount of memory per planning node. Here are some
recommendations to set it up.
- Start low: 32-64MB
- Look for ‘temporary file’ lines in logs
- Set to 2-3x the largest temp file
About maintenance_work_mem, here are some recommandations:
- 10% of system memory, up to1GB
- Maybe even higher if you are having VACUUM problems
About effective_cache_size, here are some guidelines.
- Set to the amount of file system cache available
- If you don’t know, set it to 50% of total system memory
Here are a couple of tips for planner settings.
- effective_io_concurrency, set to the number of I/O channels or ignore it
- random_page_cost
- 3.0 for a typical RAID10 array
- 2.0 for a SAN
- 1.1 for Amazon EBS
http://michael.otacoo.com/manuals/postgresql/