delete old pg_log files
search cancel

delete old pg_log files

book

Article ID: 296789

calendar_today

Updated On:

Products

VMware Tanzu Greenplum

Environment

Product Version: 6.19

Resolution

To find out how many files are older then 150 days (can be adjusted to 60 or 30 days as you need it)
[gpadmin@mdw-lab2 ~]$ gpssh -f hostfile -e "find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l"
[sdw1-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[sdw1-lab2] 13
[sdw2-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[sdw2-lab2] 11
[ mdw-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[ mdw-lab2] 7

Now delete the files
[gpadmin@mdw-lab2 ~]$ gpssh -f hostfile -e "find /data/*/*/pg_log/ -name *csv -ctime +150 -type f -delete"
[sdw1-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f -delete
[sdw2-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f -delete
[ mdw-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f -delete

Check again, and as you see there are no more found files older then 150 days
[gpadmin@mdw-lab2 ~]$ gpssh -f hostfile -e "find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l"
[sdw1-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[sdw1-lab2] 0
[sdw2-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[sdw2-lab2] 0
[ mdw-lab2] find /data/*/*/pg_log/ -name *csv -ctime +150 -type f | wc -l
[ mdw-lab2] 0

The permanent solution is to add the delete command as a cronjob for gpadmin user:
crontab -e

0 3 * * * source /usr/local/greenplum-db/greenplum_path.sh; gpssh -f /home/gpadmin/hostfile -e "find /data/*/*/pg_log/ -name *csv -ctime +60 -type f -delete"
The above entry will run a find command at 3am everyday and deletes the log files older then 60 days.