Skip to main content
Version: Next

pg_stat_bgwriter

The pg_stat_bgwriter view provides cumulative statistics about the background writer process, which is responsible for writing dirty buffers to disk in the background. This view helps monitor the efficiency of the background writer and overall buffer management. It includes metrics such as the number of buffers written during checkpoints, buffers cleaned by the background writer, and buffers written directly by backend processes. These statistics are useful for tuning database performance and understanding write activity patterns.

columntypereferencesdescription
checkpoints_timedbigintNumber of scheduled checkpoints that have been performed.
checkpoints_reqbigintNumber of requested checkpoints that have been performed.
checkpoint_write_timedouble precisionTotal amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds.
checkpoint_sync_timedouble precisionTotal amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds.
buffers_checkpointbigintNumber of buffers written during checkpoints.
buffers_cleanbigintNumber of buffers written by the background writer.
maxwritten_cleanbigintNumber of times the background writer stopped a cleaning scan because it had written too many buffers.
buffers_backendbigintNumber of buffers written directly by a backend.
buffers_backend_fsyncbigintNumber of times the background writer stopped a cleaning scan because it had written too many buffers.
buffers_allocbigintNumber of buffers allocated.
stats_resettimestamp with time zoneTime at which these statistics were last reset.