Postgresql – How to purge old files from pg_xlogs directory

postgresqlwrite-ahead-logging

I have an archive command copying WAL files from pg_xlogs to my archive directory. However, I notice that the pg_xlogs directory is growing in size with (but is limiting itself to around 7 files). What controls this "7" value? Is there a risk it will grow to a huge number of files?

How do I limit the number of log files, or even better, limit to no more than 48 hours worth? I found a similarly titled question here but it doesn't really apply. I'm using PostgreSQL version 8.4.20 (so settings/commands from v9 won't apply)

Can I just create a cron job that deletes files from pg_xlogs older than 48 hours? Will this crash/corrupt the pgsql server? Is there a better way?

Can I use my archive_command to delete the source file after moving to my archive directory?

Best Answer

Firstly PG 8.4 is no longer supported (since July 2014), you should move your databases to a supported version as soon as possible.

The WAL configuration settings for the 8.4 version are documented here:

https://www.postgresql.org/docs/8.4/static/runtime-config-wal.html

In particular checkpoint_segments control the number of WAL files.

You must not delete WAL files, either manually or with a cron job or with archive_command. This would definitely corrupt your database.

WAL files may grow in number if archive_command is not working or lagging behind.