Re: syslogger file descriptor question - Mailing list pgsql-bugs

From Magnus Hagander
Subject Re: syslogger file descriptor question
Date
Msg-id CABUevEythzzb=YbHcUbbxuhNQs_DoHsk+PzCkuLF03_OXD7zLg@mail.gmail.com
Whole thread Raw
In response to syslogger file descriptor question  (chenyanfei <postgresql_2016@163.com>)
List pgsql-bugs
On Fri, Apr 30, 2021 at 4:16 AM chenyanfei <postgresql_2016@163.com> wrote:
>
> When use the  pg_ctl start -l  command to start the postgres, I find the
> syslogger process point to the specified log file.
>
>
> With long time running, the log file is too big. So we delete it, but the fd
> is show as deleted.
>
>
> It looks like the file descriptor leak. Although this problem has little
> impact, it brings troubles to customers.
> The regular file has the rotate mechanism, so it can close the old fd and
> reopen the new file.
>
> My question is if I specify them to /dev/null whether have any problem. I
> find one process do this not in first start.

pg_ctl just redirects what comes at stderr, and doesn't in itself
handle rotation that's correct. There are basically two ways to handle
that for you I think:

1. Enable the PostgreSQL logging collector, that is set
logging_collector='on' in your postgresql.conf. That way, only the
startup logging will go to the pg_ctl logfile, which will never grow
large. The main logging will go to the log as specified in the
PostgreSQL logging configuration.

2. Don't remove the large log file to clear it out, instead use
something like "cat /dev/null > logfile". That way the existing file
descriptors remain working, and new logging data will go into the
file. If you're using logrotate, that's the "copytruncate" option (and
what for example debian does in it's packaging).

Or a combination of the two.

--
 Magnus Hagander
 Me: https://www.hagander.net/
 Work: https://www.redpill-linpro.com/



pgsql-bugs by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: BUG #16989: parameter track_commit_timestamp's category problem
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #16908: Postgres (12) allows you (re)-attach partitions that violate Foreign Key constraints?