Skip to content

Instantly share code, notes, and snippets.

@kirang89
Last active August 29, 2015 14:00
Show Gist options
  • Save kirang89/11193647 to your computer and use it in GitHub Desktop.
Save kirang89/11193647 to your computer and use it in GitHub Desktop.
Optimal Settings for Postgres

###Optimal Settings for Postgres

log_destination = 'csvlog'

log_directory = 'pg_log'

logging_collector = on (rotates files)

log_filename = 'postgres-%Y-%m-%d_%H%M%S'

log_rotation_age = 1d

log_rotation_size = 1GB

log_min_duration_statement = 250ms (log statements that take > 250ms to execute)

log_checkpoints = on

log_connections = on

log_disconnections = on

log_lock_waits = on (log when a lock waits more than 1 sec, which is the default values)

log_temp_files = 0 (log whenever temp files are created)

shared_buffers = 25% of memory to 8GB      # allocated at startup

work_mem = (2 * {RAM})/max_connections    # allocated on demand

maintenance_work_mem = {RAM}/16              # allocated on demand

effective_cache_size = {RAM}/2                        # allocated on demand

max_connections = no more than 400  

wal_buffers = 16MB

checkpoint_completion_target = 0.9

# Depends on restart time - higher values give better performance but does reduce the startup time for  # postgres for a dirty restart
checkpoint_timeout = 10m-30m 

checkpoint_segments = 32 # To start.

effective_io_concurrency — Set to the  number of I/O channels; otherwise, ignore  it.

random_page_cost — 3.0 for a typical  RAID10 array, 2.0 for a SAN, 1.1 for Amazon EBS.

# Needs pg_stat_statements extension. See extras section for setting it up
pg_stat_statements.max = 1000
pg_stat_statements.track = top # top,all,none
pg_stat_statements.save = off

###Extras Set the shared_preload_libraries to pg_stat_statements in postgresql.conf to help get some sweet analytics about queries on DB

shared_preload_libraries = 'pg_stat_statements'

#psql
create extension "pg_stat_statements";
select * from pg_stat_statements; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment