Skip to content

Lesson 1 of 9 · 24m

Production Configuration: Memory, WAL, and Connections

The postgresql.conf settings that matter on day one, what the unit suffixes mean, and why max_connections is a capacity decision rather than a performance knob.

The first production Postgres outage I ever owned was not caused by a bug. It was caused by copying a tuning blog post into postgresql.conf without understanding the budget behind it. The database got faster for twenty minutes, then the kernel OOM killer shot a backend during a traffic spike.

Configuration is a budget: memory, disk flush behavior, and process count. Start conservative, measure, then change one thing at a time.

Edit deliberately, reload deliberately

shared_buffers = 4GB
effective_cache_size = 12GB
work_mem = 32MB
maintenance_work_mem = 512MB
max_connections = 200

ALTER SYSTEM writes postgresql.auto.conf, which is read after postgresql.conf and therefore wins. Some settings respond to SELECT pg_reload_conf(); shared_buffers and max_connections require a restart.

SELECT name, setting, unit, context, pending_restart
FROM pg_settings
WHERE name IN ('shared_buffers', 'work_mem', 'max_connections');

If pending_restart is true, the running server is not using the value you think it is.

Memory is shared, per-operation, and cache-aware

shared_buffers is PostgreSQL's own page cache; 25% of RAM is a common starting point on a dedicated host. effective_cache_size is a planner hint about PostgreSQL plus operating system cache, not allocated memory.

work_mem is the dangerous one. It is per sort or hash operation, not per connection. One query can allocate it several times, so 200 connections at 32 MB can become many gigabytes under the wrong plan.

WAL and checkpoints trade latency for recovery time

max_wal_size = 4GB
checkpoint_timeout = 10min
checkpoint_completion_target = 0.9
wal_compression = on

Write-ahead logging makes commits durable before data pages reach their final locations. A tiny max_wal_size causes frequent checkpoint spikes; huge values lengthen crash recovery. On modern versions, inspect pg_stat_checkpointer rather than guessing.

max_connections is a liability ceiling

Every connection is a process with memory, snapshot, and lock-management overhead. Thousands of mostly idle connections do not create scalability; they create context switching. Size max_connections for real concurrency, then put a pooler in front when applications need more sockets.

Field notes

  • Reserve memory for connections, WAL buffers, the operating system, and monitoring agents before tuning shared memory upward.
  • effective_cache_size does not allocate RAM, but it can change query plans.
  • work_mem explosions often appear first as OOM killer lines in dmesg.
  • Configuration management does not automatically control postgresql.auto.conf; audit both files.
  • Record why every non-default exists. Six months later, nobody remembers which blog post owned it.

Was this lesson helpful?

Sign in to rate