How to use pg_archivecleanup on Windows Trying to figure out a proper way to clean old WAL files located in archive directory for point in time recovery purposes.
I know I can use hard-coded name of WAL segment something like this:

pg_archivecleanup.exe H:\Backup\pgArchive 0000000100000001000000C1


but apparantly I would like to automate this process.

Thank you.
Automating the process is simple once you know what you want to delete.

I can give you a few hints:


Typically, you want to remove all WAL archives older than the oldest base backup which you want to retain.
Whenever a base backup is done, PostgreSQL will archive a file called *.backup.

You can use this file as the second argument to pg_archivecleanup to remove everything older than that backup.


So to retain the last three backups, you could look at all *.backup files, sort them by modification time and find the third youngest file, then use pg_archivecleanup with that file as second argument.