PostgreSQL Connection Tuning

February 13, 2026 | PostgreSQL Performance

Tune shared_buffers, work_mem by RAM.

Tuning PostgreSQL Memory and Connections

PostgreSQL's default configuration is conservative — designed to run on minimal hardware. Tuning memory settings based on your server's RAM and workload type can improve query performance by 2-5x.

Key Memory Parameters

ParameterDefaultRecommendedPurpose
shared_buffers128 MB25% of RAMShared cache for data pages
effective_cache_size4 GB75% of RAMPlanner's estimate of OS cache size
work_mem4 MB32-256 MBMemory per sort/hash operation
maintenance_work_mem64 MB512 MB - 2 GBMemory for VACUUM, CREATE INDEX
wal_buffers-1 (auto)64 MBWAL write buffer

Tuning by Server Size

16 GB RAM Server (Common for SMBs)

shared_buffers = 4GB
effective_cache_size = 12GB
work_mem = 64MB
maintenance_work_mem = 1GB
wal_buffers = 64MB
max_connections = 200

64 GB RAM Server (Production)

shared_buffers = 16GB
effective_cache_size = 48GB
work_mem = 128MB
maintenance_work_mem = 2GB
wal_buffers = 64MB
max_connections = 300

Connection Limits

Each connection uses ~10 MB of RAM. With max_connections = 200, that's 2 GB just for connections. For applications needing more than 200 concurrent connections, use PgBouncer for connection pooling instead of increasing max_connections.

work_mem Considerations

Warning: work_mem is allocated per-operation, not per-connection. A complex query with 5 sorts could use 5 × work_mem. Set it conservatively at the server level and increase per-session for analytics queries:

-- For an analytics session
SET work_mem = '512MB';
SELECT ... complex aggregation query ...;
RESET work_mem;

Eazy SaaS Tip: Use PGTune as a starting point for your server size, then adjust based on monitoring. Watch for temp_files in pg_stat_database — if high, increase work_mem.