shared_buffers
Size of PostgreSQL's own page cache, shared by all sessions.
- 默认
128MB- Range
- 128kB to about 8TB, in 8kB pages (minimum 16 pages)
- Restart needed
- 是
- Default checked on
- PostgreSQL 18
作用
Every table and index page is read through shared buffers. PostgreSQL also relies on the OS page cache, so a page can be cached twice; that is why the usual starting point is about 25% of RAM rather than most of it. The value is allocated at startup as one shared memory segment.
默认值
128MB. Compiled-in default is 128MB (PostgreSQL 18); initdb writes 128MB into postgresql.conf, or less if the machine's shared memory is too small. The official Docker image keeps 128MB.
Check the current value
SHOW shared_buffers; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'shared_buffers';
Change it
ALTER SYSTEM SET shared_buffers = '4GB'; -- applies only after a server restart
Server restart required (pg_settings.context is postmaster). ALTER SYSTEM only stages the new value in postgresql.auto.conf.
When to change it
Almost always, on any server with more than a couple of GB of RAM. Start at 25% of RAM on a dedicated host, then compare the buffer hit ratio in pg_stat_database and pg_statio_user_tables before going much higher.
What can go wrong
Too large leaves little room for the OS cache and per-query work_mem, and checkpoints have more dirty pages to write. Above roughly 8-16GB, enable huge pages or the page tables themselves get expensive.
The closest setting on other engines
| 引擎 | 设置项 | 默认 | Restart |
|---|---|---|---|
| PostgreSQL |
shared_buffers this page
|
128MB |
是 |
| MySQL |
innodb_buffer_pool_size
|
128MB |
否 |
| SQL Server |
max server memory (MB)
|
2147483647 |
否 |
| Oracle |
sga_target
|
0 |
否 |
| SQLite |
cache_size
|
-2000 (about 2MB) |
否 |
Questions about shared_buffers
What is the default value of shared_buffers in PostgreSQL?
128MB. Compiled-in default is 128MB (PostgreSQL 18); initdb writes 128MB into postgresql.conf, or less if the machine's shared memory is too small. The official Docker image keeps 128MB.
Does changing shared_buffers require a restart?
Yes. Server restart required (pg_settings.context is postmaster). ALTER SYSTEM only stages the new value in postgresql.auto.conf.
When should I change shared_buffers?
Almost always, on any server with more than a couple of GB of RAM. Start at 25% of RAM on a dedicated host, then compare the buffer hit ratio in pg_stat_database and pg_statio_user_tables before going much higher.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check shared_buffers on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.