| From: | shveta malik <shveta(dot)malik(at)gmail(dot)com> |
|---|---|
| To: | Cagri Biroglu <cagri(dot)biroglu(at)adyen(dot)com> |
| Cc: | Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, "smithpb2250(at)gmail(dot)com" <smithpb2250(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, shveta malik <shvetamalik(at)gmail(dot)com> |
| Subject: | Re: Per-table resync for logical replication subscriptions |
| Date: | 2026-11-23 09:25:55 |
| Message-ID: | CAJpy0uADuRGESNK1UjZ5dcEnQyQgJ1v=hDqAQfDdqLBmz3X=tw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sat, Nov 21, 2026 at 11:41 PM Cagri Biroglu <cagri(dot)biroglu(at)adyen(dot)com> wrote:
>
> Hi Shveta,
>
> Thanks, and thanks Peter for pointing you here. Having followed [1],
> I agree it is a use case: with your reproducer on master today the
> table is copied whole, and once the publication is back, REFRESH
> TABLE re-copies just that table with its column list and row filter.
> It would also be how to copy a skipped table, if [1] later moves to a
> WARNING as Peter suggested.
Agreed.
> For the case you describe, I would keep REFRESH TABLE as it is and
> rely on [1]:
>
> - With [1], the re-seeded table ends where [1] leaves any table whose
> initial sync finds it unpublished: it stays in 'd', nothing is
> copied, and "with the ERROR the next retry simply syncs it" once it
> is published again, as you said in [1]. If it stays unpublished,
> the way out, with disable_on_error too, is the one your v4-0002
> documents. I tested both on v15 with your v4.
The end state is the same, but the difference lies in what happens to
the data beforehand. With [1] alone, nothing is lost: the sync fails
and the local rows stay. REFRESH TABLE, however, truncates them first
and then hits the same error, so it turns a harmless "not published"
state into data loss.
The same happens independently of [1] when the table is dropped on the
publisher: REFRESH TABLE truncates it, and the sync then keeps failing
with "table ... not found on publisher". The error itself is right,
but by the time it is raised, the subscriber's data is already lost,
before the user can do anything about it.
>
> - Removing it has the problems you gave in [1] against the worker
> doing it: a table published again stays out until someone runs
> REFRESH PUBLICATION, and a per-table removal is only a partial
> refresh, e.g. after a publish_via_partition_root change it would
> drop the partitions without adding the root.
Agreed, a per-table removal is only a partial refresh. I am fine with
not doing it in REFRESH TABLE.
>
> - A check with the publisher first cannot replace [1], since the
> table can be unpublished right after it, and every REFRESH TABLE
> would have to connect; for ready tables under origin = any it does
> not today.
Agreed, it can't replace [1], and it is not meant to. It only avoids
discarding data on a request that is already invalid when it is made;
[1] remains the safety net for later changes.
The connection is needed anyway; the command exists to copy the table
again from the pub. If the publisher can't be reached, the table can't
be refilled either, so IMO, it is better to fail before truncating.
> Done with fetch_relation_list(), it also has the
> publisher open every published table, the cost fd7a25af11e took out
> of tablesync: about 160 ms for a FOR ALL TABLES publication of 50k
> tables here, and it waits behind an ACCESS EXCLUSIVE lock on any of
> them.
The cost need not be that of fetch_relation_list(). The check can use
the same per-table lookups as tablesync; look up the table by name,
then call pg_get_publication_tables() with the publication names and
the table's OID (the form added by fd7a25af11e).
The check could occur just before the truncate. It can't rule out a
table being unpublished right after it or before the copy at ENABLE,
but that is a concurrent change on the publisher, which [1] already
handles with an error. The aim is narrower: REFRESH TABLE should not
discard the local data when the table is already not published at the
time it is run, which is the case a user is far more likely to hit.
Thoughts?
>
> REFRESH TABLE is meant for a table that is still published and
> replicating but has drifted, and when to reconcile membership stays
> with the user, as with REFRESH SEQUENCES. So in the next version I
> would add the note REFRESH SEQUENCES has, to run REFRESH PUBLICATION
> first if the publication's set of tables has changed; a table it
> removes is then refused by REFRESH TABLE without being truncated.
The note helps a user who knows the set of tables has changed, not one
who doesn't, e.g. when someone else manages the publisher. Such a
user, seeing the sync fail, may well run REFRESH TABLE to fix it and
lose the rows. The patch already refuses a table fed by another
subscription "rather than silently losing data"; IMO the same
reasoning applies here.
~~
Overall, my only concern is the TRUNCATE part: the command should not
end up discarding the local data for an invalid request. Kindly let me
know if this has already been discussed earlier in the thread, as I
haven't had a chance to read it completely.
thanks
Shveta
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dean Rasheed | 2026-11-23 09:29:39 | Re: MERGE fails to reject source references in NOT MATCHED BY SOURCE actions |
| Previous Message | Dean Rasheed | 2026-11-23 09:25:00 | Re: MERGE fails to reject source references in NOT MATCHED BY SOURCE actions |