| From: | shveta malik <shveta(dot)malik(at)gmail(dot)com> |
|---|---|
| To: | Hüseyin Demir <huseyin(dot)d3r(at)gmail(dot)com> |
| Cc: | "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, shveta malik <shvetamalik(at)gmail(dot)com> |
| Subject: | Re: [PATCH] Report changes discarded for relations not in the subscription |
| Date: | 2026-11-24 10:36:03 |
| Message-ID: | CAJpy0uCJh-kiyMOPiDJZNta+xhxhVELzgy8_NVe0c=A5zGOGvg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Fri, Oct 30, 2026 at 1:07 PM Hüseyin Demir <huseyin(dot)d3r(at)gmail(dot)com> wrote:
>
> Hi Hayato,
>
> > > Dear Hüseyin,
> > >
> > > > I encountered an issue after a pg_upgrade of a subscriber instance.
> > > > pg_subscription_rel came back empty, and the apply worker then discarded
> > > > every incoming change while the replication origin and the publisher
> > > > slot's confirmed_flush_lsn advanced past the discarded rows. Both ends
> > > > durably recording the transactions as applied, with nothing in either log
> > > > to say otherwise.
> > >
> > > To confirm, what was the datasabse version of old and new cluster? 9a17be1e2
> > > allowed to migrate the content of pg_subscription_rel catalog[1]. It means it's
> > > unexpected behavior and must be fixed if old one is PG17+.
> > >
> > > [1]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=9a17be1e2
> > >
> > > Best regards,
> > > Hayato Kuroda
> > > FUJITSU LIMITED
>
> Created a v2 patch and let me summarize the problem.
>
> If a table is added to a publication (ALTER PUBLICATION ... ADD TABLE)
> and ALTER SUBSCRIPTION ... REFRESH PUBLICATION is not run on the
> subscriber, the table has no pg_subscription_rel row. The apply
> worker drops every change for it in should_apply_changes_for_rel(),
> with no log message, no conflict and no statistics counter. The
> publisher is told the changes were applied, so the origin and the slot
> move past them. Rows only reappear if the table is later added and
> copied again.
>
> Report the skip from should_apply_changes_for_rel():
>
> - relation not in the subscription: LOG, with a hint to run ALTER
> SUBSCRIPTION ... REFRESH PUBLICATION
> - relation not yet synchronized: DEBUG2
>
> Each relation is reported once per sync state for the lifetime of the
> apply worker, tracked in LogicalRepRelMapEntry, since this gate is
> reached once per change. A restarted worker reports again.
I observed that this is not true. It actually depends on the lifetime
of LogicalRepRelMapEntry, not the apply worker. In
logicalrep_relmap_update(), the entry gets cleared, which resets
'last_unapplied_state' as well. logicalrep_relmap_update() is called
on each RELATION message from the publisher. This means that whenever
the missed table is altered on the publisher (e.g. create index, alter
table), the subscriber will log the message again on the subsequent
INSERT into that table. For DDL this is fine, as it is infrequent, but
for streamed transactions, it logs once for every streamed
transaction, as each streamed transaction sends the RELATION message
again (see the comment atop RelationSyncEntry in pgoutput.c). Is this
acceptable? See the test below:
On the publisher, set logical_decoding_work_mem = '64kB'. Create a
table tab1 (create table tab1 (a int);) on both nodes and add it to
the publication, but do not refresh the subscription. Then run on the
publisher:
INSERT INTO tab1 SELECT g FROM generate_series(1, 5000) g;
INSERT INTO tab1 SELECT g FROM generate_series(1, 5000) g;
INSERT INTO tab1 SELECT g FROM generate_series(1, 5000) g;
The subscriber logs "skipping changes for relation .." three times,
once per transaction.
thanks
Shveta
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fabrice Chapuis | 2026-11-24 11:16:18 | Re: unidirectional logical replication logging issue |
| Previous Message | Etsuro Fujita | 2026-11-24 10:20:46 | Re: postgres_fdw: statistics import can silently fall back to sampling across encodings |