PostgreSQL – Archiving Old Data

postgresqlpostgresql-9.2

My environment:

# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.3 (Maipo)
# rpm -q postgresql
postgresql-9.2.18-1.el7.x86_64
# 

I used following Streaming Replication – PostgreSQL wiki to set up replication between master/slave and now after a while I end up with following:

-bash-4.2$ du -h ~/archive/
19G /var/lib/pgsql/archive/
-bash-4.2$ ls -la ~/archive/ | head
total 19169360
drwxr-xr-x.  2 postgres postgres    61440 Jun  6 12:10 .
drwx------. 11 postgres postgres     4096 Jun  6 11:21 ..
-rw-------.  1 postgres postgres 16777216 Feb  6 10:19 0000000100000008000000AE
-rw-------.  1 postgres postgres 16777216 Feb 14 20:30 0000000100000008000000AF
-rw-------.  1 postgres postgres 16777216 Feb 14 20:30 0000000100000008000000B0
-rw-------.  1 postgres postgres 16777216 Feb 14 20:30 0000000100000008000000B1
-rw-------.  1 postgres postgres 16777216 Feb 14 20:30 0000000100000008000000B2
-rw-------.  1 postgres postgres 16777216 Feb 14 20:30 0000000100000008000000B3
-rw-------.  1 postgres postgres 16777216 Feb  6 10:33 0000000100000008000000B4
-bash-4.2$ 

should I setup a cron job to kill old archives? or there is postgres way of doing this?

Best Answer

You can use pg_archivecleanup.

You will find documentation here : https://www.postgresql.org/docs/current/static/pgarchivecleanup.html