Search code examples
postgresqlpostgresql-13

What is a restartpoint in postgresql?


In the postgresql.conf file for PostgreSQL version 13, the archive_cleanup_command comment explains the command in the following way:

#archive_cleanup_command = ''         # command to execute at every restartpoint.

The documentation here and here have no mention of a 'restartpoint'. This raises the following questions:

  1. What is a restartpoint? For example: is restartpoint just the same word for a checkpoint? Do the two mean the exact same thing?
  2. When is a restartpoint created? For example: if the restartpoint is just a checkpoint then the check point will be created every 5mins or whatever the setting for checkpoint_timeout is in postgresql.conf file.
  3. When is the archive cleanup command run? For example: The archive cleanup command is run every time the archive_timeout (set in the postgresql.conf file) is reached. If the archive timeout is set to 1hr, then the archive_cleanup_command runs every 1hr.

Solution

  • A restartpoint is just a checkpoint during recovery, and it is triggered in the same fashion as a checkpoint: either by timeout or by the amount of WAL processed since the last restartpoint. Note also that

    Restartpoints can't be performed more frequently than checkpoints in the master because restartpoints can only be performed at checkpoint records.

    The reason for restartpoints is “restartable recovery”: if your recovery process is interrupted, the next restart won't start recovering from the beginning of the backup, but from the latest restartpoint.

    archive_cleanup_command is run for all completely recovered WAL segments during a restartpoint. Its main use case are log shipping standby servers: using archive_cleanup_command they can remove all shipped WAL segments they don't need any more, so that the directory containing them doesn't grow out of bounds.