Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtTsb-0007at-O0 for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Dec 2013 03:02:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VtTsb-0005v5-8P for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Dec 2013 03:02:29 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtTsa-0005uy-2t for pgsql-bugs@postgresql.org; Thu, 19 Dec 2013 03:02:28 +0000 Received: from mail12.ics.ntts.co.jp ([210.232.35.65]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VtTsQ-0001pg-NX for pgsql-bugs@postgresql.org; Thu, 19 Dec 2013 03:02:27 +0000 Received: from sadoku34.silk.ntts.co.jp (sadoku34 [10.7.18.34]) by mail12.ics.ntts.co.jp (8.14.4/8.14.4/NTTSOFT) with ESMTP id rBJ32Gaq006764 for ; Thu, 19 Dec 2013 12:02:16 +0900 (JST) Received: (from root@localhost) by sadoku34.silk.ntts.co.jp (8.13.8/NTTSOFT) id rBJ32Gee008402 for pgsql-bugs@postgresql.org; Thu, 19 Dec 2013 12:02:16 +0900 (JST) Received: from ccmds32.silk.ntts.co.jp [10.107.0.32] by sadoku34.silk.ntts.co.jp with SMTP id NAA08401; Thu, 19 Dec 2013 12:02:16 +0900 Received: from mail147.silk.ntts.co.jp (ccmds32.silk.ntts.co.jp [127.0.0.1]) by ccmds32.silk.ntts.co.jp (8.14.3/8.14.3) with ESMTP id rBJ32Gov011120 for ; Thu, 19 Dec 2013 12:02:16 +0900 Received: from mail147.silk.ntts.co.jp (localhost.localdomain [127.0.0.1]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with ESMTP id rBJ32CrJ000485 for ; Thu, 19 Dec 2013 12:02:12 +0900 Received: from ccmds32 (mail145.silk.ntts.co.jp [10.107.0.145]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with SMTP id rBJ32B2t000482 for ; Thu, 19 Dec 2013 12:02:11 +0900 Message-ID: <52B26197.9080208@po.ntts.co.jp> Date: Thu, 19 Dec 2013 12:01:43 +0900 From: Tomonari Katsumata User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #8686: Standby could not restart. References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------010702010805020504020406" X-CC-Mail-RelayStamp: CC-Mail-V4.3-Client X-CC-Mail-RelayStamp: CC-Mail-V4.3-Server X-Pg-Spam-Score: -2.4 (--) 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 This is a multi-part message in MIME format. --------------010702010805020504020406 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, This is a patch against REL9_2_STABLE(*) (*)0c07ef1ad2ba73a6a050f3e1a19267f961a43586 regards, --------------- Tomonari Katsumata (2013/12/19 11:57), katsumata.tomonari@po.ntts.co.jp wrote: > The following bug has been logged on the website: > > Bug reference: 8686 > Logged by: Tomonari Katsumata > Email address: katsumata.tomonari@po.ntts.co.jp > PostgreSQL version: 9.2.6 > Operating system: Red Hat Enterprise Linux 6.2 x86_64 > Description: > > Hi, > > > I'm testing whether a standby could restart with asynchronous replication. > > > The testcase is very simple like below. > (A) start asyncronous replication > (B) stop standby with "-m f" > (C) start standby > > > I tried (B) and (C) periodically. > > > In almost cases, it worked fine. > But standby could not start one time because of PANIC. > ---- Log ----- > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: database system was shut down > in recovery at 2013-12-09 10:42:29 JST > [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6273 > cp: cannot stat `../arc/00000002.history': No such file or directory > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: entering standby mode > [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6359 > cp: cannot stat `../arc/000000010000000100000008': No such file or > directory > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: consistent recovery state > reached at 1/8E7F110 > [Standby] 2013-12-09 10:42:30 JST LOCATION: CheckRecoveryConsistency, > xlog.c:7366 > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: restored log file > "000000010000000100000007" from archive > [Standby] 2013-12-09 10:42:30 JST LOCATION: RestoreArchivedFile, > xlog.c:3273 > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: redo starts at 1/783B230 > [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6827 > [Standby] 2013-12-09 10:42:30 JST WARNING: 01000: page 1365 of relation > base/16384/16388 does not exist > [Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel > 1663/16384/16388; tid 1365/152; new 1365/153 > [Standby] 2013-12-09 10:42:30 JST LOCATION: report_invalid_page, > xlogutils.c:66 > [Standby] 2013-12-09 10:42:30 JST PANIC: XX000: WAL contains references to > invalid pages > [Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel > 1663/16384/16388; tid 1365/152; new 1365/153 > [Standby] 2013-12-09 10:42:30 JST LOCATION: log_invalid_page, > xlogutils.c:91 > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: startup process (PID 12560) > was terminated by signal 6: Aborted > [Standby] 2013-12-09 10:42:30 JST LOCATION: LogChildExit, > postmaster.c:2895 > [Standby] 2013-12-09 10:42:30 JST LOG: 00000: terminating any other active > server processes > [Standby] 2013-12-09 10:42:30 JST LOCATION: HandleChildCrash, > postmaster.c:2682 > [Standby] 2013-12-09 11:10:12 JST LOG: 00000: database system was > interrupted while in recovery at log time 2013-12-09 10:32:14 JST > [Standby] 2013-12-09 11:10:12 JST HINT: If this has occurred more than once > some data might be corrupted and you might need to choose an earlier > recovery target. > [Standby] 2013-12-09 11:10:12 JST LOCATION: StartupXLOG, xlog.c:6289 > --------- > > > I tried to fix this problem. > At first, I doubted the recovery state reached "consistent" before redo > starts. > And then I checked pg_control and related WAL. > The WAL sequence is like below. > > > WAL--(a)--(b)--(c)--(d)--(e)--> > ================================================ > (a) Latest checkpoint's REDO location > 1/783B230 > > > (b) hot_update > 1/7842010 > > > (c) truncate > 1/8E7E5C8 > > > (d) Latest checkpoint location > 1/8E7F0B0 > > > (e) Minimum recovery ending location > 1/8E7F110 > ================================================ > > > >From these things, I found it has happened with this scenario. > ---------- > (1) standby starting > (2) seeking checkpoint location 1/8E7F0B0 because backup_label is not > absecnt > (3) reachedConsistency is set to true at 1/8E7F110 in > CheckRecoveryConsistent > (4) redo start from 1/783B230 > (5) PANIC at 1/7842010 because reachedConsistency has set already and > operating against a block which will be truncated at (c). > ---------- > > > At step(2), EndRecPtr is set to 1/8E7F110(next to 1/8E7F0B0), > so reachedConsistency is set to true at step(3). > > > I think it's not need to increase EndRecPtr while seeking checkpoint > location. > I tried to revise it and this worked fine. > > > I think this is very very narrow gate, but it could happen. > > > I'm not sure this problem happen with synchronous replication or > another version of PostgreSQL(ie. 9.3/9.1/9.0), > but at least we need to fix it. > > > regards, > ---------------- > Tomonari Katsumata > > > > --------------010702010805020504020406 Content-Type: text/x-diff; name="do_not_increase_EndRecPtr_while_seek_ckptloc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="do_not_increase_EndRecPtr_while_seek_ckptloc.patch" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 190d86b..92599bc 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -4222,10 +4222,13 @@ retry: if (!RecordIsValid(record, *RecPtr, emode)) goto next_record_is_invalid; pageHeaderSize = XLogPageHeaderSize((XLogPageHeader) readBuf); - EndRecPtr.xlogid = readId; - EndRecPtr.xrecoff = readSeg * XLogSegSize + readOff + + if (!fetching_ckpt) + { + EndRecPtr.xlogid = readId; + EndRecPtr.xrecoff = readSeg * XLogSegSize + readOff + pageHeaderSize + MAXALIGN(SizeOfXLogContRecord + contrecord->xl_rem_len); + } ReadRecPtr = *RecPtr; /* needn't worry about XLOG SWITCH, it can't cross page boundaries */ @@ -4235,8 +4238,11 @@ retry: /* Record does not cross a page boundary */ if (!RecordIsValid(record, *RecPtr, emode)) goto next_record_is_invalid; - EndRecPtr.xlogid = RecPtr->xlogid; - EndRecPtr.xrecoff = RecPtr->xrecoff + MAXALIGN(total_len); + if (!fetching_ckpt) + { + EndRecPtr.xlogid = RecPtr->xlogid; + EndRecPtr.xrecoff = RecPtr->xrecoff + MAXALIGN(total_len); + } ReadRecPtr = *RecPtr; memcpy(buffer, record, total_len); @@ -4247,8 +4253,11 @@ retry: if (record->xl_rmid == RM_XLOG_ID && record->xl_info == XLOG_SWITCH) { /* Pretend it extends to end of segment */ - EndRecPtr.xrecoff += XLogSegSize - 1; - EndRecPtr.xrecoff -= EndRecPtr.xrecoff % XLogSegSize; + if (!fetching_ckpt) + { + EndRecPtr.xrecoff += XLogSegSize - 1; + EndRecPtr.xrecoff -= EndRecPtr.xrecoff % XLogSegSize; + } /* * Pretend that readBuf contains the last page of the segment. This is --------------010702010805020504020406 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 --------------010702010805020504020406--