pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <amit.kapila@huawei.com>
To: sari.thiele@usit.uio.no
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #7890: wrong behaviour using pg_rotate_logfile() with parameter	log_truncate_on_rotation = on
Date: Mon, 18 Feb 2013 20:11:06 +0530
Message-ID: <00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com> (raw)
In-Reply-To: <E1U7PZN-0000zg-NC@wrigleys.postgresql.org>
References: <E1U7PZN-0000zg-NC@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Monday, February 18, 2013 5:42 PM sari thiele wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      7890
> Logged by:          Sari Thiele
> Email address:      sari.thiele@usit.uio.no
> PostgreSQL version: 9.1.8
> Operating system:   Red Hat Enterprise Linux Server release 6.3
> Description:
> 
> Hi,
> 
> I am trying to use the function pg_rotate_logfile() to force a truncate
> of
> the current log file by setting the parameter "log_truncate_on_rotation
> =
> on".
> But it looks like that this does not work, like I expected.
> 
> System info:
> Red Hat Enterprise Linux Server release 6.3 (Santiago)
> 
> select version();
>                                                   version
> 
> -----------------------------------------------------------------------
> ---------------------------------------
>  PostgreSQL 9.1.8 on x86_64-unknown-linux-gnu, compiled by gcc (GCC)
> 4.4.6
> 20120305 (Red Hat 4.4.6-4), 64-bit
> 
> 
> Parameter set-up:
> 
> log_filename = 'postgresql-%F_%H.log'
> logging_collector = on
> log_truncate_on_rotation = on
> log_rotation_age = 1h
> log_rotation_size = 0
> 
> SELECT pg_rotate_logfile();
> 
> After the function call, the file is still filled with the previous
> data.
> After my understanding the log file should be emptied (truncated).
> 
> -----------
> To check if there is something wrong with my set-up, I did some other
> tests,
> too.
> 
> 1.
> log_filename = 'postgresql-%F_%T.log'
> logging_collector = on
> log_truncate_on_rotation = on
> log_rotation_age = 1h
> log_rotation_size = 0
> 
> SELECT pg_rotate_logfile();
> 
> After the function call a new file is generated, because of the
> logfilename
> string (HH:MM:ss).
> This is correct.
> 
> -------------------------
> 2.
> log_filename = 'postgresql-%M.log'
> logging_collector = on
> log_truncate_on_rotation = on
> log_rotation_age = 10min
> log_rotation_size = 0
> 
> Here is the file automatically truncated after an hour, because of the
> file
> name. So that works also correct.
> 
> ----
> 
> We checked the source code and it looks like the problem could be here:
> 
> src/backend/postmaster/syslogger.c
> 
> 
> /*
>  * Decide whether to overwrite or append.  We can overwrite if (a)
>  * Log_truncate_on_rotation is set, (b) the rotation was triggered by
>  * elapsed time and not something else, and (c) the computed file name
> is
>  * different from what we were previously logging into.
>  *
>  * Note: last_file_name should never be NULL here, but if it is,
> append.
>  */
>  if (time_based_rotation || (size_rotation_for
> &LOG_DESTINATION_STDERR))
>     {
>      if (Log_truncate_on_rotation && time_based_rotation &&
>          last_file_name != NULL &&
>          strcmp(filename, last_file_name) != 0) ==> *
>         fh = logfile_open(filename, "w", true);
>      else
>         fh = logfile_open(filename, "a", true);
> 
> 
> ==> * this checks if the new file name is different from the old one.
> In my case it is still the same name and so the new log lines will be
> appended to the current file, not truncated like I expected.
> I think this is the wrong behaviour, what do you think?

The only reason is you have used pg_rotate_logfile() to perform the action, otherwise if it would have been done
based on time, it should have truncated the file.
Why you think this is wrong behavior, do you expect any time you call pg_rotate_logfile(), it should truncate the file if
log_truncate_on_rotation is on?
I think if you are expecting such behavior, it might not be right expectation, because it considers the the time and log_filename format as well. 

With Regards,
Amit Kapila.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (11+ messages)  latest in thread

Message-ID: <00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com>
Permalink:  ../00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com/
Also on:    postgresql.org/message-id/00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: amit.kapila@huawei.com, sari.thiele@usit.uio.no
  Subject: Re: BUG #7890: wrong behaviour using pg_rotate_logfile() with parameter	log_truncate_on_rotation = on
  In-Reply-To: <00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com>
  References: <E1U7PZN-0000zg-NC@wrigleys.postgresql.org> <00a201ce0de5$fc2f1920$f48d4b60$@kapila@huawei.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox