Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tg4i6-00072b-SY for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Dec 2012 02:27:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tg4i5-0007bL-UX for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Dec 2012 02:27:41 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tg4i4-0007bF-Qd for pgsql-bugs@postgresql.org; Wed, 05 Dec 2012 02:27:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tg4i3-0001UB-6C for pgsql-bugs@postgresql.org; Wed, 05 Dec 2012 02:27:40 +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 qB52RYKU022654; Tue, 4 Dec 2012 21:27:34 -0500 (EST) From: Tom Lane To: Andres Freund cc: Jeff Janes , Heikki Linnakangas , Noah Misch , Pg Bugs Subject: Re: PITR potentially broken in 9.2 In-reply-to: <20121205021537.GB9811@awork2.anarazel.de> References: <241.1354117868@sss.pgh.pa.us> <14784.1354394848@sss.pgh.pa.us> <16296.1354399004@sss.pgh.pa.us> <7787.1354482169@sss.pgh.pa.us> <20516.1354666844@sss.pgh.pa.us> <20121205021537.GB9811@awork2.anarazel.de> Comments: In-reply-to Andres Freund message dated "Wed, 05 Dec 2012 03:15:38 +0100" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <22626.1354674363.0@sss.pgh.pa.us> Date: Tue, 04 Dec 2012 21:27:34 -0500 Message-ID: <22653.1354674454@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22626.1354674363.1@sss.pgh.pa.us> Andres Freund writes: >> But the key is, the database was not actually consistent at that >> point, and so opening hot standby was a dangerous thing to do. >> >> The bug that allowed the database to open early (the original topic if >> this email chain) was masking this secondary issue. > Could you check whether the attached patch fixes the behaviour? Yeah, I had just come to the same conclusion: the bug is not with Heikki's fix, but with the pause logic. The comment says that it shouldn't pause unless users can connect to un-pause, but the actual implementation of that test is several bricks shy of a load. Your patch is better, but it's still missing a bet: what we need to be sure of is not merely that we *could* have told the postmaster to start hot standby, but that we *actually have done so*. Otherwise, it's flow-of-control-dependent whether it works or not; we could fail if the main loop hasn't gotten to CheckRecoveryConsistency since the conditions became true. Looking at the code in CheckRecoveryConsistency, testing LocalHotStandbyActive seems appropriate. I also thought it was pretty dangerous that this absolutely critical test was not placed in recoveryPausesHere() itself, rather than relying on the call sites to remember to do it. So the upshot is that I propose a patch more like the attached. This is not a regression because the pause logic is broken this same way since 9.1. So I no longer think that we need a rewrap. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-patch; charset="us-ascii" Content-ID: <22626.1354674363.2@sss.pgh.pa.us> Content-Description: fix-pause-logic.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c index 50e2b22..593dcee 100644 *** a/src/backend/access/transam/xlog.c --- b/src/backend/access/transam/xlog.c *************** recoveryStopsHere(XLogRecord *record, bo *** 5923,5928 **** --- 5923,5932 ---- static void recoveryPausesHere(void) { + /* Don't pause unless users can connect! */ + if (!LocalHotStandbyActive) + return; +=20 ereport(LOG, (errmsg("recovery has paused"), errhint("Execute pg_xlog_replay_resume() to continue."))); *************** StartupXLOG(void) *** 6697,6707 **** */ if (recoveryStopsHere(record, &recoveryApply)) { ! /* ! * Pause only if users can connect to send a resume ! * message ! */ ! if (recoveryPauseAtTarget && standbyState =3D=3D STANDBY_SNAPSHOT_RE= ADY) { SetRecoveryPause(true); recoveryPausesHere(); --- 6701,6707 ---- */ if (recoveryStopsHere(record, &recoveryApply)) { ! if (recoveryPauseAtTarget) { SetRecoveryPause(true); recoveryPausesHere(); *************** StartupXLOG(void) *** 6737,6752 **** /* * Update shared replayEndRecPtr before replaying this record, * so that XLogFlush will update minRecoveryPoint correctly. */ SpinLockAcquire(&xlogctl->info_lck); xlogctl->replayEndRecPtr =3D EndRecPtr; recoveryPause =3D xlogctl->recoveryPause; SpinLockRelease(&xlogctl->info_lck); =20=20 ! /* ! * Pause only if users can connect to send a resume message ! */ ! if (recoveryPause && standbyState =3D=3D STANDBY_SNAPSHOT_READY) recoveryPausesHere(); =20=20 /* --- 6737,6751 ---- /* * Update shared replayEndRecPtr before replaying this record, * so that XLogFlush will update minRecoveryPoint correctly. + * + * While we have the lock, also check for a pause request. */ SpinLockAcquire(&xlogctl->info_lck); xlogctl->replayEndRecPtr =3D EndRecPtr; recoveryPause =3D xlogctl->recoveryPause; SpinLockRelease(&xlogctl->info_lck); =20=20 ! if (recoveryPause) recoveryPausesHere(); =20=20 /* ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--