From: | Ron Johnson <ronljohnsonjr(at)gmail(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Log retention query |
Date: | 2025-01-28 16:38:33 |
Message-ID: | CANzqJaBSwqEvHnhEnp04C-hirLJ_6vPZ1KoenyhaydSO+S56Hw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
It's impossible to *rotate* logs with the date embedded in the name. All
you can do is delete the oldest files. Why we call that "rotation" is a
mystery.
Junwang's find command does that for you, as does the bash script I
presented.
On Tue, Jan 28, 2025 at 11:22 AM Paul Brindusa <paulbrindusa88(at)gmail(dot)com>
wrote:
> Hi everyone,
>
> @Ron: I've tried all the classic log tools, for some reason that I do
> not remember logrotate does not rotate the logs.
> @Adrian: three node cluster with patroni again.
>
> On Tue, Jan 28, 2025 at 3:02 PM Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
> wrote:
>
>> logrotate will, of course, also work.
>>
>> On Tue, Jan 28, 2025 at 9:20 AM Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
>> wrote:
>>
>>> Deleting old log files is _NOT_ a Postgresql problem. Bash and crontab
>>> work perfectly for me.
>>>
>>> (Could I have done a one-liner like Junwang? Sure, but I like the
>>> obvious and explicit.)
>>>
>>> declare -i Weeks=8
>>> declare -i Days=$Weeks*7
>>> declare Dir=/var/log/postgresql
>>> declare OldFiles=$(find $Dir/p*-*log* -mtime +$Days | sort)
>>> if [ -z "$OldFiles" ];
>>> then
>>> echo "No old files to delete in ${Dir}."
>>> else
>>> rm -v $OldFiles
>>> fi
>>>
>>> On Tue, Jan 28, 2025 at 8:41 AM Paul Brindusa <paulbrindusa88(at)gmail(dot)com>
>>> wrote:
>>>
>>>> @Junwang apologies, I should have mentioned that we've tried setting
>>>> up a crontab and it has not worked. Have you got something similar working?
>>>>
>>>> @Laurenz: log_filename: postgresql-%Y-%m-%d.log -- if we redo the
>>>> syntax can we make it trigger garbage collection on 180 days?
>>>>
>>>> On Tue, Jan 28, 2025 at 1:28 PM Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
>>>> wrote:
>>>>
>>>>> On Tue, 2025-01-28 at 09:57 +0000, Paul Brindusa wrote:
>>>>> > Good morning everyone,
>>>>> >
>>>>> > Before I get on with today's problem, I would like to say how much I
>>>>> appreciate this community and everything that you do for end users.
>>>>> >
>>>>> > In today's problem I would like to understand if the following lines
>>>>> in our config handle the log rotation for our clusters?
>>>>> >
>>>>> > log_checkpoints: on
>>>>> > logging_collector: on
>>>>> > log_truncate_on_rotation: on
>>>>> > log_rotation_age: 1d
>>>>> > log_rotation_size: 1GB
>>>>> > log_error_verbosity: verbose
>>>>> >
>>>>> > I have been deleting the logs manually for the last month, since I
>>>>> am confused how the log collector rotates them.
>>>>> >
>>>>> > Am looking to delete logs older than 180 days. What are we
>>>>> doing wrong in the config?
>>>>>
>>>>> It all depends on how you configured "log_filename".
>>>>>
>>>>> If the setting is "postgresql-%a.log" or "postgresql-%d.log",
>>>>> PostgreSQL
>>>>> will recycle the old log files once a week or once a month.
>>>>>
>>>>> If the setting is the default "postgresql-%Y-%m-%d_%H%M%S.log", the
>>>>> same
>>>>> log file name will never be reused, and there will be no log rotation.
>>>>>
>>>>> PostgreSQL doesn't actively delete old log files.
>>>>>
>>>>> Yours,
>>>>> Laurenz Albe
>>>>>
>>>>
>>>>
>>>> --
>>>> Kind Regards,
>>>> Paul Brindusa
>>>> paulbrindusa88(at)gmail(dot)com
>>>>
>>>>
>>>
>>> --
>>> Death to <Redacted>, and butter sauce.
>>> Don't boil me, I'm still alive.
>>> <Redacted> lobster!
>>>
>>
>>
>> --
>> Death to <Redacted>, and butter sauce.
>> Don't boil me, I'm still alive.
>> <Redacted> lobster!
>>
>
>
> --
> Kind Regards,
> Paul Brindusa
> paulbrindusa88(at)gmail(dot)com
>
>
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
From | Date | Subject | |
---|---|---|---|
Next Message | Shaheed Haque | 2025-01-28 18:02:25 | Re: Content of pg_publication using a local connection versus network connection? |
Previous Message | Bharani SV-forum | 2025-01-28 16:23:41 | Help in vetting error using "pg_upgrade" - steps for Postgres DB upgrade from Ver 13.X to ver 14.X/15.X and issue with python binaries |