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.96) (envelope-from ) id 1vpKhd-005vOR-3A for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Feb 2026 06:24:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vpKhd-009Q7M-0I for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Feb 2026 06:24:56 +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.96) (envelope-from ) id 1vpKhc-009Q7D-2F for pgsql-bugs@lists.postgresql.org; Mon, 09 Feb 2026 06:24:56 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vpKha-00000001EUa-1mLJ for pgsql-bugs@lists.postgresql.org; Mon, 09 Feb 2026 06:24:55 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7cfcb46ffc9so2849288a34.0 for ; Sun, 08 Feb 2026 22:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770618294; cv=none; d=google.com; s=arc-20240605; b=UPOs6u08zzUwwWTdP+G97powOD8ZKP7Us+IBgjFnKMXutXj57z16Z60+UA6uOyynez ZU5EpAVkKCHQYDoy7g/7phR4utJ3E5WElbNOGB8Vftdq6wHeMPYAPYwxjaHw6JlBOeZQ RbAgLEMPnUBzdxdAd7sV0lI1D+F7ehdZ5zdFN8e0IkBgVl3dJxP4a3WJtnLf6OFR/SAO P684TORx7xUXZPjAGUF4g1MtMc+mAIgBxtavyaPhdmZZD+PgMz2DkzzKf18AdgE/e58M 2Wr4wb7ecCDvITJj3NheFV11aGu6Dws6ywLRU21JzyGPVe7uWpoJ3El16++/sgzOFEif bGEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=q/ef7F1JTqqMfi1IFUbv/BSsbgdgPodW7j2lOsxAYlE=; fh=vR25N3+d8dNHUTLhu+5NPbhqmVDzmSWekj9cOnxEonw=; b=MCK/ztn7Z9yu+dZdYlJ0EMdO5IcKcJBRD0EhSuDn2EHb4zkilSvZfPrFjhXJ4gi5Ub x1GLroQ3K3xU9cAaxH86hXQqrgGYGbg5LJXMnqQMZc159JhEG48A/JE4/J726l+DCBGf hkpkmnqzYGrLpAJsCd/cLwNflTV1aM8aeKUa4OYYR8GJN2aRR3DGIeI84uxVBjt0UItd nDKKaMd65yZV7pi57iDGI66cwLKraHMY0W56wzHQQCjzNaLPZ3ogHyspU2ms15JX7zKU XYsQhg0b5wguxm6+e2rwjrUpq7hXRbAxXKJleH7Oqh9PSjHSkQxi6h9XhY5uNfrxmqJI hibA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770618294; x=1771223094; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=q/ef7F1JTqqMfi1IFUbv/BSsbgdgPodW7j2lOsxAYlE=; b=CU874gqpWNsnu6eb9Ws4ZR4PfOXb+0Ep5IcZgZFc8xJp5LqwLCUM+Ee1NsMnTerjTY ACqVRBiDQK8qKSKUWP2NM2WtQTEUWxmi6N59tkyzoNIMtscoel5ku2zRZ2LzVCdvw/fQ F++Z6nUJglUxUN7XXo6KHVnqdQMnEK1fNZebXgMmYLwnYl36lljq/hXe2/G67v5km6dQ 1Qq8wtMOD0FQHf4VAkXLwLIdMtif90dlFT99HFHnP/CZouz1stYQGzubobXEfdqHco0d Wbf9SQJSjSrOPQY5/Eyx8qfWYZpZfmrL0LsUcfB/TU3KFU9BlldnFqP2cV6d3+GS9iRC UgbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770618294; x=1771223094; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=q/ef7F1JTqqMfi1IFUbv/BSsbgdgPodW7j2lOsxAYlE=; b=HN8FjfYCwHEdu7ikm9JDEl3CVrkO5gwsrJVzIZ/QE8dhbndZjEhTTeruvpxfGaVUGU Wsw99L1ALeMR2ySr1UfW9znu8eVnJW8otwHb37nRhWRX1+z31liqL3nXbqv2ATHx5+vy 8vq2NN3RNrYIK/WcI4VrOF+P4UIqH1TPjZHA9ZtuCSAKybhruSOgXAuxbUTJQC3ep8QY v6kdDODCZ1DLI+hvcDBjGh20KGr8v0wwB//2zkGEM82srXawmHmrCl8g0VYej2k1rYjc Js1TBNoVNhhTvN7FknijSdkuCNkcRxOuoNcPp057Zv4Y9kF8L/vjeHHcR9ppDE6pBNKc k/eg== X-Gm-Message-State: AOJu0YwDU/XET+PIyOZk7/5S8YWpx5vdP9IfrAdJy/ihRZQfk5hYewgd vzlz8/jn5v5nzoeMut6QE6hiVgRPcyPYaJJvaWypCNWvCAnmP19icw9GSd3dC0fCNY451dp72SG l9aPuYzAaJrQSzHLW3aHrTKN4LAFqlKbt31o4z0k= X-Gm-Gg: AZuq6aJk0A4WuXsLiGjPdGDgRc8kBhF+ChuYOCQ8T0YqcRXXcZkPloEX+fe8etImCdK X5jze8IH/X/97RwIFTbuEVwlM13m9FBx+18VpOnr0k4bFnDv7hkgA9vn1fLEU7ANPhk5hF1rUqY ubv+DTUWRpL/RUj6OKsbxHPl9etiJapeGQcHVV7T4+5tIWHqWwS2A69S3/S5imoAFJLp5agMzYG vKoXRI4mHrnAIrhYjyo+x31ErEIqKBq4fNfYkqhIoBcrXJW1InzXKk5m1qdle/bXzIV9f9TQSPN l4uRVGUrFFltArCZnDhgya+/xCjdrvZue38XyRJ7W3F4/2BI5x9EY/0= X-Received: by 2002:a05:6820:3097:b0:661:1ae2:baaa with SMTP id 006d021491bc7-66ba7e7c971mr6549899eaf.34.1770618293661; Sun, 08 Feb 2026 22:24:53 -0800 (PST) MIME-Version: 1.0 References: <19393-6a82427485a744cf@postgresql.org> <2b3a2cd5f9b6e82fba6ac45b413291b01dd252ea.camel@cybertec.at> <61c535617992fff830961ecc09a9c20096bc1f36.camel@cybertec.at> In-Reply-To: <61c535617992fff830961ecc09a9c20096bc1f36.camel@cybertec.at> From: =?UTF-8?Q?H=C3=BCseyin_Demir?= Date: Mon, 9 Feb 2026 07:24:42 +0100 X-Gm-Features: AZwV_QhELrxHfcd_gpxUGv2rXhkGk5qPdGnJPhx3qMJrjAYtuXhcI2yVH09Mchw Message-ID: Subject: Re: BUG #19393: pg_upgrade fails with duplicate key violation when CHECK constraint named *_not_null exists To: Laurenz Albe Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000006d3735064a5e32fd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006d3735064a5e32fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Laurenz, Thanks for the patch and LGTM for PostgreSQL 18. I tried to create following table on PG18 benchmark=3D# CREATE TABLE two_not_null_constraints ( col integer NOT NULL, CONSTRAINT two_not_null_constraints_col_not_null CHECK (col IS NOT NULL) ); ERROR: duplicate key value violates unique constraint "pg_constraint_conrelid_contypid_conname_index" DETAIL: Key (conrelid, contypid, conname)=3D(16385, 0, two_not_null_constraints_col_not_null) already exists. In PG17 I was able to create the table. benchmark=3D# CREATE TABLE two_not_null_constraints ( col integer NOT NULL, CONSTRAINT two_not_null_constraints_col_not_null CHECK (col IS NOT NULL) ); CREATE TABLE benchmark=3D# SELECT conname, contype FROM pg_constraint WHERE conrelid =3D 'two_not_null_constraints'::regclass ORDER BY conname; DROP TABLE two_not_null_constraints; -[ RECORD 1 ]---------------------------------- conname | two_not_null_constraints_col_not_null contype | c One question during the tests should we confirm the output of pg_constraint table ? It would make sense during the tests but the current test is also good to proceed. benchmark=3D# SELECT conname, contype FROM pg_constraint WHERE conrelid =3D 'two_not_null_constraints'::regclass ORDER BY conname; conname | contype ----------------------------------------+--------- two_not_null_constraints_col_not_null | n two_not_null_constraints_col_not_null1 | c (2 rows) Laurenz Albe , 5 =C5=9Eub 2026 Per, 17:52 tarihin= de =C5=9Funu yazd=C4=B1: > On Thu, 2026-02-05 at 15:58 +0100, I wrote: > > The bug is actually not in pg_upgrade, but in CREATE TABLE. The > attached patch > > fixes the problem for me by avoiding given constraint names when > generating > > the names for NOT NULL constraints. > > ... and here is v2, including a regression test. > > Yours, > Laurenz Albe > --0000000000006d3735064a5e32fd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Laurenz,

