Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Us78L-0000wJ-TG for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Jun 2013 08:00:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Us78L-0001wv-DN for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Jun 2013 08:00:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Us78K-0001wo-7u for pgsql-bugs@postgresql.org; Thu, 27 Jun 2013 08:00:48 +0000 Received: from moutng.kundenserver.de ([212.227.17.9]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Us78C-0001L0-TJ for pgsql-bugs@postgresql.org; Thu, 27 Jun 2013 08:00:47 +0000 Received: from anarazel.de (p5DDC50F3.dip0.t-ipconnect.de [93.220.80.243]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0MP3ch-1UwmEW2IK7-0063Zb; Thu, 27 Jun 2013 10:00:35 +0200 Received: by anarazel.de (Postfix, from userid 1000) id 1BAE010121E; Thu, 27 Jun 2013 10:01:35 +0200 (CEST) Date: Thu, 27 Jun 2013 10:01:35 +0200 From: Andres Freund To: lalbin@fhcrc.org Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8257: Multi-Core Restore fails when containing index comments Message-ID: <20130627080135.GA12870@awork2.anarazel.de> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wac7ysb48OaltWcw" Content-Disposition: inline In-Reply-To: X-Provags-ID: V02:K0:soi/ULoNKSKPxCcN7CUtXaLXW/yj7/100YGCqzbdxUm er//0r6/hf9LKQ26Vod1L2/Al++UiUDD17TiMLs74ANlH8eiaE zFCB77EvkdRZ2j73ZJsNNAXHWaEfyTBNPUE7YUNXOH7JL6uUuk qftOOPwSwHyupoETm3VYspc4HVIekhwpr9OtfKpI757F2oSTCd bvKbiio7jkkGnU/F1Xc57p5lQfHwzDwCVUECQsqYUXPx26xlgS +kCTmwi4WqhjoswDaCf/Gr4dImkdJ/a4tXBviTq1/SFfOUDb48 4jAU0vQMUEIcRPEPCUiarJcefwe4r5o98YvxFlfeQewHrwbI0p HxEdcGup4muqqmqliYXmneBL7gGn1EJei/VYXvsi+ X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --wac7ysb48OaltWcw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Lloyd, On 2013-06-26 23:43:00 +0000, lalbin@fhcrc.org wrote: > I have found the restore will fail when using pg_restore's -j option, with > more than one core, on a dump that contains a COMMENT INDEX. > Run this next section to add the table, index, and index comment to the > test_db database. > CREATE TABLE public.tbl_test ( > pkey TEXT NOT NULL, > CONSTRAINT tbl_test_pkey PRIMARY KEY(pkey) > ); > COMMENT ON INDEX public.tbl_test_pkey > IS 'Index Comment'; > Once this test database is created, create a backup of the database. > pg_dump -Fc test_db > test_db.dump The problem is that pg_dump makes the comment depend on the index instead of the constraint: ; Selected TOC Entries: ... 170; 1259 69261 TABLE public tbl_test andres ; depends on: 6 1941; 0 69261 TABLE DATA public tbl_test andres ; depends on: 170 1833; 2606 69268 CONSTRAINT public tbl_test_pkey andres ; depends on: 170 170 1950; 0 0 COMMENT public INDEX tbl_test_pkey andres ; depends on: 1832 There is no object 1832 in the dump since that was ommitted in favor of the constraint 1833 which internally creates the index. So what we need to do is to make the comment depend on the constraint instead. With the attached patch we get: 170; 1259 69261 TABLE public tbl_test andres ; depends on: 6 1941; 0 69261 TABLE DATA public tbl_test andres ; depends on: 170 1833; 2606 69268 CONSTRAINT public tbl_test_pkey andres ; depends on: 170 170 1950; 0 0 COMMENT public INDEX tbl_test_pkey andres ; depends on: 1833 unsurprisingly after that restore completes. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --wac7ysb48OaltWcw Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="fix-pg-dump-order-with-comment-on-index.patch" diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 2ce0cd8..107cabb 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -13493,6 +13493,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) PQExpBuffer q; PQExpBuffer delq; PQExpBuffer labelq; + bool is_constraint = indxinfo->indexconstraint != 0; if (dataOnly) return; @@ -13509,7 +13510,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) * do dump any comment for it. (This is safe because dependency ordering * will have ensured the constraint is emitted first.) */ - if (indxinfo->indexconstraint == 0) + if (!is_constraint) { if (binary_upgrade) binary_upgrade_set_pg_class_oids(fout, q, @@ -13547,11 +13548,15 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) NULL, NULL); } - /* Dump Index Comments */ + /* + * Dump Index Comments - depend on the constraint instead of the index if + * present to ensure sensible ordering. + */ dumpComment(fout, labelq->data, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, - indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId); + indxinfo->dobj.catId, 0, + is_constraint ? indxinfo->indexconstraint : indxinfo->dobj.dumpId); destroyPQExpBuffer(q); destroyPQExpBuffer(delq); --wac7ysb48OaltWcw Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --wac7ysb48OaltWcw--