Re: How to maintain the csv log files in pg_log directory only for past 30 days

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: How to maintain the csv log files in pg_log directory only for past 30 days
Date: 2018-09-28 13:31:46
Message-ID: 3b246f3b-221e-8988-e9d5-91848a5ffcb3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/28/2018 12:03 AM, Raghavendra Rao J S V wrote:
>
> Hi All,
>
> Log file will be generated in *csv* format at *pg_log* directory in our
> PostgreSQL. Every day we are getting one log file. We would like to
> maintain only max 30 days. Which setting need to modify by us in
> “postgresql.conf” in order to recycle the log files after 30 days.

Does it have to be in postgresql.conf?  A cron job which runs a few minutes
after midnight works just fine.

Compresses yesterday's log file and deletes files older than 30 days:
#!/bin/bash
DIR=/var/lib/pgsql/data/pg_log
cd $DIR
PREVDT=$(date -d "-1 day" +"%F")
bzip2 -9 postgresql-${PREVDT}.log
OLDFILES=$(find $DIR/postgresql-*log* -mtime +30)
rm -v $OLDFILES

--
Angular momentum makes the world go 'round.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2018-09-28 13:37:55 Re: Why my query not using index to sort?
Previous Message Adrian Klaver 2018-09-28 13:29:48 Re: Why my query not using index to sort?