Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id A95382E0083 for ; Mon, 9 Jun 2008 12:43:18 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 26384-05 for ; Mon, 9 Jun 2008 12:43:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail129178.authsmtp.co.uk (outmail129178.authsmtp.co.uk [62.13.129.178]) by developer.postgresql.org (Postfix) with ESMTP id 1E5C12E0067 for ; Mon, 9 Jun 2008 12:43:14 -0300 (ADT) Received: from mail.authsmtp.com (mail.authsmtp.com [62.13.128.187]) by punt3.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m59Fgw42044216; Mon, 9 Jun 2008 16:42:58 +0100 (BST) Received: from [192.168.0.3] (85-211-228-245.dyn.gotadsl.co.uk [85.211.228.245]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m59Fgp7X094580; Mon, 9 Jun 2008 16:42:51 +0100 (BST) Subject: Re: pg_dump restore time and Foreign Keys From: Simon Riggs To: Andrew Dunstan Cc: Tom Lane , Decibel! , Robert Treat , pgsql-hackers@postgresql.org In-Reply-To: <484D4AE7.2050209@dunslane.net> References: <1212647003.19964.19.camel@ebony.site> <4847D4A7.70309@dunslane.net> <1212670595.19964.55.camel@ebony.site> <200806071308.00845.xzilla@users.sourceforge.net> <1212860515.12046.78.camel@ebony.site> <484ADAD4.2080701@dunslane.net> <19362.1213023432@sss.pgh.pa.us> <1213024379.12046.111.camel@ebony.site> <484D4AE7.2050209@dunslane.net> Content-Type: text/plain Date: Mon, 09 Jun 2008 16:46:19 +0100 Message-Id: <1213026379.12046.119.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: b888933b-363a-11dd-8155-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksacxtFaAxbZ0xf HGQLW1xEUVt7XWF/ bggfZQBDYEtPQQdo WFZLRldNFgBqBAMB SEMbW28lNwIueHd0 YE5iEHJSX000J051 SkdXFj8bZmFjOX0e URQMagtVdQZXfh9E a1h6AHAKZjZWKBg1 TUcAHxkaHhhlExEd Wg46IU8XWQ4REyUg QAoPVSkuGEBNTiM/ ZzIhMFMdE0BZEUgj KjNh X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:1045/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/397 X-Sequence-Number: 119510 On Mon, 2008-06-09 at 11:23 -0400, Andrew Dunstan wrote: > > Simon Riggs wrote: > > On Mon, 2008-06-09 at 10:57 -0400, Tom Lane wrote: > > > >> Decibel! writes: > >> > >>> Actually, in the interest of stating the problem and not the > >>> solution, what we need is a way to add FKs that doesn't lock > >>> everything up to perform the key checks. > >>> > >> Ah, finally a useful comment. I think it might be possible to do an > >> "add FK concurrently" type of command that would take exclusive lock > >> for just long enough to add the triggers, then scan the tables with just > >> AccessShareLock to see if the existing rows meet the constraint, and > >> if so finally mark the constraint "valid". Meanwhile the constraint > >> would be enforced against newly-added rows by the triggers, so nothing > >> gets missed. You'd still get a small hiccup in system performance > >> from the transient exclusive lock, but nothing like as bad as it is > >> now. Would that solve your problem? > >> > > > > That's good, but it doesn't solve the original user complaint about > > needing to re-run many, many large queries to which we already know the > > answer. > > > But we don't know it for dead sure, we only think we do. What if the > data for one or other of the tables is corrupted? We'll end up with data > we believe is consistent but in fact is not, ISTM. If you can somehow > guarantee the integrity of data in both tables then we might be > justified in assuming that the FK constraint will be consistent - that's > why I suggested some sort of checksum mechanism might serve the purpose. Agreed. Can we get COPY to output the checksum of its output as part of the command tag? How else can we return the checksum? In $file.cksum for any given output file? We can then use an explicit checksum option in the COPY when we reload, with CHECKSUM option. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support