PG_ARCHIVECLEANUP(1)
π PG_ARCHIVECLEANUP(1) β the glow-up edition π
okay so bestie, picture this: you're running a PostgreSQL standby server and your WAL archive directory is just collecting files like it's auditioning for hoarders. enter pg_archivecleanup, the manual page you're reading right now, and honestly? it's giving main character energy for disk cleanup. β¨
πΈ SYNOPSIS πΈ
pg_archivecleanup [option...] archivelocation oldestkeptwalfile
π¦ DESCRIPTION π¦
so pg_archivecleanup is literally designed to be used as an archive_cleanup_command to clean up WAL file archives when you're running as a standby server (peep Section 26.2). but also? it can totally fly solo as a standalone program to clean WAL file archives. versatile icon. π
to configure a standby server to use pg_archivecleanup, you put this lil gem 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. got it? good. π«Ά
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. like, read the room, bestie β don't delete files out from under your other standbys. π
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. iconic behavior, no cap. 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. so like, permissions check first, bestie. π₯
β¨ OPTIONS β¨
pg_archivecleanup accepts the following command-line arguments β and yes, we're listing every single one, because we don't skip. periodt.
-dβ print lots of debug logging output onstderr. it's giving "tell me everything" energy. π¬-nβ print the names of the files that would have been removed onstdout(performs a dry run). lowkey the responsible queen move β look before you delete. π-V,--versionβ print thepg_archivecleanupversion and exit. slay, but make it version info. π-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. compressed archive girlies, this one's for you. ποΈβ¨-?,--helpβ show help aboutpg_archivecleanupcommand line arguments, and exit. when in doubt, ask for help. no shame. π«Ά
π ENVIRONMENT π
the environment variable PG_COLOR specifies whether to use color in diagnostic messages. possible values are always, auto and never. because even your error messages deserve a lil aesthetic. π
π§ 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. old-school compatible, bestie. π°οΈ
pg_archivecleanup is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs. so if you wanna hack on it, the code is literally set up for you. iykyk. π»π
π 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 ποΈβ¨
π SEE ALSO π
pg_standby(1) β go check it out, bestie. π«Ά
and that's the whole vibe, bestie. this page came straight from PostgreSQL 13.23 documentation, dated 2025 β so when you're out here slaying your WAL archives, just remember who told you. mwah. πππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13-contrib 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-contrib 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-contrib 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13-contrib 13.23-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