| From: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Collect ALTER PUBLICATION commands for event triggers |
| Date: | 2026-07-24 02:06:42 |
| Message-ID: | CAHGQGwH-wWO=0406dbSiPvxNMhc-6TQK7ORZ_+9SyaR5fDsvyg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Collect-ALTER-PUBLICATION-mapping-drops-for-event.patch | application/octet-stream | 12.8 KB |
| v1-0002-Collect-ALTER-PUBLICATION-SET-ALL-commands-for-ev.patch | application/octet-stream | 5.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chao Li | 2026-07-24 02:23:53 | Re: Fix missing FORMAT when deparsing JSON_ARRAY(query) |
| Previous Message | ZizhuanLiu X-MAN | 2026-07-24 02:01:12 | Re: COMMENTS are not being copied in CREATE TABLE LIKE |