postgresql_16:7.3.2.1 Description
PostgreSQL 16 > Reference > PostgreSQL Server Applications > pg_archivecleanup > Description
pg_archivecleanup is designed to be used as an archive_cleanup_command to clean up WAL file archives when running as a standby server (see (see postgresql_16:4.12.2)). pg_archivecleanup can also be used as a standalone program to clean WAL file archives.
To configure a standby server to use pg_archivecleanup, put this into its postgresql.conf configuration file: archive_cleanup_command = 'pg_archivecleanup *archivelocation* %r' where *archivelocation* is the directory from which WAL segment files should be removed.
When used within (see guc-archive-cleanup-command), all WAL files logically preceding the value of the %r argument will be removed from *archivelocation*. This minimizes the number of files that need to be retained, while preserving crash-restart capability. Use of this parameter is appropriate if the *archivelocation* is a transient staging area for this particular standby server, but *not* when the *archivelocation* is intended as a long-term WAL archive area, or when multiple standby servers are recovering from the same archive location.
When used as a standalone program all WAL files logically preceding the *oldestkeptwalfile* will be removed from *archivelocation*. In this mode, if you specify a .partial or .backup file name, then only the file prefix will be used as the *oldestkeptwalfile*. This treatment of .backup file name allows you to remove all WAL files archived prior to a specific base backup without error. For example, the following example will remove all files older than WAL file name 000000010000003700000010: pg_archivecleanup -d archive 000000010000003700000010.00000020.backup pg_archivecleanup: keep WAL file "archive/000000010000003700000010" and later pg_archivecleanup: removing file "archive/00000001000000370000000F" pg_archivecleanup: removing file "archive/00000001000000370000000E"
pg_archivecleanup assumes that *archivelocation* is a directory readable and writable by the server-owning user.