// postgresql · checkpoints & recovery

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.

// one client for every engine

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. 许可详情