Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4BBE91337B2F for ; Tue, 19 Oct 2010 06:27:03 -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 28167-07 for ; Tue, 19 Oct 2010 09:26:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og122.obsmtp.com (exprod7og122.obsmtp.com [64.18.2.22]) by mail.postgresql.org (Postfix) with SMTP id 88DCD1335B36 for ; Tue, 19 Oct 2010 06:26:52 -0300 (ADT) Received: from source ([209.85.215.45]) by exprod7ob122.postini.com ([64.18.6.12]) with SMTP ID DSNKTL1kXAQrz8LX20MGkve3Y7CO0+iU0IN0@postini.com; Tue, 19 Oct 2010 02:26:53 PDT Received: by mail-ew0-f45.google.com with SMTP id 26so1802299ewy.18 for ; Tue, 19 Oct 2010 02:26:52 -0700 (PDT) Received: by 10.213.28.205 with SMTP id n13mr5182920ebc.5.1287480410521; Tue, 19 Oct 2010 02:26:50 -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 b52sm2612511eei.13.2010.10.19.02.26.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 19 Oct 2010 02:26:49 -0700 (PDT) Message-ID: <4CBD6458.4050400@enterprisedb.com> Date: Tue, 19 Oct 2010 12:26:48 +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> In-Reply-To: <1287355728.8516.383.camel@jdavis> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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/170 X-Sequence-Number: 28460 On 18.10.2010 01:48, Jeff Davis wrote: > 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. Makes sense. I wonder if we could just move the rename() after reading the checkpoint record? > 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. I guess, although it's really not appropriate that the database doesn't recover after a crash during a base 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). Right, that's not good either. One alternative is to not remove any WAL files during a base backup. The obvious downside is that if the backup takes a long time, you run out of disk space. The fundamental problem is that by definition, a base backup is completely indistinguishable from the data directory in the original server. Or is it? We recommend that you exclude the files under pg_xlog from the backup. So we could create a "pg_xlog/just_kidding" file along with backup_label. When starting recovery, if just_kidding exists, we can assume that we're doing crash recovery and ignore backup_label. 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? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com