pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: exclusion@gmail.com
Subject: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key
Date: Sun, 22 Sep 2024 14:00:00 +0000
Message-ID: <18628-4f11be4e0b1c9002@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      18628
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 17rc1
Operating system:   Ubuntu 22.04
Description:        

The following script:
for ((i=1;i<=100;i++)); do
psql  -q -c "DROP TABLE IF EXISTS pt, p1, p2 CASCADE;"

echo "
CREATE TABLE pt (id int PRIMARY KEY, rid int,
  FOREIGN KEY (rid) REFERENCES pt(id))
PARTITION BY LIST (id);

CREATE TABLE p1 PARTITION OF pt FOR VALUES IN (1);
CREATE TABLE p2 (id int PRIMARY KEY, rid int);
" | psql -q

psql -c "ALTER TABLE pt DETACH PARTITION p1;" &
psql -c "ALTER TABLE pt ATTACH PARTITION p1 FOR VALUES IN (1);" &
psql -c "ALTER TABLE pt ATTACH PARTITION p2 FOR VALUES IN (2);"
wait

echo  "
ALTER TABLE pt DETACH PARTITION p1;
" | psql 2>&1 | grep 'could not find' && break;
done

psql -c "
SELECT c.conname, c.oid, t.tgname, tgtype
FROM pg_trigger t, pg_constraint c, pg_class cl
WHERE tgconstraint = c.oid AND conrelid = cl.oid AND
  cl.relname = 'p1';"

ends up with:
ERROR:  could not find ON INSERT check triggers of foreign key constraint
16409

and the p1 constraints at the end are:
   conname   |  oid  |            tgname            | tgtype 
-------------+-------+------------------------------+--------
 p1_rid_fkey | 16409 | RI_ConstraintTrigger_a_16410 |      9
 p1_rid_fkey | 16409 | RI_ConstraintTrigger_a_16411 |     17
 pt_rid_fkey | 16399 | RI_ConstraintTrigger_c_16400 |      5
 pt_rid_fkey | 16399 | RI_ConstraintTrigger_c_16401 |     17
(4 rows)

Whilst when the partition is in normal conditions, it's constraints are:
   conname   |  oid  |            tgname            | tgtype 
-------------+-------+------------------------------+--------
 pt_rid_fkey | 19171 | RI_ConstraintTrigger_a_19182 |      9
 pt_rid_fkey | 19171 | RI_ConstraintTrigger_a_19183 |     17
 pt_rid_fkey | 19171 | RI_ConstraintTrigger_c_19172 |      5
 pt_rid_fkey | 19171 | RI_ConstraintTrigger_c_19173 |     17

Reproduced on REL_15_STABLE (starting from 4566345cf) .. master.



view thread (7+ messages)  latest in thread

Message-ID: <18628-4f11be4e0b1c9002@postgresql.org>
Permalink:  ../18628-4f11be4e0b1c9002@postgresql.org/
Also on:    postgresql.org/message-id/18628-4f11be4e0b1c9002@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, exclusion@gmail.com
  Subject: Re: BUG #18628: Race condition during attach/detach partition breaks constraints of partition having foreign key
  In-Reply-To: <18628-4f11be4e0b1c9002@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox