| From: | shveta malik <shveta(dot)malik(at)gmail(dot)com> |
|---|---|
| To: | Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com> |
| Cc: | Peter Smith <smithpb2250(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, vignesh C <vignesh21(at)gmail(dot)com>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, shveta malik <shvetamalik(at)gmail(dot)com> |
| Subject: | Re: Initial table sync copies the whole table when it is no longer published |
| Date: | 2026-11-24 05:51:01 |
| Message-ID: | CAJpy0uAiBeDqWnWXgi+5oj+NjTX_YtfV9nuCif3K=qkKn-W7cw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, Nov 23, 2026 at 5:53 PM Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com> wrote:
>
> >
> > I agree with the suggestion. I have incorporated the suggested shorter
> > text with a few tweaks. Please have a look.
> >
>
> Hi Shveta,
> I continue testing for similar cases to unlogged tables (reported in
> [1]). I found similar issues can happen with View, Materialized View,
> Foreign table.
> Tablesync can copy data from view/ materialized view/ foreign table on
> publisher to the subscriber table on HEAD,
>
> Here are the steps:
> Pub:
> create table tab1(a int, b int, c int);
> create publication pub1 for table tab1;
>
> Sub:
> create table tab1(a int, b int, c int);
> create subscription sub1 connection '...' publication pub1
> WITH(enabled='false');
>
> Pub:
> drop table tab1;
> --The table sync can copy View, Materialized View, Foreign table.
> -- For View:
> create view tab1 as select 1 as a, 2 as b, 3 as c;
>
> -- For Materialized view
> -- create materialized view tab1 as select 1 as a, 2 as b, 3 as c;
>
> -- For foreign table
> -- create extension postgres_fdw;
> -- create table backing_tab1 as select 1 as a, 2 as b, 3 as c;
> -- create server loopback_server foreign data wrapper postgres_fdw
> options (host 'localhost', port '5432', dbname 'postgres');
> -- create user mapping for current_user server loopback_server;
> -- create foreign table tab1(a int, b int, c int) server
> loopback_server options (table_name 'backing_tab1');
>
> Sub:
> alter subscription sub1 ENABLE;
>
> -- For all the three case: wait a few seconds for the sync
> select * from tab1 order by c;
> select srrelid::regclass, srsubstate FROM pg_subscription_rel;
>
> Result:
> a | b | c
> ---+---+---
> 1 | 2 | 3
>
> srrelid | srsubstate
> ---------+------------
> tab1 | r
>
> I applied v5-0001 and tested for the above scenarios. I confirmed that
> the patch handles unlogged tables, views, materialized views, and
> foreign tables by reporting appropriate errors.
> I have one question about the initial relation lookup in
> fetch_remote_table_info():
> ```
> appendStringInfo(&cmd, "SELECT c.oid, c.relreplident, c.relkind"
> " FROM pg_catalog.pg_class c"
> " INNER JOIN pg_catalog.pg_namespace n"
> " ON (c.relnamespace = n.oid)"
> " WHERE n.nspname = %s"
> " AND c.relname = %s",
> quote_literal_cstr(nspname),
> quote_literal_cstr(relname));
> ```
> Would it make sense to add the following conditions?
> " AND c.relkind IN ('r', 'p')"
> " AND c.relpersistence = 'p'",
>
> This would restrict the lookup to permanent ordinary and partitioned
> tables, allowing us to reject unsupported relations at this stage
> rather than during the subsequent publication-membership checks.
> Thoughts?
Thanks for testing these cases. I think the relkind/relpersistence
filter is not needed. IMO, which relations can be published is
entirely the publisher's decision; the subscriber should only ask
whether the table is published, not re-implement those rules in its
lookup, which would then have to be kept in sync if the rules change.
Additionally, the scenario you reported is a special one, where the
table is replaced on the publisher by a relation of another type with
the same name before the sync started, but it is still rejected on the
subscriber with the current fix in place. So I think we are good with
the current fix alone.
thanks
Shveta
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rajesh Kumar Thandapani | 2026-11-24 06:05:47 | Re: Bug in logical decoding with DDL and subtransactions |
| Previous Message | Michael Paquier | 2026-11-24 05:22:33 | Re: REINDEX CONCURRENTLY reports lockers_done > lockers_total |