Thread: syslogger file descriptor question

syslogger file descriptor question

From
chenyanfei
Date:
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.




--
Sent from: https://www.postgresql-archive.org/PostgreSQL-bugs-f2117394.html



Re: syslogger file descriptor question

From
Magnus Hagander
Date:
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/