postgresqldatabase-administrationpostgresql-9.5postgresql-12

What are the difference between background writer and checkpoint in postgresql?


As per my understanding

  1. checkpoint write all dirty buffer(data) periodically into disk and
  2. background writer writes some specific dirty buffer(data) into disk

It looks both do almost same work.

But what are the specific dirty buffer(data) writes into disk? How frequently checkpoint and bgwriter it is calling?

I want to know what are the difference between them.

Thanks in advance


Solution

  • It looks both do almost same work.

    Looking at the source code link given by Adrian, you can see these words in the comments for the background writer:

    As of Postgres 9.2 the bgwriter no longer handles checkpoints.

    ...which means in the past, the background writer and checkpointer tasks were handled by one component, which explains the similarity that probably led you to ask this question. The two components were split on 1/Nov/2011 in this commit and you can learn more about the checkpointer here.

    From my own understanding, they are doing the same task from different perspectives. The task is making sure we use a limited amount of resources:

    It may be helpful to read more about the WAL (Write-Ahead Log) in general.