Privacy Policy
Snippets index

  Optimize Postgresql settings

Test default settings

Example:

$ sudo -u postgres psql -c "show max_connections"
 max_connections
-----------------
 100
(1 row)

Generate optimized config parameters

from https://pgtune.leopard.in.ua/:

# DB Version: 9.6
# OS Type: linux
# DB Type: web
# Total Memory (RAM): 16 GB
# Number of Connections: 10

max_connections = 10
shared_buffers = 4GB
effective_cache_size = 12GB
maintenance_work_mem = 1GB
min_wal_size = 1GB
max_wal_size = 2GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 200
max_worker_processes = 4
max_parallel_workers_per_gather = 2
work_mem = 209715kB

Apply new parameters

Copy parameters to file /etc/postgresql/9.6/main/conf.d/optimize.conf, then:

# sudo service postgresql restart

Test new settings

Example:

$ sudo -u postgres psql -c "show max_connections"
 max_connections
-----------------
 10
(1 row)