PG_ARCHIVECLEANUP(1)
π pg_archivecleanup, bestie edition π
okay so this is the PG_ARCHIVECLEANUP(1) manual page, and we are gonna read it together like a group chat π grab a snack π because pg_archivecleanup is here to clean up WAL archive files and honestly? iconic.
β¨ NAME β¨
pg_archivecleanup β clean up PostgreSQL WAL archive files ποΈβ¨
πΈ SYNOPSIS πΈ
pg_archivecleanup [option...] archivelocation oldestkeptwalfile
π¦ 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 Section 27.2). It can also be used as a standalone program to clean WAL file archives. periodt. π
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 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. π«Ά
π OPTIONS π
pg_archivecleanup accepts the following command-line arguments:
-dβ prints lots of debug logging output onstderr. bestie, it's giving verbose. π-nβ prints the names of the files that would have been removed onstdout(performs a dry run). no cap, nothing actually gets deleted. π§-V,--versionβ prints thepg_archivecleanupversion and exits. π-xextension β provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example:-x .gz. π-?,--helpβ show help aboutpg_archivecleanupcommand line arguments, and exit. π
π ENVIRONMENT π
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto, and never. slay. π
β NOTES β
pg_archivecleanup is designed to work with PostgreSQL 8.0 and later when used as a standalone utility, or with PostgreSQL 9.0 and later when used as an archive cleanup command. β¨
pg_archivecleanup is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs. π
π EXAMPLES π
On Linux or Unix systems, you might use:
archive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2>>cleanup.log'
where the archive directory is physically located on the standby server, so that the archive_command is accessing it across NFS, but the files are local to the standby. This will:
- produce debugging output in
cleanup.logπ₯ - remove no-longer-needed files from the archive directory ποΈβ¨
π that's the whole page, bestie β brought to you by PostgreSQL 15.19 Documentation, dated 2026, from the PG_ARCHIVECLEANUP(1) manual. mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15-contrib 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-contrib 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-contrib 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15-contrib 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms