Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BFBBC1337B56 for ; Sun, 17 Oct 2010 20:18:06 -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 52657-03 for ; Sun, 17 Oct 2010 23:17:59 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.161.174]) by mail.postgresql.org (Postfix) with ESMTP id D9A77133729E for ; Sun, 17 Oct 2010 20:17:58 -0300 (ADT) Received: by gxk6 with SMTP id 6so94882gxk.19 for ; Sun, 17 Oct 2010 16:17:58 -0700 (PDT) Received: by 10.150.211.19 with SMTP id j19mr5569142ybg.446.1287355734076; Sun, 17 Oct 2010 15:48:54 -0700 (PDT) Received: from [192.168.1.100] (c-76-102-27-65.hsd1.ca.comcast.net [76.102.27.65]) by mx.google.com with ESMTPS id m12sm13181430ybn.0.2010.10.17.15.48.52 (version=SSLv3 cipher=RC4-MD5); Sun, 17 Oct 2010 15:48:53 -0700 (PDT) Subject: Re: Recovery bug From: Jeff Davis To: pgsql-bugs@postgresql.org In-Reply-To: <1287183483.30681.54.camel@jdavis-ux.asterdata.local> References: <1287183483.30681.54.camel@jdavis-ux.asterdata.local> Content-Type: multipart/mixed; boundary="=-g4vPvmlHurheSKpXvttz" Date: Sun, 17 Oct 2010 15:48:48 -0700 Message-ID: <1287355728.8516.383.camel@jdavis> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 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, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201010/146 X-Sequence-Number: 28436 --=-g4vPvmlHurheSKpXvttz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit On Fri, 2010-10-15 at 15:58 -0700, Jeff Davis wrote: > I don't have a fix yet, because I think it requires a little discussion. > For instance, it seems to be dangerous to assume that we're starting up > from a backup with access to the archive when it might have been a crash > of the primary system. This is obviously wrong in the case of an > automatic restart, or one with no restore_command. Fixing this issue > might also remove the annoying "If you are not restoring from a backup, > try removing..." PANIC error message. > > Also, in general we should do more logging during recovery, at least the > first stages, indicating what WAL segments it's looking for to get > started, why it thinks it needs that segment (from backup or control > data), etc. Ideally we would verify that the necessary files exist (at > least the initial ones) before making permanent changes. It was pretty > painful trying to work backwards on this problem from the final > controldata (where checkpoint and prior checkpoint are the same, and > redo is before both), a crash, a PANIC, a backup_label.old, and not much > else. > Here's a proposed fix. I didn't solve the problem of determining whether we really are restoring a backup, or if there's just a backup_label file left around. I did two things: 1. If reading a checkpoint from the backup_label location, verify that the REDO location for that checkpoint exists in addition to the checkpoint itself. If not, elog with a FATAL immediately. 2. Change the error that happens when the checkpoint location referenced in the backup_label doesn't exist to a FATAL. If it can happen due to a normal crash, a FATAL seems more appropriate than a PANIC. The benefit of this patch is that it won't continue on, corrupting the pg_controldata along the way. And it also tells the administrator exactly what's going on and how to correct it, rather than leaving them with a PANIC and bogus controldata after they crashed in the middle of a backup. I still think it would be nice if postgres knew whether it was restoring a backup or recovering from a crash, otherwise it's hard to automatically recover from failures. I thought about using the presence of recoveryRestoreCommand or PrimaryConnInfo to determine that. But it seemed potentially dangerous if the person restoring a backup simply forgot to set those, and then it tries restoring from the controldata instead (which is unsafe to do during a backup). Comments? Regards, Jeff Davis --=-g4vPvmlHurheSKpXvttz Content-Type: application/x-gzip; name="recovery.patch.gz" Content-Disposition: attachment; filename="recovery.patch.gz" Content-Transfer-Encoding: base64 H4sIANR6u0wAA9VUTU/bQBA9h18xWILaqRPTFiKqikNKKEJyAVFQc0CqNutxvMLeDbtrIK34751d u05AtOqpUn3wx3w8z7w3s/1+H1hiNE9mjN+gzBLGORqTWM2kYVXyUKr5kG8MBgOY/UVc/+nlvmFv /937eG9/dxecCb5Ypm29mKZnx+GdElnkwdugvX2gr8EGQK+nkSudwQFcIMsOC+Q3CyWkvfDmkDvD uTOkisewE33wSSKHsE3cPIDTqzSNvP3Hxmu695J+84Q+fGY3CKbWCLZgFi6OJmdQKs6sUBLwQRhr hnBZCAMVW4JUFmbYJdsCgTODQP+jdwK5ZwYYcM1MAVmthZwDk6BkKSSCI61exF36fSF4ASXmlnIa 57eSzbAEplUts6YkjTkhS+KZor6O0y7d4LxCaX3UK3KWmhhaUn0oCYAX4g6z4a/opHmpsOKLZbi9 4i2GaarmROcx2gmzrOUtisGI76jy8LALjYhdj+Lo3XRp52yOTpdwe02JocZMUT5JG0POSoMxWF1j FDXZrQg96mqhtA0/jS/HacsKXSFqXZl5GHBVl5mnPBdEhkNdSdOxksFsCbybC2jKD6IVIBBgQa4w OMlhqWoiBz2sRmOV1yjXquo0cNUuyVmpO+dzIueiRLgOtkyyLtN1MAxicKRNhI46dh7p4aet63By 9PHq+E3cGNc7fF420JyR5FvTZGsadPG93pMxH7otE1kMz6wOIs99HS8v4O7I7dbb3y2g+9ujvyNp 1u7L5nof5+PTk8MX2uiE8vIgNXNbC9LrZV3a9H8oS9NZc8CMdoiE0Wh1wPy55XY4/9OWfwJ67ExG 2QUAAA== --=-g4vPvmlHurheSKpXvttz--