Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 5BC082E008B for ; Mon, 9 Jun 2008 14:52:19 -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 56689-05-4 for ; Mon, 9 Jun 2008 14:52:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail137175.authsmtp.co.uk (outmail137175.authsmtp.co.uk [62.13.137.175]) by developer.postgresql.org (Postfix) with ESMTP id 1FB8C2E00A7 for ; Mon, 9 Jun 2008 14:51:58 -0300 (ADT) Received: from mail-c188.authsmtp.com (mail-c188.authsmtp.com [62.13.128.25]) by punt6.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id m59HpbVi083613; Mon, 9 Jun 2008 18:51:37 +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 m59HpZ64064173; Mon, 9 Jun 2008 18:51:36 +0100 (BST) Subject: Re: pg_dump restore time and Foreign Keys From: Simon Riggs To: Robert Treat Cc: Tom Lane , Decibel! , Andrew Dunstan , pgsql-hackers@postgresql.org In-Reply-To: <200806091237.49153.xzilla@users.sourceforge.net> References: <1212647003.19964.19.camel@ebony.site> <1213026485.12046.123.camel@ebony.site> <20406.1213027167@sss.pgh.pa.us> <200806091237.49153.xzilla@users.sourceforge.net> Content-Type: text/plain Date: Mon, 09 Jun 2008 18:54:57 +0100 Message-Id: <1213034097.12046.150.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Server-Quench: b482965d-364c-11dd-aecc-001871e930f4 X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksacxtFaAxbZ0xf HGQLW1xEUVV7XGJ/ aAwfZQBDYEtPQQdo WFZLRldNFgBqBAMB SEMbW2EyHQNCeHh0 ZEFhEHNbWkY0J0J1 QEdSEDkbZmFkO30e URQMalIBI1BXfh9E Yld+AXoOYTMDKBg1 TUcAHxkaHhhlExEd Wg46IU8XWQ4REyUg QAoPVSkuGEBNTiM/ ZzIhMFMdE0BZEUgj KjNh X-Authentic-SMTP: 61633235383639.cat.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/414 X-Sequence-Number: 119527 On Mon, 2008-06-09 at 12:37 -0400, Robert Treat wrote: > On Monday 09 June 2008 11:59:27 Tom Lane wrote: > > Simon Riggs writes: > > > On Mon, 2008-06-09 at 11:33 -0400, Tom Lane wrote: > > >> No, we are running a large query to which the user *thinks* he knows the > > >> answer. There are any number of reasons why he might be wrong. > > > > > > Of course. I should have said "to which we already know the answer" to > > > indicate I'm passing on others' criticisms of us. > > > > [ shrug... ] We don't know the answer either, and anyone who says > > we do is merely betraying his ignorance of the number of ways to load > > a foot-gun. > > > > I think the more realistic scenario (based on the FK idea) is that you want to > prevent any future rows from coming without validating the FK, and you're > willing to clean up any violators after the fact, since you can make that > an "out of the critical path" operation. > > if you extend this to a more general "create constraint concurrently" (to > handle normal constraint, not null constraints, etc...), it would certainly > be a big win, and i think most would see it as a reasonable compromise. Agreed. I think the "out of the critical path" action is more likely to be the intended path rather than the "never check at all" route. If we break down the action into two parts. ALTER TABLE ... ADD CONSTRAINT foo FOREIGN KEY ... NOVALIDATE; which holds exclusive lock, but only momentarily After this runs any new data is validated at moment of data change, but the older data has yet to be validated. ALTER TABLE ... VALIDATE CONSTRAINT foo which runs lengthy check, though only grabs lock as last part of action This way we have the ability to add them concurrently if we choose by running one after the other, or we can run first part only for now and run the other one at a more convenient moment. On a full set of checks on a large complex database can easily take hours or even days. We should allow this. It's not a footgun, its an honest attempt by people to add RI checks to their database. The only other alternative for some people is to not add FKs at all, which is also a footgun, but we don't seem bothered that they might take that option. -- Simon Riggs www.2ndQuadrant.com PostgreSQL Training, Services and Support