PG_ARCHIVECLEANUP(1)

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

✨ pg_archivecleanup(1) ✨

okay bestie, so this is the pg_archivecleanup page from the PostgreSQL 14.24 Documentation β€” yeah, the actual official manual, but make it make sense. sit down, hydrate, let's go 🫢


πŸŽ€ NAME πŸŽ€

pg_archivecleanup β€” cleans up your PostgreSQL WAL archive files. that's it, that's the whole vibe. it's the little cleanup fairy of your archive directory 🧚


🌸 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 27.2 for the lore). it can also be used as a standalone program to clean WAL file archives. main character energy either way πŸ‘‘

to configure a standby server to use pg_archivecleanup, you 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 it's used inside archive_cleanup_command, all WAL files logically preceding the value of the %r argument get removed from archivelocation. this keeps the number of files you need to retain lowkey minimal while still 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. read that twice, bestie, it matters πŸ’€

when it's used as a standalone program, all WAL files logically preceding the oldestkeptwalfile get 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 names is iconic because it lets you remove all WAL files archived prior to a specific base backup without error. for example, this removes 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. no cap, it just assumes that. so maybe make sure it's true πŸ™ˆ


✨ OPTIONS ✨

pg_archivecleanup accepts the following command-line arguments:

  • -d β€” print lots of debug logging output on stderr. she's chatty and we love that for her πŸ”₯
  • -n β€” print the names of the files that would have been removed on stdout (performs a dry run). the "no thoughts, just vibes" mode where nothing actually gets deleted πŸ¦‹
  • -V, --version β€” print the pg_archivecleanup version and exit. bye πŸ‘‹
  • -x extension β€” provide an extension that will be stripped from all file names before deciding if they should be deleted. 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. so good, so practical πŸ’…
  • -?, --help β€” show help about pg_archivecleanup command line arguments, and exit. when in doubt, ask for help, queen πŸ’œ

πŸ¦‹ ENVIRONMENT πŸ¦‹

the environment variable PG_COLOR specifies whether to use color in diagnostic messages. possible values are always, auto and never. pick your 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. vintage-compatible, honestly πŸŽ€

pg_archivecleanup is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs. yes bestie, you can literally go in and customize it β€” designated sections and everything. it's giving DIY era πŸ”§


🌟 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

two birds, one config line, periodt πŸ“


and that's the whole page! source is PostgreSQL 14.24, dated 2026, and yep β€” it's PG_ARCHIVECLEANUP(1), the one and only. go forth and clean your archives responsibly, bestie πŸ’–βœ¨πŸŽ€