Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u6vC8-007o15-7J for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Apr 2025 17:44:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u6vC6-007L0n-9H for pgsql-bugs@arkaria.postgresql.org; Mon, 21 Apr 2025 17:44:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u6vC5-007L0d-ML for pgsql-bugs@lists.postgresql.org; Mon, 21 Apr 2025 17:44:34 +0000 Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u6vC3-001DWO-2Z for pgsql-bugs@postgresql.org; Mon, 21 Apr 2025 17:44:33 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 22861114016B; Mon, 21 Apr 2025 13:44:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Mon, 21 Apr 2025 13:44:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1745257470; x=1745343870; bh=l g5UaiaoEakRZXBoD517tyURFjOTTSage5roURo1wNk=; b=cYKVTJ5ppbDf8eYnl Xq4gPbf4r7rJvDUBspQwI+SM79LMo5j72QeOiwD1yj4hTbD5C3TLqu6N5wq3SVFK bcTmIdynujKG5DcdGcnwZswky/nU4ODi2Tvd3FE1RHZYG0pLUlWu6Htqdv8SNtjD /0OmD0AA83FAFgC7i+iYwTlzrNFcSu0WEvHi6bqv3nZczJ84PROC169wJWFqoi6n WBYnX8iWtcixtk32BpJM8iajySYCUZWUSl0Rc+Q77bWJcPkPK92EV8PKYMblKafe x6qtE5arikfI340wLvsXS1iToYIeYbKlH4lZluDTpbyobRgT5442vyD5fOPAlmQC 7SgaQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvgedugeekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddt jeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlh hvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffeh fffhjeejhffgieeuueekjeekfffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvg hrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsg gprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehrvghshhhk vghkihhrihhllhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdgsuhhgsh esphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglhesshhsshdrphhghhdr phgrrdhush X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 21 Apr 2025 13:44:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1745257467; bh=2Oy6sPbf3Br0ilh6qLDl+zF0U+n6khg3RI4pfu9CZpw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Zdca2RdPMT59PnBi7Hk20ADM83gguzTIYB96HfNOfMOT9wKDFNoKlRuyBAT3DN2Mn TH9NrexDfrA3wPgXqE9xH9TsX56WKXocuaxwG1NDKOTQR6ltIDzOmdegUGnfkmKyrB R5JAz4FF2Mks1RW6mfssJ/ojL4I57y3lYOcSaNSCr3nyMEhaRCfalIb3UIwiGjJtR8 SWV6rbcq+Zyrmut37wmLpGkrnqdnUR4cTTsNHoJ/aFcLxij2jSgsIgtPzDDYNSje5O TNo9U2G0zcUgwir4IyeGFVPu18VrMc/RJFoLoZJJbw0DQ3KhWJ/zjr07J7cdoNYskA 80Z76Yvcl0+bw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 6006290; Mon, 21 Apr 2025 19:44:27 +0200 (CEST) Date: Mon, 21 Apr 2025 19:44:27 +0200 From: Alvaro Herrera To: Tom Lane Cc: Kirill Reshke , pgsql-bugs@postgresql.org Subject: Re: Command order bug in pg_dump Message-ID: <202504211744.4mzfm7wytiye@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <592472.1745247403@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Apr-21, Tom Lane wrote: > I don't think this is pg_dump's fault: there is no such constraint > when the ALTER TABLE starts. Something inside the ALTER TABLE > recursion seems to be messing up if there is already another > similar FK constraint. This trace is pretty interesting: > > regression=# create database db1; > CREATE DATABASE > regression=# \c db1 > You are now connected to database "db1" as user "postgres". > db1=# create table tfk (i int unique) partition by range (i ); > CREATE TABLE > db1=# create table tfk_po partition of tfk for values from ( 0 ) to (1); > CREATE TABLE > db1=# create table tt (i int) partition by range (i ); > CREATE TABLE > db1=# create table tt_po partition of tt for values from ( 0 ) to (1); > CREATE TABLE > db1=# ALTER TABLE public.tt > db1-# ADD CONSTRAINT tt_a_fkey FOREIGN KEY (i) REFERENCES public.tfk(i); > ALTER TABLE > db1=# ALTER TABLE public.tt > db1-# ADD CONSTRAINT tt_i_fkey FOREIGN KEY (i) REFERENCES public.tfk(i); > ERROR: constraint "tt_i_fkey" for relation "tt" already exists Oh hah. So constraint tt_a_fkey has chosen the name tt_i_fkey for its internal sub-constraint object to point to the partitions, so when the user wants to created tt_i_fkey, the name available anymore. Maybe we can change the naming policy so that these internal constraint objects have names that are unlikely to be chosen by users, maybe by suffixing "fkey_int" instead of "fkey", or something like that. (We could even do "$1" and so on for this kind of constraint). In hindsight, it isn't such a great idea to let the system choose the best name for an internal implementation object. I'd probably not change this in versions 13 and 14 at all in any case, because the code is too different. I'm unsure whether this is enough of a bug to consider backpatching to 15-17; maybe we should just change 18 at this point, since I haven't heard of a user complaining about this. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Estoy de acuerdo contigo en que la verdad absoluta no existe... El problema es que la mentira sí existe y tu estás mintiendo" (G. Lama)