Обсуждение: Log Rotation

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

Log Rotation

От
SOzcn
Дата:
Hello team I hope everything going well for you guys! 

 I have a question about log rotation.

I set the parameters as a daily. The set parameters are as follows.

In this case, the log file is created as "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs in the 12th day file need to be truncated. 

Is the expected result correct? Or does PostgreSQL not support deleting, truncating files? I got successful results when I did this process hourly. However, I could not get a correct result when I tried it daily log truncate.

The parameter for I used as Hour log;  postgresql-%H%M

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql/logtest'
log_filename = 'postgresqllogtest-%Y-%m-%d_%H%M%S.log'
log_rotation_age=1440
log_min_duration_statement = 5000
log_line_prefix = 'time=%t [%p]: db=%d,user=%u,app=%a,client=%h '
log_statement = 'none'
log_temp_files = 0
log_timezone = 'Europe/Istanbul'
log_hostname = on
log_min_messages = warning
log_min_error_statement = error
log_lock_waits = on

Re: Log Rotation

От
Tom Lane
Дата:
SOzcn <selahattinozcnma@gmail.com> writes:
> I set the parameters as a daily. The set parameters are as follows.

> In this case, the log file is created as
> "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs
> in the 12th day file need to be truncated.

> Is the expected result correct? Or does PostgreSQL not support deleting,
> truncating files? I got successful results when I did this process hourly.
> However, I could not get a correct result when I tried it daily log
> truncate.

If you want log rotation, you need to choose your filename pattern
so that old log files will be overwritten after a while; or else
set up some external tool for removing the old ones.  Postgres does
not do anything to keep track of old log files.

            regards, tom lane



Re: Log Rotation

От
SOzcn
Дата:
Hello Tom,
Thanks for the response.
On the top you can see the parameters, I already set the parameters as you said. But the truncate didn't work for daily.

Tom Lane <tgl@sss.pgh.pa.us>, 12 Ara 2023 Sal, 19:18 tarihinde şunu yazdı:
SOzcn <selahattinozcnma@gmail.com> writes:
> I set the parameters as a daily. The set parameters are as follows.

> In this case, the log file is created as
> "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs
> in the 12th day file need to be truncated.

> Is the expected result correct? Or does PostgreSQL not support deleting,
> truncating files? I got successful results when I did this process hourly.
> However, I could not get a correct result when I tried it daily log
> truncate.

If you want log rotation, you need to choose your filename pattern
so that old log files will be overwritten after a while; or else
set up some external tool for removing the old ones.  Postgres does
not do anything to keep track of old log files.

                        regards, tom lane

Re: Log Rotation

От
Ron Johnson
Дата:
On Tue, Dec 12, 2023 at 11:11 AM SOzcn <selahattinozcnma@gmail.com> wrote:
Hello team I hope everything going well for you guys! 

 I have a question about log rotation.

I set the parameters as a daily. The set parameters are as follows.

In this case, the log file is created as "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs in the 12th day file need to be truncated. 

Is the expected result correct? Or does PostgreSQL not support deleting, truncating files? I got successful results when I did this process hourly. However, I could not get a correct result when I tried it daily log truncate.

The parameter for I used as Hour log;  postgresql-%H%M

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql/logtest'
log_filename = 'postgresqllogtest-%Y-%m-%d_%H%M%S.log'

%M%S really isn't needed.
 
log_rotation_age=1440

(Setting that to "1d" is clearer IMO than 1440 minutes.)

It _says_ "rotation", but _means_ "overwrite".

If you want to _delete_ files older than 12 days, you must have an external process do it: logrotate, or your own shell script that uses find(1).

Re: Log Rotation

От
SOzcn
Дата:
Thanks for the response Ron!
Have a great week!

Ron Johnson <ronljohnsonjr@gmail.com>, 12 Ara 2023 Sal, 19:48 tarihinde şunu yazdı:
On Tue, Dec 12, 2023 at 11:11 AM SOzcn <selahattinozcnma@gmail.com> wrote:
Hello team I hope everything going well for you guys! 

 I have a question about log rotation.

