Question & Answer
Question
This article describes how to delete postgres logs when database is running.
Answer
1. Check the current postgres log status in the cluster.
[root@hosta pg_log]# pwd
/var/lib/pgsql/data/pg_log
[root@hosta pg_log]# date
Thu Feb 8 13:23:24 CST 2018
[root@hosta pg_log]# ls -l
total 19952
-rw------- 1 postgres postgres 3101772 Feb 3 00:00 postgresql-Fri.log
-rw------- 1 postgres postgres 3102180 Feb 6 00:00 postgresql-Mon.log
-rw------- 1 postgres postgres 3143054 Feb 4 00:00 postgresql-Sat.log
-rw------- 1 postgres postgres 3102180 Feb 5 00:00 postgresql-Sun.log
-rw------- 1 postgres postgres 1730082 Feb 8 13:22 postgresql-Thu.log
-rw------- 1 postgres postgres 3102180 Feb 7 00:00 postgresql-Tue.log
-rw------- 1 postgres postgres 3102180 Feb 8 00:00 postgresql-Wed.log
2. Backup all logs except "postgresql-Thu.log", since "postgresql-Thu.log" is today's log and it is in using by postgresql.
3. Delete all logs except "postgresql-Thu.log". the result is as below:
[root@hosta pg_log]# ll
total 1704
-rw------- 1 postgres postgres 1738698 Feb 8 13:26 postgresql-Thu.log
4. Then the next day, postgresql will generate "postgresql-Fri.log", and will generate "postgresql-Sat.log" on Saturday.
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
isg3T1027117