Collect ALTER PUBLICATION commands for event triggers
Collect ALTER PUBLICATION commands for event triggers
Hi,
I found two cases where ALTER PUBLICATION fires ddl_command_end,
but pg_event_trigger_ddl_commands() does not report the corresponding
ALTER PUBLICATION command.
Attached are two patches.
0001 patch: Collect ALTER PUBLICATION mapping drops
When an ALTER PUBLICATION command only removes publication membership mappings,
the publication itself is not collected as a ddl_command_end object.
For example:
ALTER PUBLICATION p DROP TABLE t1;
ALTER PUBLICATION p SET TABLE t2;
sql_drop reports the removed publication relation,
but pg_event_trigger_ddl_commands() reports no corresponding
ALTER PUBLICATION entry. This seems like a bug to me. Thoughts?
0001 patch fixes the issue by detecting when table or schema membership
mappings are removed and collecting the publication itself once as the
ALTER PUBLICATION command.
As a side-effect of this fix, SET commands that both remove and add
memberships may now produce both a publication-level entry and
the existing per-membership entries for additions. This is intentional,
since they represent different parts of the command.
I think this should be backpatched to all supported branches. But,
if the above behavioral change is considered too risky for backpatching,
though, I'm fine with applying it only to master. Thoughts?
0002: Collect ALTER PUBLICATION SET ALL changes
ALTER PUBLICATION ... SET ALL TABLES and SET ALL SEQUENCES have
a similar issue. These commands fire ddl_command_end,
but pg_event_trigger_ddl_commands() can return no entry.
0002 patch fixes the issue by making AlterPublicationAllFlags() report
whether the publication state changed. If it did, the publication itself is
collected as the ALTER PUBLICATION command.
As a side-effect of this fix, SET ALL TABLES ... EXCEPT (...) may now produce
both a publication-level entry and the existing per-membership entries for
added exclusions. This is intentional, since they represent different parts
of the command.
I think this should be backpatched to v19, where
ALTER PUBLICATION SET ALL TABLES and SET ALL SEQUENCES were introduced.
Regards,
--
Fujii Masao
Re: Collect ALTER PUBLICATION commands for event triggers
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Jul 24, 2026, at 10:06, Fujii Masao wrote: > > Hi, > > I found two cases where ALTER PUBLICATION fires ddl_command_end, > but pg_event_trigger_ddl_commands() does not report the corresponding > ALTER PUBLICATION command. > > Attached are two patches. > > 0001 patch: Collect ALTER PUBLICATION mapping drops > > When an ALTER PUBLICATION command only removes publication membership mappings, > the publication itself is not collected as a ddl_command_end object. > > For example: > ALTER PUBLICATION p DROP TABLE t1; > ALTER PUBLICATION p SET TABLE t2; > > sql_drop reports the removed publication relation, > but pg_event_trigger_ddl_commands() reports no corresponding > ALTER PUBLICATION entry. This seems like a bug to me. Thoughts? > > 0001 patch fixes the issue by detecting when table or schema membership > mappings are removed and collecting the publication itself once as the > ALTER PUBLICATION command. > > As a side-effect of this fix, SET commands that both remove and add > memberships may now produce both a publication-level entry and > the existing per-membership entries for additions. This is intentional, > since they represent different parts of the command. > > I think this should be backpatched to all supported branches. But, > if the above behavioral change is considered too risky for backpatching, > though, I'm fine with applying it only to master. Thoughts? > > > 0002: Collect ALTER PUBLICATION SET ALL changes > > ALTER PUBLICATION ... SET ALL TABLES and SET ALL SEQUENCES have > a similar issue. These commands fire ddl_command_end, > but pg_event_trigger_ddl_commands() can return no entry. > > 0002 patch fixes the issue by making AlterPublicationAllFlags() report > whether the publication state changed. If it did, the publication itself is > collected as the ALTER PUBLICATION command. > > As a side-effect of this fix, SET ALL TABLES ... EXCEPT (...) may now produce > both a publication-level entry and the existing per-membership entries for > added exclusions. This is intentional, since they represent different parts > of the command. > > I think this should be backpatched to v19, where > ALTER PUBLICATION SET ALL TABLES and SET ALL SEQUENCES were introduced. > > Regards, > > -- > Fujii Masao > Both v1-0001 and v1-0002 look good to me. While reviewing 0002, I noticed another suspicion. AlterPublicationAllFlags() directly updates the pg_publication tuple but doesn’t call InvokeObjectPostAlterHook(). This seems inconsistent with AlterPublicationOptions() and AlterPublicationOwner_internal(), which invoke that hook after altering the publication. As this is a separate issue from this patch, should I start a new thread? This seems an oversight of 493f8c6439c. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: Collect ALTER PUBLICATION commands for event triggers
От:
shihao zhong <zhong950419@gmail.com>
Дата:
> Sorry for the delay. V2 looks good to me.
I applied v2 on master with asserts and measured the output.
Please commit 0003 separately and soon. It is an unrelated five-line
fix for a v19 feature, and v19 has branched.
pubform = GETSTRUCT(tup) line;
0001/0002 collect when the catalog changed, but ddl_command_end means
the command ran. Measured, all three applied:
ADD TABLE t2 membership row only
SET TABLE t1,t2,t3 (same set) zero rows
DROP TABLE t1 publication row
SET (publish='insert') twice publication row both times
SET ALL TABLES (already all tables) zero rows
But one command now has two rules. And 0002's claim that it fixes "no
entry" for SET ALL TABLES is untrue for the no-op case
Hi,
Please commit 0003 separately and soon. It is an unrelated five-line
fix for a v19 feature, and v19 has branched.
Do we need the following line in 003?
pubform = GETSTRUCT(tup) line;
heap_modify_tuple() does not change the OID.
0001/0002 collect when the catalog changed, but ddl_command_end means
the command ran. Measured, all three applied:
ADD TABLE t2 membership row only
SET TABLE t1,t2,t3 (same set) zero rows
DROP TABLE t1 publication row
SET (publish='insert') twice publication row both times
SET ALL TABLES (already all tables) zero rows
But one command now has two rules. And 0002's claim that it fixes "no
entry" for SET ALL TABLES is untrue for the no-op case
I think weneed to fix the commit message.
Thanks,
Shihao