Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id ABBBB632CA9 for ; Thu, 14 Jan 2010 07:28:11 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 86815-02 for ; Thu, 14 Jan 2010 11:28:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail136049.authsmtp.co.uk (outmail136049.authsmtp.co.uk [62.13.136.49]) by mail.postgresql.org (Postfix) with ESMTP id 77FBC632672 for ; Thu, 14 Jan 2010 07:28:00 -0400 (AST) Received: from mail-c194.authsmtp.com (mail-c194.authsmtp.com [62.13.128.121]) by punt3.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id o0EBRiFa002256; Thu, 14 Jan 2010 11:27:44 GMT Received: from [192.168.0.3] (88-110-134-25.dynamic.dsl.as9105.com [88.110.134.25]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id o0EBRgS1052241; Thu, 14 Jan 2010 11:27:43 GMT Subject: Re: Small Bug in GetConflictingVirtualXIDs From: Simon Riggs To: Andres Freund Cc: pgsql-hackers@postgresql.org, Tom Lane , Alvaro Herrera In-Reply-To: <200912272011.27003.af@cybertec.de> References: <200912210402.37850.andres@anarazel.de> <200912220319.10264.af@cybertec.de> <1261478551.7442.4332.camel@ebony> <200912272011.27003.af@cybertec.de> Content-Type: multipart/mixed; boundary="=-yD4ei19/pwJ5isphKeOc" Date: Thu, 14 Jan 2010 11:27:42 +0000 Message-Id: <1263468462.26654.19743.camel@ebony> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 X-Server-Quench: d51d0389-00ff-11df-80b9-0022640b883e X-Report-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZOTQEd DAteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksachtFaQFbZ1hf HGQLWlREUVx7W2R/ bwkfZQ1DY0tOQQRp VFZLR01XHAJ3AVJe BmtsME4RdgVDenx0 ZAhjW3deWgoucEcp Qk1cHHAGZTE2dWEe BBZFfwMGeR5Kfh1H bFR/BnsFYjBJBC9q VzwTFhsSEA9kHWxu RwgJKRo4XElDHzh0 aB0eNjIpE0kETDky KRMYK0QAAU8VAmQe KjMA X-Authentic-SMTP: 61633235383639.1015:706/Kp X-AuthFastPath: 255 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.589 tagged_above=-10 required=5 tests=BAYES_00=-2.599, FH_DATE_PAST_20XX=3.188 X-Spam-Level: X-Archive-Number: 201001/1440 X-Sequence-Number: 154661 --=-yD4ei19/pwJ5isphKeOc Content-Type: text/plain Content-Transfer-Encoding: 7bit On Sun, 2009-12-27 at 20:11 +0100, Andres Freund wrote: > On Tuesday 22 December 2009 11:42:30 Simon Riggs wrote: > > On Tue, 2009-12-22 at 03:19 +0100, Andres Freund wrote: > > > On Monday 21 December 2009 16:48:52 Simon Riggs wrote: > > > > Giving the drop database a snapshot is not the answer. I expect Andres > > > > to be able to fix this with a simple patch that would not effect the > > > > case of normal running. > > > > > > Actually its less simply than I had thought at first - I don't think the > > > code ever handled that correctly. > > > I might be wrong there, my knowledge of the involved code is a bit > > > sparse... The whole conflict resolution builds on the concept of waiting > > > for an VXid, but an idle backend does not have a valid vxid. Thats > > > correct, right? > > I don't see any mileage in making Startup process wait for an idle > > session, so no real reason to wait for others either. > So here is a small patch implementing that behaviour. On further testing, I received a re-connection from an automatic session retry. That shouldn't have happened, but it indicates the need for locking around the conflict handler. I had understood that to be placed elsewhere but that seems wrong now. This is a low priority item, so looking for a quick fix to allow time on other areas. Any objections? -- Simon Riggs www.2ndQuadrant.com --=-yD4ei19/pwJ5isphKeOc Content-Disposition: attachment; filename="db_conflict_locking.patch" Content-Type: text/x-patch; name="db_conflict_locking.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit *** a/src/backend/commands/dbcommands.c --- b/src/backend/commands/dbcommands.c *************** *** 1944,1950 **** dbase_redo(XLogRecPtr lsn, XLogRecord *record) --- 1944,1958 ---- dst_path = GetDatabasePath(xlrec->db_id, xlrec->tablespace_id); if (InHotStandby) + { + /* + * Lock database while we resolve conflicts to ensure that InitPostgres() + * cannot fully re-execute concurrently. This avoids backends re-connecting + * automatically to same database, which can happen in some cases. + */ + LockSharedObjectForSession(DatabaseRelationId, xlrec->db_id, 0, AccessExclusiveLock); ResolveRecoveryConflictWithDatabase(xlrec->db_id); + } /* Drop pages for this database that are in the shared buffer cache */ DropDatabaseBuffers(xlrec->db_id); *************** *** 1960,1965 **** dbase_redo(XLogRecPtr lsn, XLogRecord *record) --- 1968,1984 ---- ereport(WARNING, (errmsg("some useless files may be left behind in old database directory \"%s\"", dst_path))); + + if (InHotStandby) + { + /* + * Release locks prior to commit. XX There is a race condition here that may allow + * backends to reconnect, but the window for this is small because the gap between + * here and commit is mostly fairly small and it is unlikely that people will be + * dropping databases that we are trying to connect to anyway. + */ + UnlockSharedObjectForSession(DatabaseRelationId, xlrec->db_id, 0, AccessExclusiveLock); + } } else elog(PANIC, "dbase_redo: unknown op code %u", info); --=-yD4ei19/pwJ5isphKeOc--