PG_ARCHIVECLEANUP(1)

πŸ“¦ version 16.15, in opensuse-leap 16.0

πŸ’– PG_ARCHIVECLEANUP(1) πŸ’–

okay bestie, welcome to the manual page for pg_archivecleanup β€” the PostgreSQL 16.15 documentation's very own WAL-archive janitor, and honestly? it's giving "quietly does the most important job at the party" energy. πŸŽ€


✨ NAME ✨

pg_archivecleanup β€” clean up PostgreSQL WAL archive files. yep, that's it, that's the whole vibe. she cleans. she archives. she slays. πŸ’…


✨ SYNOPSIS ✨

pg_archivecleanup [option...] archivelocation oldestkeptwalfile

✨ DESCRIPTION ✨

so pg_archivecleanup is literally designed to be used as an archive_cleanup_command β€” like, that's her whole main character arc β€” to clean up WAL file archives when you're running as a standby server (peep Section 27.2 if you wanna go deeper πŸ‘€). but also? she can absolutely be used as a standalone program to clean WAL file archives. versatile icon. 🌈

to configure a standby server to use pg_archivecleanup, drop 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 she's used within archive_cleanup_command, all WAL files logically preceding the value of the %r argument will be removed from archivelocation. the way this minimizes the number of files that need to be retained while preserving crash-restart capability?? obsessed. 🫢

⚠️ okay important vibe check: 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. pls don't do her dirty like that. 😭

when used as a standalone program, all WAL files logically preceding the oldestkeptwalfile will be removed from archivelocation. and 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 β€” no drama, no mess, just vibes. πŸ’…

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"

and just so we're clear: pg_archivecleanup assumes that archivelocation is a directory readable and writable by the server-owning user. no exceptions, bestie. πŸ”‘


✨ OPTIONS ✨

pg_archivecleanup accepts the following command-line arguments:

  • -d β€” print lots of debug logging output on stderr. she's a talker and we love that for her. πŸ—£οΈ
  • -n β€” print the names of the files that would have been removed on stdout (performs a dry run). literally the "look but don't touch" of file deletion. πŸ‘€
  • -V, --version β€” print the pg_archivecleanup version and exit. identity check real quick. πŸͺž
  • -x extension β€” 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 about pg_archivecleanup command line arguments, and exit. the "wait what does this do again" button. πŸ†˜

✨ ENVIRONMENT ✨

the environment variable PG_COLOR specifies whether to use color in diagnostic messages. possible values are always, auto and never. yes she has a color palette. aesthetics matter. 🎨


✨ 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, no cap. ⭐

pg_archivecleanup is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs. she's open, she's giving "come customize me", she's a builder. 🧚


✨ 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

okay that's the whole page!! πŸ’– source & version tea: this is PostgreSQL 16.15, dated 2026, and it's the PG_ARCHIVECLEANUP(1) page β€” now go forth and clean those WAL archives, bestie, you're gonna eat. πŸ”₯πŸ‘‘πŸŒΈ