Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id BB4B21FB5A4E for ; Sun, 15 Apr 2012 21:41:24 -0300 (ADT) Received: from smtp182.dfw.emailsrvr.com ([67.192.241.182]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SJa0P-0002fM-On for pgsql-admin@postgresql.org; Mon, 16 Apr 2012 00:41:23 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp8.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id BF05681F9 for ; Sun, 15 Apr 2012 20:41:07 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp8.relay.dfw1a.emailsrvr.com (Authenticated sender: cernst-AT-zvelo.com) with ESMTPSA id 775BE80B8 for ; Sun, 15 Apr 2012 20:41:07 -0400 (EDT) Message-ID: <4F8B6AA1.1040709@zvelo.com> Date: Sun, 15 Apr 2012 18:41:05 -0600 From: Chris Ernst Organization: Zvelo, Inc. User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120411 Thunderbird/11.0.1 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Recreate primary key without dropping foreign keys? X-Enigmail-Version: 1.4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201204/75 X-Sequence-Number: 39411 Hi all, In PostgreSQL 9.1.3, I have a few fairly large tables with bloated primary key indexes. I'm trying to replace them using newly created unique indexes as outlined in the docs. Something like: CREATE UNIQUE INDEX CONCURRENTLY dist_id_temp_idx ON distributors (dist_id); ALTER TABLE distributors DROP CONSTRAINT distributors_pkey, ADD CONSTRAINT distributors_pkey PRIMARY KEY USING INDEX dist_id_temp_idx; However, the initial drop of the primary key constraint fails because there are a whole bunch of foreign keys depending on it. I've done some searching and haven't found a workable solution. Is there any way to swap in the new index for the primary key constraint without dropping all dependent foreign keys? Or am I pretty much stuck with dropping and recreating all of the foreign keys? Thanks in advance. Chris Ernst Data Operations Engineer Zvelo, Inc. http://zvelo.com/