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 1wOahT-0001IR-2F for pgsql-bugs@arkaria.postgresql.org; Sun, 17 May 2026 12:34:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wOahR-0008P8-2W for pgsql-bugs@arkaria.postgresql.org; Sun, 17 May 2026 12:34:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wOCkb-002gXW-1e for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 11:00:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wOCkY-00000000uZQ-3nJo for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 11:00:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=yCu3nAU93isHjchXbDyeAH27vjxbSZZy/WwlZzU5u0s=; b=WMRNQxP7it3p9Jr4m+Bjyge+Zk Tvyvsh1QtP/oyLbHpu9fWseYrRJRWifmuZsI5lSVReCbiKxrrV9OfUX4/ceK6g3zzBLAbMoZlUJWa UE8ZZh0TV8g7CEerH8PJDT8Gng88Pm6yS6Tt0eVhKXHP6AENTiHFf9MgquXbv3mYbfjuvKsCUulaX dEUQdIj698xE+bucMBYAhlYaS7ZtwhJh4j6vRtFBmyDAalBFIlEQXd+o9A8TQvLF6DVCKZlAI5fRq duPnDC76Rg5zm6KpOoKBafzGWkx3KNMu8eZTxW36bCeHAWEp2vDTHZunU2QjQJtf35VuhhNZDWmS1 AZvf5SzA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wOCkX-002Tio-1K for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 11:00:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wOCkV-0051fX-2o for pgsql-bugs@lists.postgresql.org; Sat, 16 May 2026 11:00:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19482: Recursive QueueFKConstraintValidation() lacks stack depth check To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: exclusion@gmail.com Reply-To: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 16 May 2026 11:00:01 +0000 Message-ID: <19482-4cc37cbf52d55235@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19482 Logged by: Alexander Lakhin Email address: exclusion@gmail.com PostgreSQL version: 18.4 Operating system: Ubuntu 24.04 Description: =20 The following script: echo " CREATE TABLE tp0 (a int, PRIMARY KEY (a)) PARTITION BY RANGE(a); ALTER TABLE tp0 ADD CONSTRAINT fk FOREIGN KEY (a) REFERENCES tp0 NOT VALID; " | psql for ((i=3D1;i<=3D48000;i++)); do # may take 2-3 hours echo "CREATE TABLE tp$i PARTITION OF tp$(( $i - 1 )) FOR VALUES FROM ($i) TO (1000000) PARTITION BY RANGE (a);"; done | psql > psql.log echo " ALTER TABLE tp0 VALIDATE CONSTRAINT fk; " | psql leads to: 2026-05-16 12:35:43.258 EEST|law|regression|6a083a6f.34aa38|LOG: statement: ALTER TABLE tp0 VALIDATE CONSTRAINT fk; 2026-05-16 12:35:56.104 EEST|||6a07f1d1.32a4c7|LOG: client backend (PID 3451448) was terminated by signal 11: Segmentation fault 2026-05-16 12:35:56.104 EEST|||6a07f1d1.32a4c7|DETAIL: Failed process was running: ALTER TABLE tp0 VALIDATE CONSTRAINT fk; Core was generated by `postgres: law regression 127.0.0.1(48420) ALTER TABLE '. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00005e57e8d06ae9 in hash_initial_lookup (hashp=3D0x5e580f378e10, hashvalue=3D795799848, bucketptr=3D0x7ffe0c940090) at dynahash.c:1767 1767 bucket =3D calc_bucket(hctl, hashvalue); (gdb) (gdb) (gdb) (gdb) #0 0x00005e57e8d06ae9 in hash_initial_lookup (hashp=3D0x5e580f378e10, hashvalue=3D795799848, bucketptr=3D0x7ffe0c940090)= at dynahash.c:1767 #1 0x00005e57e8d0545c in hash_search_with_hash_value (hashp=3D0x5e580f378e= 10, keyPtr=3D0x7ffe0c94010c, hashvalue=3D795799848, action=3DHASH_FIND, foundPt= r=3D0x0) at dynahash.c:1010 #2 0x00005e57e8d0538a in hash_search (hashp=3D0x5e580f378e10, keyPtr=3D0x7ffe0c94010c, action=3DHASH_FIND, foundPtr=3D0x0) at dynahash.c:= 961 #3 0x00005e57e8a7c224 in GetPrivateRefCountEntry (buffer=3D125, do_move=3D= true) at bufmgr.c:381 #4 0x00005e57e8a8051a in PinBuffer (buf=3D0x762990250980, strategy=3D0x0) = at bufmgr.c:3085 ... #20 0x00005e57e8ce0a15 in CheckNNConstraintFetch (relation=3D0x762989504168) at relcache.c:4619 #21 0x00005e57e8cd9b66 in RelationBuildTupleDesc (relation=3D0x762989504168) at relcache.c:701 #22 0x00005e57e8cdaa23 in RelationBuildDesc (targetRelId=3D464701, insertIt=3Dtrue) at relcache.c:1204 #23 0x00005e57e8cdc5cb in RelationIdGetRelation (relationId=3D464701) at relcache.c:2142 #24 0x00005e57e84d14d2 in relation_open (relationId=3D464701, lockmode=3D4)= at relation.c:58 #25 0x00005e57e85a16c8 in table_open (relationId=3D464701, lockmode=3D4) at table.c:44 #26 0x00005e57e877c41b in QueueFKConstraintValidation (wqueue=3D0x7ffe0d13d128, conrel=3D0x76299e17b6d0, fkrel=3D0x7629895039e8, pkrelid=3D16385, contuple=3D0x5e5850492148, lockmode=3D4) at tablecmds.c:13080 #27 0x00005e57e877c450 in QueueFKConstraintValidation (wqueue=3D0x7ffe0d13d128, conrel=3D0x76299e17b6d0, fkrel=3D0x762989503268, pkrelid=3D16385, contuple=3D0x5e5850491c98, lockmode=3D4) at tablecmds.c:13086 #28 0x00005e57e877c450 in QueueFKConstraintValidation (wqueue=3D0x7ffe0d13d128, conrel=3D0x76299e17b6d0, fkrel=3D0x762989502ae8, pkrelid=3D16385, contuple=3D0x5e58504917e8, lockmode=3D4) at tablecmds.c:13086 ... #37383 0x00005e57e877c450 in QueueFKConstraintValidation (wqueue=3D0x7ffe0d13d128, conrel=3D0x76299e17b6d0, fkrel=3D0x76299dd9b218, pkrelid=3D16385, contuple=3D0x5e580f357b98, lockmode=3D4) at tablecmds.c:13086 #37384 0x00005e57e877c450 in QueueFKConstraintValidation (wqueue=3D0x7ffe0d13d128, conrel=3D0x76299e17b6d0, fkrel=3D0x76299dd98358, pkrelid=3D16385, contuple=3D0x5e580f35d628, lockmode=3D4) at tablecmds.c:13086 #37385 0x00005e57e877c025 in ATExecValidateConstraint (wqueue=3D0x7ffe0d13d128, rel=3D0x76299dd98358, constrName=3D0x5e580f3554d8= "fk", recurse=3Dtrue, recursing=3Dfalse, lockmode=3D4) at tablecmds.c:12966 #37386 0x00005e57e876acde in ATExecCmd (wqueue=3D0x7ffe0d13d128, tab=3D0x5e580f354fc8, cmd=3D0x5e580f355488, lockmode=3D4, cur_pass=3DAT_PAS= S_MISC, context=3D0x7ffe0d13d320) at tablecmds.c:5497 #37387 0x00005e57e876a347 in ATRewriteCatalogs (wqueue=3D0x7ffe0d13d128, lockmode=3D4, context=3D0x7ffe0d13d320) at tablecmds.c:5334 #37388 0x00005e57e876968c in ATController (parsetree=3D0x5e580f32aa88, rel=3D0x76299dd98358, cmds=3D0x5e580f32aa38, recurse=3Dtrue, lockmode=3D4, context=3D0x7ffe0d13d320) at tablecmds.c:4889 #37389 0x00005e57e876929d in AlterTable (stmt=3D0x5e580f32aa88, lockmode=3D= 4, context=3D0x7ffe0d13d320) at tablecmds.c:4544 #37390 0x00005e57e8ae8380 in ProcessUtilitySlow (pstate=3D0x5e580f354470, pstmt=3D0x5e580f32ab38, queryString=3D0x5e580f329f60 "ALTER TABLE tp0 VALIDATE CONSTRAINT fk;", context=3DPROCESS_UTILITY_TOPLEVEL, params=3D0x0, queryEnv=3D0x0, dest=3D0x5e580f32aef8, qc=3D0x7ffe0d13d980) at utility.c:1321 Reproduced on REL_18_STABLE, starting from b663b9436, and on master.