Thanks for the = patch and LGTM for PostgreSQL 18.

I tried to crea= te following table on PG18

benchmark=3D# CREA= TE TABLE two_not_null_constraints (
col integer NOT NULL,
CONSTRAINT two_not_null_constraints_col_not_null CHECK (col IS= NOT NULL)
);
ERROR: duplicate key value violates un= ique constraint "pg_constraint_conrelid_contypid_conname_index"
DETAIL: Key (conrelid, contypid, conname)=3D(16385, 0, two_not_nu= ll_constraints_col_not_null) already exists.

In PG17 I was able to create the table.

benc= hmark=3D# CREATE TABLE two_not_null_constraints (
col intege= r NOT NULL,
CONSTRAINT two_not_null_constraints_col_not_null = CHECK (col IS NOT NULL)
);
CREATE TABLE
benc= hmark=3D# SELECT conname, contype FROM pg_constraint
WHERE co= nrelid =3D 'two_not_null_constraints'::regclass
ORDER = BY conname;
DROP TABLE two_not_null_constraints;
-[ RE= CORD 1 ]----------------------------------
conname | two_not_null= _constraints_col_not_null
contype | c

<= div>
One question during the tests should we confirm the outp= ut of pg_constraint table ? It would make sense during the tes= ts but the current test is also good to proceed.

=
benchmark=3D# SELECT conname, contype FROM pg_constraint
= WHERE conrelid =3D 'two_not_null_constraints'::regclass
= ORDER BY conname;
conname | c= ontype
----------------------------------------+---------
<= div> two_not_null_constraints_col_not_null | n
two_not_null_con= straints_col_not_null1 | c
(2 rows)

Laurenz Albe <laurenz.al= be@cybertec.at>, 5 =C5=9Eub 2026 Per, 17:52 tarihinde =C5=9Funu yazd= =C4=B1:
On Thu, = 2026-02-05 at 15:58 +0100, I wrote:
> The bug is actually not in pg_upgrade, but in CREATE TABLE.=C2=A0 The = attached patch
> fixes the problem for me by avoiding given constraint names when gener= ating
> the names for NOT NULL constraints.

... and here is v2, including a regression test.

Yours,
Laurenz Albe
--0000000000006d3735064a5e32fd--