Repository navigation
Expand file tree
/
Copy pathpostgresql.conf
More file actions
70 lines (59 loc) · 3.03 KB
/
Copy pathpostgresql.conf
File metadata and controls
70 lines (59 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Production Postgres tuning for Portfolio.
#
# Target host: 2 vCPU / 4 GB DigitalOcean droplet, running Postgres alongside
# Puma, Sidekiq, Redis AND a second application ("help"). Budget accordingly —
# these are deliberately below the usual single-purpose-database guidance.
#
# Prod runs PostgreSQL 9.5, which has no conf.d include. Append this block to
# the END of /etc/postgresql/9.5/main/postgresql.conf; later settings win, so
# it overrides the stock values above it.
#
# Baseline before this file (all stock since the 2016 install):
# shared_buffers 128MB · work_mem 4MB · effective_cache_size 4GB
# random_page_cost 4 · checkpoint_completion_target 0.5
# shared_preload_libraries (empty) · cache hit ratio 32.6%
# --- Requires a full restart (brief downtime) --------------------------------
# 128MB could not hold the working set, so every large scan evicted the whole
# cache. 512MB rather than the usual 25%-of-RAM because this box is shared.
shared_buffers = 512MB
# The extension was already installed and pghero is in the Gemfile, but the
# library was never preloaded, so there has never been any query-level
# visibility in production (and CaptureQueryStatsWorker sits commented out
# because of it).
shared_preload_libraries = 'pg_stat_statements'
# --- Reload is enough (no downtime) ------------------------------------------
# 4MB forced large sorts and bitmap scans to spill; production had accumulated
# 515GB of temp files and was producing lossy bitmap scans. Per sort node per
# connection, so this stays modest given ~15-20 real connections.
work_mem = 16MB
# Speeds up VACUUM and index builds. Bounded by autovacuum_max_workers (3).
maintenance_work_mem = 128MB
# Planner hint only, no allocation. 4GB was optimistic on a host that shares
# its RAM with two app servers.
effective_cache_size = 2GB
# The stock 4 assumes spinning rust and pushed the planner toward sequential
# scans. This is SSD-backed.
random_page_cost = 1.1
effective_io_concurrency = 200
# Spread checkpoint writes across the interval instead of bunching them into
# short bursts — these bursts are the visible "occasional spikes".
checkpoint_completion_target = 0.9
pg_stat_statements.track = all
pg_stat_statements.max = 5000
# --- Apply -------------------------------------------------------------------
#
# sudo cp /etc/postgresql/9.5/main/postgresql.conf{,.bak-$(date +%F)}
# sudo tee -a /etc/postgresql/9.5/main/postgresql.conf < postgresql.conf
# sudo systemctl restart postgresql # required for the two settings above
#
# Verify:
# SELECT name, setting FROM pg_settings
# WHERE name IN ('shared_buffers','work_mem','random_page_cost',
# 'shared_preload_libraries');
#
# Then re-enable the PgHero capture job in config/initializers/sidekiq_cron.rb.
#
# NOTE: PostgreSQL 9.5 has been end-of-life since February 2021. It has no
# parallel query, no declarative partitioning, and a materially weaker planner
# than anything current. Upgrading is the single highest-value follow-up here;
# everything above is tuning within what 9.5 can do.