pg_archivecleanup to clean old archive logs in PostgreSQL

pg_archivecleanup is designed to be used as an archive_cleanup_command to clean up WAL file archives when running as a standby server. pg_archivecleanup can also be used as a standalone program to clean WAL file archives.

If you are using it in the stadnby server (where stadnby server configured with log-shipping) then put below option in recovery.conf in stadnby server.

archive_cleanup_command = ‘pg_archivecleanup archivelocation %r’

If you want to use the pg_archivecleanup command to clean the archive logs in a standlone node use the below command. When used as a standalone program all WAL files logically preceding the restartwalfile will be removed from archivelocation.

pg_archivecleanup [ option … ] archivelocation restartwalfile


pg_archivecleanup -d /home/postgres/archive 000000010000003700000010.00000020.backup

This will remove all the logfiles which are older than “000000010000003700000010”

So After completion of the base backup we can use this command to clean the old archivelogs.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s