When you start your PostgreSQL database, a bunch of background

Arpit Bhayani

Arpit Bhayani

Jul 10, 2024 • 2 min read


When you start your PostgreSQL database, a bunch of background processes are also forked; I spent some time today understanding them in-depth, here’s everything you need to know about them ⚡

Each background process handles specific tasks to maintain database efficiency, reliability, and performance. Some of important background processes are

  1. autovacuum

Autovacuum is a daemon process that periodically scans tables to remove these dead tuples, thereby reclaiming storage space and maintaining optimal performance. It uses a cost-based vacuuming strategy, limiting the amount of work it does in each iteration to minimize the impact on regular database operations.

  1. checkpointer

The checkpointer process is responsible for writing all dirty pages to the disk and creating a checkpoint record in the Write-Ahead Log (WAL). This ensures that the database can recover to a consistent state in the event of a crash. The process is governed by a checkpoint_timeout interval and max_wal_size as a signal to execute.

  1. Background Writer

The Background Writer process writes dirty buffers to disk in the background, rather than waiting for a checkpoint or individual backend processes to perform the writes. This helps to smooth out the I/O load, which otherwise would be spikey.

  1. WAL Writer

The WAL Writer process flushes the Write-Ahead Log (WAL) buffers to disk, ensuring all the changes to the database are logged and can be recovered in case of a crash. The process is governed by the wal_writer_delay parameter which controls the flush frequency.

Apart from these 4, there are others like Statistics Collector, Archiver, Logical Replication processes, and Background Worker processes; which we will discuss later.

By the way, you can see these processes by running a query on pg_stat_activity or running a ps | pstree -p command on the Postgres process.

⚡ I keep writing and sharing my practical experience and learnings every day, so if you resonate then follow along. I keep it no fluff.

youtube.com/c/ArpitBhayani

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses