Обсуждение: current log file removal

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

current log file removal

От
Yambu
Дата:
Hi

How can I safely remove the log file that is being used  currently and zip it without interfering with the postgres server?

We are running out of space on the server and the logs are eating a lot of space, we need to zip them without first stopping the server.

regards

Re: current log file removal

От
Van Hoa Phan
Дата:
Would this do?

cat /dev/null > my_log_file.log

On Fri, Nov 27, 2020 at 12:41 AM Yambu <hyambu@gmail.com> wrote:
Hi

How can I safely remove the log file that is being used  currently and zip it without interfering with the postgres server?

We are running out of space on the server and the logs are eating a lot of space, we need to zip them without first stopping the server.

regards

Re: current log file removal

От
Holger Jakobs
Дата:
The ordinary log rotation should do.

These are the default settings (therefore commented with a # in
postgresql.conf):

#log_rotation_age = 1d                  # Automatic rotation of logfiles
will
                                         # happen after that time.  0
disables.
#log_rotation_size = 10MB               # Automatic rotation of logfiles
will
                                         # happen after that much log
output.
                                         # 0 disables.

So your log files will not exceed 10 MB.

Of course, you can to this manually as well. Just rename the current
logfile,  a new one will be created.

Then gzip or bzip2 or xz the old one.

Am 26.11.20 um 14:40 schrieb Yambu:
> Hi
>
> How can I safely remove the log file that is being used currently and
> zip it without interfering with the postgres server?
>
> We are running out of space on the server and the logs are eating a
> lot of space, we need to zip them without first stopping the server.
>
> regards

--
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012


Вложения

Re: current log file removal

От
Yambu
Дата:
Hi

When I renamed log file, there was no new one created, do I need to reload postgres?

regards

On Thu, Nov 26, 2020 at 4:03 PM Holger Jakobs <holger@jakobs.com> wrote:
The ordinary log rotation should do.

These are the default settings (therefore commented with a # in
postgresql.conf):

#log_rotation_age = 1d                  # Automatic rotation of logfiles
will
                                         # happen after that time.  0
disables.
#log_rotation_size = 10MB               # Automatic rotation of logfiles
will
                                         # happen after that much log
output.
                                         # 0 disables.

So your log files will not exceed 10 MB.

Of course, you can to this manually as well. Just rename the current
logfile,  a new one will be created.

Then gzip or bzip2 or xz the old one.

Am 26.11.20 um 14:40 schrieb Yambu:
> Hi
>
> How can I safely remove the log file that is being used currently and
> zip it without interfering with the postgres server?
>
> We are running out of space on the server and the logs are eating a
> lot of space, we need to zip them without first stopping the server.
>
> regards

--
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012

Re: current log file removal

От
Paul Förster
Дата:
Hi,

> On 26. Nov, 2020, at 15:46, Yambu <hyambu@gmail.com> wrote:
>
> When I renamed log file, there was no new one created, do I need to reload postgres?

a new log file will be created when necessary and not just for fun. So, if there is an event that needs logging, then
thelog file will be written to. If it doesn't exist, then it will be created. 

If your log level permits, then you can provoke that, but it's really not necessary to do that.

Cheers,
Paul


Re: current log file removal

От
Ron
Дата:
I set these values in postgresql.conf, then have a cron job which runs just 
after midnight that compresses yesterday's log files. That same cron job 
deletes compressed files older than X days.

log_destination = 'stderr'
logging_collector = on
log_directory = '/your/data/location/12/pg_log' # assuming v12, of course
log_filename = 'postgresql-%F.log'
log_rotation_age = 1d

On 11/26/20 8:03 AM, Holger Jakobs wrote:
> The ordinary log rotation should do.
>
> These are the default settings (therefore commented with a # in 
> postgresql.conf):
>
> #log_rotation_age = 1d                  # Automatic rotation of logfiles will
>                                         # happen after that time. 0 disables.
> #log_rotation_size = 10MB               # Automatic rotation of logfiles will
>                                         # happen after that much log output.
>                                         # 0 disables.
>
> So your log files will not exceed 10 MB.
>
> Of course, you can to this manually as well. Just rename the current 
> logfile,  a new one will be created.
>
> Then gzip or bzip2 or xz the old one.
>
> Am 26.11.20 um 14:40 schrieb Yambu:
>> Hi
>>
>> How can I safely remove the log file that is being used currently and zip 
>> it without interfering with the postgres server?
>>
>> We are running out of space on the server and the logs are eating a lot 
>> of space, we need to zip them without first stopping the server.
>>
>> regards
>

-- 
Angular momentum makes the world go 'round.