Re: [PATCH] Fixed creation of empty .log files during log rotation

From: Arseny Kositsin <a(dot)kositsyn(at)postgrespro(dot)ru>
To: Tomas Vondra <tomas(at)vondra(dot)me>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Fixed creation of empty .log files during log rotation
Date: 2024-12-13 11:21:45
Message-ID: 4dc16c9a-a546-48a6-a8df-ab7441a008a6@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Tomas.

08.12.2024 01:06, Tomas Vondra wrote:

> Yeah, creating all those files seems rather unnecessary. But wouldn't it
> be easier to do the check in logfile_rotate_dest(), instead of for each
> call? I think something like this would do the trick:
>
> @@ -1292,6 +1292,9 @@ logfile_rotate_dest(bool time_based_rotation, int
> size_rotation_for,
>      if (!time_based_rotation && (size_rotation_for & target_dest) == 0)
>          return true;
>
> +    if ((Log_destination & target_dest) == 0)
> +        return true;
> +
>      /* file extension depends on the destination type */
>      if (target_dest == LOG_DESTINATION_STDERR)
>          logFileExt = NULL;

Thanks for the comments, I agree that it is better to move the check to
logfile_rotate_dest().

> In fact, isn't it wrong to do the check outside? logfile_rotate_dest()
> is responsible for closing the log files too, and with the check outside
> we keep the first .log file open forever (lsof shows that).
>
> FWIW my fix has the same issue, but IMO that just means the logic needs
> to be more complex, but still in logfile_rotate_dest().

You can close the first file if you remove the second part of the
condition in
if (because it is stderr). I checked it in lsof and the first log file is
closing:

@@ -1274,8 +1274,7 @@ logfile_rotate_dest(bool time_based_rotation, int
size_rotation_for,
      * is assumed to be always opened even if stderr is disabled in
      * log_destination.
      */
-    if ((Log_destination & target_dest) == 0 &&
-        target_dest != LOG_DESTINATION_STDERR)
+    if ((Log_destination & target_dest) == 0)
  {
    if (*logFile != NULL)
      fclose(*logFile);

But the comment above says that stderr should always remain open, even if
disabled in log_destination. Is it really necessary to do more complex
logic
in order to close this file? I'm sorry if I misunderstood something.

What do you think about this?

Best regards,
Arseny Kositsin.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2024-12-13 11:53:34 Re: Allow subfield references without parentheses
Previous Message Alvaro Herrera 2024-12-13 11:04:33 Re: Allow FDW extensions to support MERGE command via CustomScan