Skip to main content

Server Configuration Tuning

Learning Focus

Use this lesson to understand the PostgreSQL settings that most often affect performance and how to tune them safely.

Concept Overview​

Server tuning is workload-dependent. Start with:

  • the slow queries you identified
  • evidence from plans and metrics

Then adjust settings deliberately.


High-Impact Settings (Conceptual)​

SettingWhat it affectsTypical direction
shared_bufferscache for data pagesincrease carefully
work_memmemory per sort/hash operationincrease for complex queries
maintenance_work_memvacuum/index buildsincrease for maintenance
max_connectionsconcurrency limitkeep reasonable; use pooling
effective_cache_sizeplanner estimate of OS cacheset to realistic value
autovacuum settingsbloat/statstune for churny tables

Practical Workflow​

  1. Measure baseline (query times, CPU, I/O, locks).
  2. Change one setting at a time.
  3. Re-run representative workloads.
  4. Keep a rollback plan.

Autovacuum Notes​

Autovacuum is critical at scale:

  • it reclaims dead tuples
  • it updates statistics
  • it enables index-only scans

If autovacuum is not keeping up, you will see bloat and unstable plans.


Common Mistakes & Troubleshooting​

MistakeWhat happensFix
Setting work_mem too highMemory spikes under concurrencyConsider connection count and query mix
Increasing connections without poolingContext switching and memory wasteUse a pooler, keep max_connections sane
Ignoring autovacuumBloat and slow queriesMonitor and tune autovacuum

Best Practices​

  • Tune based on measurement, not defaults.
  • Use connection pooling.
  • Keep autovacuum healthy.
  • Document configuration changes.

Quick Reference​

SHOW shared_buffers;
SHOW work_mem;
SHOW max_connections;

What's Next​