Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 7E99B9A4AA5 for ; Mon, 16 Jul 2012 02:43:39 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sqe5q-0001Xk-L2 for pgsql-bugs@postgresql.org; Mon, 16 Jul 2012 05:43:39 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6G5hMAd002055; Mon, 16 Jul 2012 01:43:22 -0400 (EDT) From: Tom Lane To: viswanatham.kirankumar@huawei.com cc: "'Chan Pham'" , pgsql-bugs@postgresql.org Subject: Re: log_truncate_on_rotation=on is not truncating In-reply-to: <767.1342414417@sss.pgh.pa.us> References: <009901cd4fad$4b5ff9d0$e21fed70$@kirankumar@huawei.com> <767.1342414417@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 16 Jul 2012 00:53:37 -0400" Date: Mon, 16 Jul 2012 01:43:22 -0400 Message-ID: <2054.1342417402@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/117 X-Sequence-Number: 33593 I wrote: > The relevant bit of the code is > /* > * The requirements here are to choose the next time > now that is a > * "multiple" of the log rotation interval. "Multiple" can be interpreted > * fairly loosely. In this version we align to log_timezone rather than > * GMT. > */ Oh, no, scratch that --- there's nothing wrong with that calculation. Actually I think the issue is with the logic that decides whether to truncate or append during rotation: * 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: during the first rotation after forking off from the postmaster, * last_file_name will be NULL. (We don't bother to set it in the * postmaster because it ain't gonna work in the EXEC_BACKEND case.) So we * will always append in that situation, even though truncating would * usually be safe. This dates from around 2004, and at the time we did not think it was very important if the first rotation opportunity failed to truncate. Of course, if you restart the postmaster so often that it never gets to the second rotation opportunity, that theory falls down. But I guess it's worth asking why you think it's a good plan to reboot so often. Most people running Postgres are appalled by the idea that they might have to have any downtime at all. regards, tom lane