Background writer

A background process responsible for writing altered buffers to disk

The background writer is a separate server process responsible for writing "dirty" (new or modified) buffers to the on-disk datafiles, to reduce load on regular backends.

The background writer was introduced with PostgreSQL 8.0 (release notes; initial commit cfeca621).

Until PostgreSQL 9.2 it was also responsible for handling checkpoints.

Configuration

Currently following configuration items control the background writer behaviour:

  • bgwriter_delay (integer)
  • bgwriter_lru_maxpages (integer)
  • bgwriter_lru_multiplier (floating point)
  • bgwriter_flush_after (integer)

Setting bgwriter_lru_maxpages to zero effectively disables the background writer.

For more details, see the background writer configuration documentation.

Statistics

The number of buffers written by the background writer itself is recorded in the "buffers_clean" column of the pg_stat_bgwriter view.

Source code

The main background writer process code: src/backend/postmaster/bgwriter.c

The actual "heavy lifting" is done in src/backend/storage/buffer/bufmgr.c, particularly function BgBufferSync().

Categories

Performance, PostgreSQL internals

See also

checkpointer