I set the parameters as a daily. The set parameters are as follows.

In this case, the log file is created as "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs in the 12th day file need to be truncated. 

Is the expected result correct? Or does PostgreSQL not support deleting, truncating files? I got successful results when I did this process hourly. However, I could not get a correct result when I tried it daily log truncate.

The parameter for I used as Hour log;  postgresql-%H%M

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql/logtest'
log_filename = 'postgresqllogtest-%Y-%m-%d_%H%M%S.log'

%M%S really isn't needed.
 
log_rotation_age=1440

(Setting that to "1d" is clearer IMO than 1440 minutes.)

It _says_ "rotation", but _means_ "overwrite".

If you want to _delete_ files older than 12 days, you must have an external process do it: logrotate, or your own shell script that uses find(1).

Re: Log Rotation

От
Laurenz Albe
Дата:
On Tue, 2023-12-12 at 19:25 +0300, SOzcn wrote:
> On the top you can see the parameters, I already set the parameters as
> you said. But the truncate didn't work for daily.

Again: PostgreSQL will only truncate a file if, during log rotation,
it starts writing to a file that already exists.
It does not take care about old, closed log files.

Yours,
Laurenz Albe



Re: Log Rotation

От
sagar jadhav
Дата:
Hi,
You can set "log_truncate_on_rotation" to "on" to truncate the log files if the log file name is same on rotation. 

Thanks,
Sagar

On Tue, Dec 12, 2023 at 9:41 PM SOzcn <selahattinozcnma@gmail.com> wrote:
Hello team I hope everything going well for you guys! 

 I have a question about log rotation.

I set the parameters as a daily. The set parameters are as follows.

In this case, the log file is created as "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs in the 12th day file need to be truncated. 

Is the expected result correct? Or does PostgreSQL not support deleting, truncating files? I got successful results when I did this process hourly. However, I could not get a correct result when I tried it daily log truncate.

The parameter for I used as Hour log;  postgresql-%H%M

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql/logtest'
log_filename = 'postgresqllogtest-%Y-%m-%d_%H%M%S.log'
log_rotation_age=1440
log_min_duration_statement = 5000
log_line_prefix = 'time=%t [%p]: db=%d,user=%u,app=%a,client=%h '
log_statement = 'none'
log_temp_files = 0
log_timezone = 'Europe/Istanbul'
log_hostname = on
log_min_messages = warning
log_min_error_statement = error
log_lock_waits = on

Re: Log Rotation

От
SOzcn
Дата:
Thanks for the response guys, yeah that works with the specific log file.
Have a nice day!

sagar jadhav <sagarjdhv5@gmail.com>, 13 Ara 2023 Çar, 05:13 tarihinde şunu yazdı:
Hi,
You can set "log_truncate_on_rotation" to "on" to truncate the log files if the log file name is same on rotation. 

Thanks,
Sagar

On Tue, Dec 12, 2023 at 9:41 PM SOzcn <selahattinozcnma@gmail.com> wrote:
Hello team I hope everything going well for you guys! 

 I have a question about log rotation.

I set the parameters as a daily. The set parameters are as follows.

In this case, the log file is created as "postgresqllogtest-2023-12-12_182351.log" after the 13th day file, the logs in the 12th day file need to be truncated. 

Is the expected result correct? Or does PostgreSQL not support deleting, truncating files? I got successful results when I did this process hourly. However, I could not get a correct result when I tried it daily log truncate.

The parameter for I used as Hour log;  postgresql-%H%M

log_destination = 'stderr'
logging_collector = on
log_directory = '/var/log/postgresql/logtest'
log_filename = 'postgresqllogtest-%Y-%m-%d_%H%M%S.log'
log_rotation_age=1440
log_min_duration_statement = 5000
log_line_prefix = 'time=%t [%p]: db=%d,user=%u,app=%a,client=%h '
log_statement = 'none'
log_temp_files = 0
log_timezone = 'Europe/Istanbul'
log_hostname = on
log_min_messages = warning
log_min_error_statement = error
log_lock_waits = on