Re: log_destination reload/restart doesn't stop file creation

From: Rafia Sabih <rafia(dot)sabih(at)enterprisedb(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: log_destination reload/restart doesn't stop file creation
Date: 2018-09-10 09:26:19
Message-ID: CAOGQiiPWPLXED25srBBe0WGz5YoBAuFOOhGL0+sjcc0cVLgumw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Aug 14, 2018 at 6:02 PM, Thom Brown <thom(at)linux(dot)com> wrote:

> Hi,
>
> I've tested the following on git head. When changing log_destination
> and reloading, the old destination file continues to be made, just not
> populated with anything. That means at every file rotation, 2 files
> are created.
>
> For example:
>
> log_destination = 'stderr'
>
> I get this in my log directory:
>
> postgresql-2018-08-14_131640.log
>
> If I change it to csvlog and reload, I end up with:
>
> 0 -rw------- 1 thom thom 0 Aug 14 13:19 postgresql-2018-08-14_131900.log
> 4 -rw------- 1 thom thom 194 Aug 14 13:19 postgresql-2018-08-14_131900.csv
>
> So I get the csv file, but it's still producing the .log file which
> remains 0 bytes. The same happens in reverse. (i.e. I end up with an
> empty .csv file and a populated .log file).
>
> I expect the old file to stop being created.
>
> What's also interesting is if I have log_destination set to 'csvlog',
> then I restart, or stop then start the database manually, I still get
> 2 files, which contain:
>
> postgresql-2018-08-14_132510.log:
> 2018-08-14 13:25:10 BST [21065]: [6-1] user=,db=,client= LOG: ending
> log output to stderr
> 2018-08-14 13:25:10 BST [21065]: [7-1] user=,db=,client= HINT: Future
> log output will go to log destination "csvlog".
>
> postgresql-2018-08-14_132510.csv:
> 2018-08-14 13:25:10.626 BST,,,21065,,5b72ca26.5249,1,,2018-08-14
> 13:25:10 BST,,0,LOG,00000,"ending log output to stderr",,"Future log
> output will go to log destination ""csvlog"".",,,,,,,""
> 2018-08-14 13:25:10.675 BST,,,21067,,5b72ca26.524b,1,,2018-08-14
> 13:25:10 BST,,0,LOG,00000,"database system was shut down at 2018-08-14
> 13:25:08 BST",,,,,,,,,""
> 2018-08-14 13:25:10.868 BST,,,21065,,5b72ca26.5249,2,,2018-08-14
> 13:25:10 BST,,0,LOG,00000,"database system is ready to accept
> connections",,,,,,,,,""
>
>
Hi,

I had a look at this issue and here are my comments for the same. As far as
this part is concerned, this looks like intentional code in postmaster.c

* If we are in fact disabling logging to stderr, first emit a log message
* saying so, to provide a breadcrumb trail for users who may not remember
* that their logging is configured to go somewhere else.
*/
if (!(Log_destination & LOG_DESTINATION_STDERR))
ereport(LOG,
(errmsg("ending log output to stderr"),
errhint("Future log output will go to log destination
\"%s\".",
Log_destination_string)));

To me having one file at system restart doesn't seem too harmful.

> Then I continue to get empty .log files:
> 0 -rw------- 1 thom thom 0 Aug 14 13:26 postgresql-2018-08-14_132600.log
> 0 -rw------- 1 thom thom 0 Aug 14 13:26 postgresql-2018-08-14_132600.csv
> 0 -rw------- 1 thom thom 0 Aug 14 13:27 postgresql-2018-08-14_132700.log
> 0 -rw------- 1 thom thom 0 Aug 14 13:27 postgresql-2018-08-14_132700.csv
> 0 -rw------- 1 thom thom 0 Aug 14 13:28 postgresql-2018-08-14_132800.log
> 4 -rw------- 1 thom thom 195 Aug 14 13:28 postgresql-2018-08-14_132800.csv
> 0 -rw------- 1 thom thom 0 Aug 14 13:29 postgresql-2018-08-14_132900.log
> 0 -rw------- 1 thom thom 0 Aug 14 13:29 postgresql-2018-08-14_132900.csv
>
> This doesn't happen if log_destination is set to 'stderr'.
>
> Regarding this issue, in logfile_rotate by default a .log file was
created, I didn't quite get the logic behind it and assume it to be a bug.
Hence, in the attached patch I have added a check to see if we need to
create a log file and only then create it.

--
Regards,
Rafia Sabih
EnterpriseDB: http://www.enterprisedb.com/

Attachment Content-Type Size
extra_logfile_bugfix_v1.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message kalyani kaniganti 2018-09-10 10:15:15 Re: BUG #15376: Postgres sql 9.4.19 pg_upgrade stops with error The source cluster was not shut down cleanly.
Previous Message Bruce Momjian 2018-09-10 04:10:40 Re: BUG #15376: Postgres sql 9.4.19 pg_upgrade stops with error The source cluster was not shut down cleanly.