Limiting the no. of logs file generated by postgreSQL

From: merina ghoghwani <merinaghoghwani(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Limiting the no. of logs file generated by postgreSQL
Date: 2018-02-15 11:54:40
Message-ID: CAKoQ0XHAy9De1C8gxUWHSW6w5iKcqX03wyWGe_+c8NxJccCBHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi All,

I am currently using PostgreSQL 9.4.5.

In one scenario with heavy traffic, log file size increased to 100GB in a
day, and due to which system ran out of disk space. The configuration in
postgresql.conf for log file was:

log_filename = 'postgresql-%a.log'

So, I want the log files to rotate such that the,
1. Total size of the Postgres logs is always less than 700MB.
2. I want to maintain recent 5 log files of 20MB each in a day .i.e. Total
100MB/day.

So I have tried only log_rotation_size option as below in configuration
file, but it didn't work for me.

log_rotation_size = '10kB' /* The file is not rotated after size increases
over 10KB. */

When I tried logging with the following configuration (just to test, the
values are pretty low):

log_rotation_size = '10kB'
log_filename = 'postgresql-%Y-%m-%d_%M.log'
log_truncate_on_rotation = 'on'
log_rotation_age = '10'

What I've observed is,
1. I get a new file after every 10 Mins or when I restart the service or
logs size is over 10KB.

But, it doesn't solve my problem to reduce the size of postgres logs, as
the file is not rotated, but a new is created every time.

Is there any way I can rotate the files or restrict number to, say max 5
files
like,
postgresql-Mon-1.log
postgresql-Mon-2.log
postgresql-Mon-3.log
postgresql-Mon-4.log
postgresql-Mon-5.log

and then re-write to "postgresql-Mon-1.log" file.

Regards,
Merina

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message pavan95 2018-02-15 12:39:47 Re: Limiting the no. of logs file generated by postgreSQL
Previous Message Shreeyansh Dba 2018-02-15 10:58:52 Re: filter partitions