pgsql: Validate ALTER PUBLICATION after acquiring the publication lock.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Validate ALTER PUBLICATION after acquiring the publication lock.
Date: 2026-09-11 04:27:30
Message-ID: E1x4srJ-00000004O2J-2t1E@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Validate ALTER PUBLICATION after acquiring the publication lock.

AlterPublicationOptions() can use stale publication state when the
publication is modified concurrently while waiting for the publication
lock. In particular, a concurrent ALTER PUBLICATION ... SET ALL TABLES
can change puballtables, causing the validation to make decisions based
on the old value and leads to assertion failure. Likewise,
CheckAlterPublication() could miss a table added concurrently, letting
SET ALL TABLES EXCEPT (...) leave pg_publication_rel with a mixture of
inclusion and exclusion rows.

Fix by acquiring the lock and re-reading the publication tuple in
AlterPublication() before either path runs, and by calling
CheckAlterPublication() only after that.

Also fix 037_except.pl, which left one computed result untested and
silently reused a subscription created by an earlier test.

Author: Vignesh C <vignesh21(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Reviewed-by: Hayato Kuroda <kuroda(dot)hayato(at)fujitsu(dot)com>
Discussion: https://postgr.es/m/CALDaNm1r2MkGu6h8zgU1Kj1sX-FcMQ7wGTeLSnhx-5joiyXEvg@mail.gmail.com
Backpatch-through: 19, where it was introduced

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5624de9904ca560c0d4473cb9e86108f4b69be38

Modified Files
--------------
src/backend/commands/publicationcmds.c | 73 ++++++++++++++++++----------------
src/test/subscription/t/037_except.pl | 21 +++++-----
2 files changed, 51 insertions(+), 43 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2026-09-11 08:51:11 pgsql: Fall back to SPI for RI checks with mismatched index collations
Previous Message Michael Paquier 2026-09-11 03:34:19 pgsql: Add relation option toast_value_type