From 99861c3a304dba9d8b9c1f1f2fc01b4f0360da55 Mon Sep 17 00:00:00 2001 From: Ayush Tiwari Date: Sun, 17 May 2026 14:18:27 +0000 Subject: [PATCH v1] Add stack depth check to QueueFKConstraintValidation() QueueFKConstraintValidation() recurses through the partition hierarchy to queue child constraint validations and to mark child rows as validated. On a sufficiently deep partition tree (the report uses roughly 48000 nested levels), the recursion exhausts the process stack and the backend crashes with SIGSEGV from deep inside the catalog access path. Other recursive helpers in tablecmds.c (and elsewhere in the backend) follow the convention of calling check_stack_depth() at function entry so that the process raises a controlled "stack depth limit exceeded" error well before we run out of stack. Do the same here. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/19482-4cc37cbf52d55235@postgresql.org --- src/backend/commands/tablecmds.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 92b0f38c353..b15b3198ce1 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -13275,6 +13275,12 @@ QueueFKConstraintValidation(List **wqueue, Relation conrel, Relation fkrel, HeapTuple copyTuple; Form_pg_constraint copy_con; + /* + * This function recurses through the partition hierarchy, so guard + * against stack overflow on very deeply nested partition trees. + */ + check_stack_depth(); + con = (Form_pg_constraint) GETSTRUCT(contuple); Assert(con->contype == CONSTRAINT_FOREIGN); Assert(!con->convalidated); -- 2.43.0