Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aP4Co-0008Vo-6O for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2016 08:14:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aP4Cn-0004Bp-7T for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2016 08:14:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aP4BS-0002c7-TW for pgsql-hackers@postgresql.org; Fri, 29 Jan 2016 08:13:34 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aP4BP-0005fg-Jb for pgsql-hackers@postgresql.org; Fri, 29 Jan 2016 08:13:34 +0000 Received: from intern.anarazel.de (83.224-78-194.adsl-static.isp.belgacom.be [194.78.224.83]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id C9DF03A98F2; Fri, 29 Jan 2016 09:13:30 +0100 (CET) Date: Fri, 29 Jan 2016 09:13:30 +0100 From: Andres Freund To: Michael Paquier Cc: Amit Kapila , Robert Haas , Jeff Janes , "pgsql-hackers@postgresql.org" Subject: Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby Message-ID: <20160129081330.e5mj65du2cknxsja@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2016-01-28 16:40:13 +0900, Michael Paquier wrote: > OK, so as a first step and after thinking about the whole for a while, > I have finished with the patch attached. This patch is aimed at > avoiding unnecessary checkpoints on idle systems when wal_level >= > hot_standby by centralizing the check to look at if there has some WAL > activity since the last checkpoint. That's not what I suggested. > /* > + * XLOGHasActivity -- Check if XLOG had some significant activity or > + * if it is idle lately. This is primarily used to check if there has > + * been some WAL activity since the last checkpoint that occurred on > + * system to control the generaton of XLOG record related to standbys. > + */ > +bool > +XLOGHasActivity(void) > +{ > + XLogCtlInsert *Insert = &XLogCtl->Insert; > + XLogRecPtr redo_lsn = ControlFile->checkPointCopy.redo; > + uint64 prev_bytepos; > + > + /* Check if any activity has happened since last checkpoint */ > + SpinLockAcquire(&Insert->insertpos_lck); > + prev_bytepos = Insert->PrevBytePos; > + SpinLockRelease(&Insert->insertpos_lck); > + > + return XLogBytePosToRecPtr(prev_bytepos) == redo_lsn; > +} > How should this actually should work reliably, given we *want* to have included a standby snapshot after the last checkpoint? In CreateCheckPoint() we have /* * Here we update the shared RedoRecPtr for future XLogInsert calls; this * must be done while holding all the insertion locks. * RedoRecPtr = XLogCtl->Insert.RedoRecPtr = checkPoint.redo; computing the next redo rec ptr and then if (!shutdown && XLogStandbyInfoActive()) LogStandbySnapshot(); before the final XLogRegisterData((char *) (&checkPoint), sizeof(checkPoint)); recptr = XLogInsert(RM_XLOG_ID, shutdown ? XLOG_CHECKPOINT_SHUTDOWN : XLOG_CHECKPOINT_ONLINE); so the above condition doesn't really something we want to rely on. Am I missing what you're trying to do? Greetings, Andres Freund -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers