Received: from maia.hub.org (unknown [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4FBEE1337B4B for ; Mon, 25 Oct 2010 08:44:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 42770-03 for ; Mon, 25 Oct 2010 11:44:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og108.obsmtp.com (exprod7og108.obsmtp.com [64.18.2.169]) by mail.postgresql.org (Postfix) with SMTP id DB5C71337B34 for ; Mon, 25 Oct 2010 08:44:41 -0300 (ADT) Received: from source ([209.85.215.49]) by exprod7ob108.postini.com ([64.18.6.12]) with SMTP ID DSNKTMVtqNGoFs4fnfLFLvY88kC5mq/mlafu@postini.com; Mon, 25 Oct 2010 04:44:42 PDT Received: by ewy19 with SMTP id 19so1362842ewy.36 for ; Mon, 25 Oct 2010 04:44:40 -0700 (PDT) Received: by 10.213.14.83 with SMTP id f19mr95607eba.57.1288007080000; Mon, 25 Oct 2010 04:44:40 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id x54sm7347166eeh.5.2010.10.25.04.44.38 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 25 Oct 2010 04:44:39 -0700 (PDT) Message-ID: <4CC56DA5.3040908@enterprisedb.com> Date: Mon, 25 Oct 2010 14:44:37 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.12) Gecko/20100913 Icedove/3.0.7 MIME-Version: 1.0 To: Jeff Davis CC: pgsql-bugs@postgresql.org Subject: Re: Recovery bug References: <1287183483.30681.54.camel@jdavis-ux.asterdata.local> <1287355728.8516.383.camel@jdavis> <4CBD6458.4050400@enterprisedb.com> <1287507095.8516.547.camel@jdavis> <1287517214.20345.5.camel@jdavis-ux.asterdata.local> In-Reply-To: <1287517214.20345.5.camel@jdavis-ux.asterdata.local> Content-Type: multipart/mixed; boundary="------------050802040503070700090408" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201010/199 X-Sequence-Number: 28489 This is a multi-part message in MIME format. --------------050802040503070700090408 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 19.10.2010 22:40, Jeff Davis wrote: > On Tue, 2010-10-19 at 09:51 -0700, Jeff Davis wrote: >> On Tue, 2010-10-19 at 12:26 +0300, Heikki Linnakangas wrote: >>> Excluding pg_xlog is just a recommendation at the moment, though, so we >>> would need a big warning in the docs. And some way to enforce that >>> just_kidding is not included in the backup would be nice, maybe we could >>> remove read-permission from it? >> >> Hmm, removing the read bit would add some confidence into the process. I >> like that idea better than just assuming that the user won't copy it. >> >> I think I like this direction most, because it doesn't leave us >> guessing. If the file is there then we assume normal recovery. If we >> encounter recovery.conf we throw FATAL. If we encounter backup_label we >> can simply remove it (perhaps with a warning that there was a crash in >> the middle of a backup). > > On second thought, this doesn't sound backpatch-friendly. We should > probably put a simpler fix in first and back-patch it. Then we can do > something like your proposal for 9.1. What do you think of my proposed > patch? Yes, let's go ahead with your original patch. It seems we should use ReadRecord instead of the lower-level XLogPageRead function. One difference is that ReadRecord performs a bunch of sanity checks on the record, while XLogPageRead just reads the raw page. Extra sanity checking before removing backup_label seems like a good idea. Another difference is that in standby-mode, ReadRecord will retry until it succeeds. A standby server should keep retrying, even the very first record, until it succeeds, otherwise we have a change in behavior. So I'm thinking of the attached patch. I'll give this some testing on older branches and commit. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com --------------050802040503070700090408 Content-Type: text/x-diff; name="recovery-redo-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="recovery-redo-2.patch" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 22fd578..1d1a7bc 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5839,6 +5839,18 @@ StartupXLOG(void) record = ReadCheckpointRecord(checkPointLoc, 0); if (record != NULL) { + /* + * Make sure that REDO location exists. This may not be + * the case if there was a crash during an online backup, + * which left a backup_label around that references a WAL + * segment that's already been archived. + */ + memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint)); + if (!ReadRecord(&(checkPoint.redo), LOG, false)) + ereport(FATAL, + (errmsg("could not find redo location referenced by checkpoint record"), + errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir))); + ereport(DEBUG1, (errmsg("checkpoint record is at %X/%X", checkPointLoc.xlogid, checkPointLoc.xrecoff))); @@ -5846,7 +5858,7 @@ StartupXLOG(void) } else { - ereport(PANIC, + ereport(FATAL, (errmsg("could not locate required checkpoint record"), errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir))); } @@ -5892,10 +5904,10 @@ StartupXLOG(void) ereport(PANIC, (errmsg("could not locate a valid checkpoint record"))); } + memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint)); } LastRec = RecPtr = checkPointLoc; - memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint)); wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN); ereport(DEBUG1, --------------050802040503070700090408--