Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 86B489FA618 for ; Thu, 9 Nov 2006 03:11:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 37054-10 for ; Thu, 9 Nov 2006 07:11:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 1CDF49F9424 for ; Thu, 9 Nov 2006 03:11:38 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id E27F756468; Thu, 9 Nov 2006 01:11:21 -0600 (CST) Received: (hashcash-sendmail, from uid 1001); Thu, 9 Nov 2006 01:11:19 -0600 Date: Thu, 9 Nov 2006 01:11:19 -0600 From: "Jim C. Nasby" To: Jerry Sievers Cc: pgsql-admin@postgresql.org Subject: Re: Manual sys catalog constraint setup to avoid downtime? Message-ID: <20061109071118.GF90133@nasby.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.1-RELEASE-p10 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.13 (2006-08-11) X-Hashcash: 1:20:061109:jerry@jerrysievers.com::7XR7uPXHAzqyRgR2:000000000000000 0000000000000000000000002q6b X-Hashcash: 1:20:061109:pgsql-admin@postgresql.org::h0HVIXxilzQITeDd:00000000000 0000000000000000000000002RNc X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/86 X-Sequence-Number: 23613 On Tue, Nov 07, 2006 at 11:05:38AM -0500, Jerry Sievers wrote: > Admins; this is (I assume) a not uncommon scenario). > > Suppose you are managing a BIG ugly DB that's in 24x7 production and > desperately in need of constraints of all types. > > (Of course, you inherited this piece of crap and the irresponsible > designers are long gone :-) > > You have verified that the application now honors the new constraints > because on your R&D DBs, the constraints are in place and no > constraint violations are occuring. > > You can't however get business to sign off on proper constraint > addition via ALTER TABLE because the tables are huge and this locks > out concurrent activity for several hours. > > My question; > > Have any of you setup the constraints by doing manual catalog updates > and later (or maybe never), gone back and cleaned up the > non-conforming data using small batch updates or deletes? > > Frobing of pg_constraint and pg_depend (at least) would be required. > > I'm wondering what non-obvious pitfalls exist here? > > Comments? Use the source, luke! Hmmm... interesting problem. For some constraints, I think you could probably handle things pretty well once we have non-blocking index creation (did that get into 8.2?). I guess the real key there would be if the constraint creation code will use indexes when checking the constraints. This would be especially useful for generic CHECK constraints... if you build an index that has a WHERE clause that matches the proposed constraint, the backend could just look to see if there are any entries in the index. If there aren't, you're good to go. In the meantime, I suggest using triggers to enforce your constraints, since you can create one without verifying the underlying data. -- Jim Nasby jim@nasby.net EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)