Обсуждение: Log file retention

Поиск
Список
Период
Сортировка

Log file retention

От
Rajesh Kumar
Дата:
Hi,

How to keep log files only for 7 days

Re: Log file retention

От
Ron Johnson
Дата:
On Tue, Mar 19, 2024 at 4:04 AM Rajesh Kumar <rajeshkumar.dba09@gmail.com> wrote:
Hi,

How to keep log files only for 7 days

logrotate?  A bash script in a cron job? 

Re: Log file retention

От
Gabriel Guillem Barceló Soteras
Дата:

From: Ron Johnson <ronljohnsonjr@gmail.com>
Date: Tuesday, 19 March 2024 at 09:16
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Log file retention

On Tue, Mar 19, 2024 at 4:04AM Rajesh Kumar <rajeshkumar.dba09@gmail.com> wrote:

Hi,

 

How to keep log files only for 7 days

 

logrotate?  A bash script in a cron job? 

 

 

I think it is the default behaviour on default install:

 

  1. Edit the postgresql.conf File:
  2. Locate the postgresql.conf file for your PostgreSQL installation.
  3. Configure the Following Parameters:
    1. Set log_filename to server_log.%a. This will create one log file per day named server_log.Mon, server_log.Tue, etc.
    2. Enable log_truncate_on_rotation to automatically overwrite last week’s log with this week’s log.
    3. Set log_rotation_age to 1440 (minutes), which corresponds to 24 hours. This ensures that logs are rotated daily.
  4. Example Configuration:

 

log_filename = 'server_log.%a'

log_truncate_on_rotation = on

log_rotation_age = 1440

 

Still keep an eye on log_rotation_size

 

After making these changes, restart your PostgreSQL server for the new settings to take effect.

 

Re: Log file retention

От
Rajesh Kumar
Дата:
Thanks...I got the same info from postgrespro after searching this for long time..

Can we also set for one month the same way?

Thanks.

On Tue, 19 Mar 2024, 13:50 Gabriel Guillem Barceló Soteras, <gbarcelo@parlamentib.es> wrote:

From: Ron Johnson <ronljohnsonjr@gmail.com>
Date: Tuesday, 19 March 2024 at 09:16
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Log file retention

On Tue, Mar 19, 2024 at 4:04AM Rajesh Kumar <rajeshkumar.dba09@gmail.com> wrote:

Hi,

 

How to keep log files only for 7 days

 

logrotate?  A bash script in a cron job? 

 

 

I think it is the default behaviour on default install:

 

  1. Edit the postgresql.conf File:
  2. Locate the postgresql.conf file for your PostgreSQL installation.
  3. Configure the Following Parameters:
    1. Set log_filename to server_log.%a. This will create one log file per day named server_log.Mon, server_log.Tue, etc.
    2. Enable log_truncate_on_rotation to automatically overwrite last week’s log with this week’s log.
    3. Set log_rotation_age to 1440 (minutes), which corresponds to 24 hours. This ensures that logs are rotated daily.
  4. Example Configuration:

 

log_filename = 'server_log.%a'

log_truncate_on_rotation = on

log_rotation_age = 1440

 

Still keep an eye on log_rotation_size

 

After making these changes, restart your PostgreSQL server for the new settings to take effect.

 

Re: Log file retention

От
Rajesh Kumar
Дата:
Instead of %a should we use postgresql-%d.log ?

On Tue, 19 Mar 2024, 13:57 Rajesh Kumar, <rajeshkumar.dba09@gmail.com> wrote:
Thanks...I got the same info from postgrespro after searching this for long time..

Can we also set for one month the same way?

Thanks.

On Tue, 19 Mar 2024, 13:50 Gabriel Guillem Barceló Soteras, <gbarcelo@parlamentib.es> wrote:

From: Ron Johnson <ronljohnsonjr@gmail.com>
Date: Tuesday, 19 March 2024 at 09:16
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Log file retention

On Tue, Mar 19, 2024 at 4:04AM Rajesh Kumar <rajeshkumar.dba09@gmail.com> wrote:

Hi,

 

How to keep log files only for 7 days

 

logrotate?  A bash script in a cron job? 

 

 

I think it is the default behaviour on default install:

 

  1. Edit the postgresql.conf File:
  2. Locate the postgresql.conf file for your PostgreSQL installation.
  3. Configure the Following Parameters:
    1. Set log_filename to server_log.%a. This will create one log file per day named server_log.Mon, server_log.Tue, etc.
    2. Enable log_truncate_on_rotation to automatically overwrite last week’s log with this week’s log.
    3. Set log_rotation_age to 1440 (minutes), which corresponds to 24 hours. This ensures that logs are rotated daily.
  4. Example Configuration:

 

log_filename = 'server_log.%a'

log_truncate_on_rotation = on

log_rotation_age = 1440

 

Still keep an eye on log_rotation_size

 

After making these changes, restart your PostgreSQL server for the new settings to take effect.

 

Re: Log file retention

От
vignesh kumar
Дата:
Use log rotate functionality instead on Linux. You can specify the size , date and retention period and file extn suffix as well.. hope this helps


From: Rajesh Kumar <rajeshkumar.dba09@gmail.com>
Sent: Tuesday, March 19, 2024 2:11:28 PM
To: Gabriel Guillem Barceló Soteras <gbarcelo@parlamentib.es>
Cc: Ron Johnson <ronljohnsonjr@gmail.com>; Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Log file retention
 
Instead of %a should we use postgresql-%d.log ?

On Tue, 19 Mar 2024, 13:57 Rajesh Kumar, <rajeshkumar.dba09@gmail.com> wrote:
Thanks...I got the same info from postgrespro after searching this for long time..

Can we also set for one month the same way?

Thanks.

On Tue, 19 Mar 2024, 13:50 Gabriel Guillem Barceló Soteras, <gbarcelo@parlamentib.es> wrote:

From: Ron Johnson <ronljohnsonjr@gmail.com>
Date: Tuesday, 19 March 2024 at 09:16
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Log file retention

On Tue, Mar 19, 2024 at 4:04AM Rajesh Kumar <rajeshkumar.dba09@gmail.com> wrote:

Hi,

 

How to keep log files only for 7 days

 

logrotate?  A bash script in a cron job? 

 

 

I think it is the default behaviour on default install:

 

  1. Edit the postgresql.conf File:
  2. Locate the postgresql.conf file for your PostgreSQL installation.
  3. Configure the Following Parameters:
    1. Set log_filename to server_log.%a. This will create one log file per day named server_log.Mon, server_log.Tue, etc.
    2. Enable log_truncate_on_rotation to automatically overwrite last week’s log with this week’s log.
    3. Set log_rotation_age to 1440 (minutes), which corresponds to 24 hours. This ensures that logs are rotated daily.
  4. Example Configuration:

 

log_filename = 'server_log.%a'

log_truncate_on_rotation = on

log_rotation_age = 1440

 

Still keep an eye on log_rotation_size

 

After making these changes, restart your PostgreSQL server for the new settings to take effect.