bgwriter_delay
Time between rounds of the background writer, which cleans buffers ahead of other sessions.
- 預設
200ms- Range
- 1ms to 10s
- Restart needed
- 否
- Default checked on
- PostgreSQL 18
其作用
Each round the background writer writes dirty buffers picked from behind the clock-sweep hand, then sleeps this long; when it finds nothing dirty it sleeps longer regardless. bgwriter_lru_maxpages bounds what it writes per round.
預設值
200ms. 200ms (PostgreSQL 18).
Check the current value
SHOW bgwriter_delay; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'bgwriter_delay';
Change it
ALTER SYSTEM SET bgwriter_delay = '500ms'; SELECT pg_reload_conf();
No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).
When to change it
Rarely. Compare buffers_backend with buffers_clean in pg_stat_bgwriter: when backends write most buffers themselves, a shorter delay or larger bgwriter_lru_maxpages shifts some of that work off the query path.
What can go wrong
Too short burns CPU on rounds that find little to write; too long leaves backends writing their own buffers and adds latency to their queries. It is not the checkpoint writer: checkpoints flush their own bulk, so this cannot fix checkpoint I/O spikes.
Questions about bgwriter_delay
What is the default value of bgwriter_delay in PostgreSQL?
200ms. 200ms (PostgreSQL 18).
Does changing bgwriter_delay require a restart?
No. No restart: reload with SELECT pg_reload_conf() or pg_ctl reload. It cannot be changed per session (context is sighup).
When should I change bgwriter_delay?
Rarely. Compare buffers_backend with buffers_clean in pg_stat_bgwriter: when backends write most buffers themselves, a shorter delay or larger bgwriter_lru_maxpages shifts some of that work off the query path.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check bgwriter_delay 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.
本頁文字與資料: CC BY 4.0,請註明出處 SQLly (sqlly.app)。 程式碼與 SQL 片段: MIT. 授權詳情