Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6A81DB5DBCB for ; Thu, 27 Oct 2011 03:57:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 01928-07 for ; Thu, 27 Oct 2011 06:57:45 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from exprod7og122.obsmtp.com (exprod7og122.obsmtp.com [64.18.2.22]) by mail.postgresql.org (Postfix) with ESMTP id 3A00CB5D91F for ; Thu, 27 Oct 2011 03:57:45 -0300 (ADT) Received: from mail-fx0-f52.google.com ([209.85.161.52]) (using TLSv1) by exprod7ob122.postini.com ([64.18.6.12]) with SMTP; Wed, 26 Oct 2011 23:57:45 PDT Received: by mail-fx0-f52.google.com with SMTP id n26so4023066faa.39 for ; Wed, 26 Oct 2011 23:57:44 -0700 (PDT) Received: by 10.223.85.139 with SMTP id o11mr64943219fal.0.1319698663925; Wed, 26 Oct 2011 23:57:43 -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 5sm9122149fad.9.2011.10.26.23.57.41 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Oct 2011 23:57:42 -0700 (PDT) Message-ID: <4EA900E5.9070905@enterprisedb.com> Date: Thu, 27 Oct 2011 09:57:41 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.21) Gecko/20110831 Icedove/3.1.13 MIME-Version: 1.0 To: Florian Pflug CC: Simon Riggs , Aidan Van Dyk , Daniel Farina , Chris Redekop , PostgreSQL-development Subject: Re: Hot Backup with rsync fails at pg_clog if under load References: <213AEFBF-479C-4F9E-B0CA-24AAB2C9F4DD@phlo.org> <1A94CE1A-C3E5-4923-B677-623D41BC273F@phlo.org> <6C3D7EDA-573E-46DC-9047-5FEB92876DA8@phlo.org> <12E895D5-C6D0-4E71-B9C3-85E1BC14E6B8@phlo.org> <5EDA27FA-963F-413D-9849-874072F317E5@phlo.org> In-Reply-To: <5EDA27FA-963F-413D-9849-874072F317E5@phlo.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201110/1426 X-Sequence-Number: 197232 On 27.10.2011 02:29, Florian Pflug wrote: > Per my theory about the cause of the problem in my other mail, I think you > might see StartupCLOG failures even during crash recovery, provided that > wal_level was set to hot_standby when the primary crashed. Here's how > > 1) We start a checkpoint, and get as far as LogStandbySnapshot() > 2) A backend does AssignTransactionId, and gets as far as GetTransactionoId(). > The assigned XID requires CLOG extension. > 3) The checkpoint continues, and LogStandbySnapshot () advances the > checkpoint's nextXid to the XID assigned in (2). > 4) We crash after writing the checkpoint record, but before the CLOG > extension makes it to the disk, and before any trace of the XID assigned > in (2) makes it to the xlog. > > Then StartupCLOG() would fail at the end of recovery, because we'd end up > with a nextXid whose corresponding CLOG page doesn't exist. No, clog extension is WAL-logged while holding the XidGenLock. At step 3, LogStandbySnapshot() would block until the clog-extension record is written to WAL, so crash recovery would see and replay that record before calling StartupCLOG(). That can happen during hot standby, though, because StartupCLOG() is called earlier. > My suggestion is to fix the CLOG problem in that same way that you fixed > the SUBTRANS problem, i.e. by moving LogStandbySnapshot() to before > CheckPointGuts(). > > Here's what I image CreateCheckPoint() should look like: > > 1) LogStandbySnapshot() and fill out oldestActiveXid > 2) Fill out REDO > 3) Wait for concurrent commits > 4) Fill out nextXid and the other fields > 5) CheckPointGuts() > 6) Rest > > It's then no longer necessary for LogStandbySnapshot() do modify > the nextXid, since we fill out nextXid after LogStandbySnapshot() and > will thus derive a higher value than LogStandbySnapshot() would have. Hmm, I don't think that fully fixes the problem. Even if you're certain that CheckPointGuts() has fsync'd the clog page to disk, VACUUM might decide to truncate it away again while the checkpoint is running. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com