DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Resource Usage / Background Writer

bgwriter_flush_after

Number of pages after which previously performed writes are flushed to disk. 0 disables forced writeback.

  • Default: 512kB
  • Type: integer (8kB)
  • Range: 0 … 2MB
  • Applies: Reload

In plain words

Writes from PostgreSQL first land in the operating system's page cache. If lots of dirty data piles up there, the final fsync at checkpoint time can stall everything. This setting makes the background writer nudge the kernel to write data out in small pieces as it goes.

For DBAs and operators

Implemented with sync_file_range() on Linux (no effect on platforms without it). Default 512 kB on Linux, 0 elsewhere; range 0 (off) to 2 MB. Siblings: checkpoint_flush_after (256 kB), backend_flush_after (off) and wal_writer_flush_after.

Usually lowers latency spikes at checkpoint end. It can hurt when the working set is larger than shared_buffers but fits in the OS cache: pages are forced to disk and then re-dirtied, adding I/O. The kernel knobs vm.dirty_background_bytes/vm.dirty_bytes address the same problem system-wide; pg_stat_io column writebacks counts these requests.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().

See it in context

Background writer Checkpoints

Related parameters

backend_flush_after checkpoint_flush_after bgwriter_delay

All Resource Usage parameters