shared_buffers reserves shared memory for PostgreSQL buffers: blocks read from disk and blocks used in operations. The 128 MB default is a portable baseline meant to start on small machines, not a production sizing decision. Change it only as part of testing or staging for the actual server and workload; PostgreSQL must be restarted before a changed value takes effect. section 6.1
More buffer memory can help, but bigger is not automatically better. Memory settings interact: shared_buffers is shared, while work_mem is available to individual operations and maintenance_work_mem serves work such as CREATE INDEX and VACUUM. Treat a configuration as a budget rather than independently maximizing each setting. section 6.1 section 6.2
Measure a realistic restore
A pgbench database dump restored in 44m15s under default settings. After setting shared_buffers to 3GB, work_mem to 128MB, and maintenance_work_mem to 512MB, then restarting, the same restore completed in 26m17s. The result supports testing a workload-specific configuration, but it does not isolate shared_buffers as the sole cause because three settings changed together. section 6.1
shared_buffers = 3GB #1 work_mem = 128MB #2 maintenance_work_mem = 512MB #3
This configuration listing shows a moderate combined adjustment. It is a benchmark input, not a universal recipe; validate it against available RAM and production-like load. section 6.1
An aggressive setting can fail to improve throughput. Raising shared_buffers to 12GB and work_mem to 2GB produced roughly the same 100-client pgbench throughput as the earlier configuration, then a 1,000-client stress test stalled and the Linux OOM killer terminated a PostgreSQL process. The danger is system-wide memory exhaustion under concurrency, with no guarantee that the kernel kills the process you expect. section 6.2 section 6.2
Use shared_buffers as an operationally tested allocation:
- Start from the default as a functional baseline, then test on staging or production-like hardware rather than assuming it is tuned. section 6.1
- Restart PostgreSQL after changing shared_buffers, then compare repeatable workload results such as restore duration or pgbench TPS. section 6.1 section 6.2
- Increase connection load separately when checking memory safety, and inspect server logs if the workload stalls or processes are killed. section 6.2
