Re: Initial table sync copies the whole table when it is no longer published

From: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(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-23 12:22:58
Message-ID: CANhcyEU9tbr-jiPX-U7CnUu3=NnMEO1PmcDkWFedAw4RjtqiKw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> 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?

[1]: https://www.postgresql.org/message-id/CANhcyEWcx%3DndzUW4GXxu-dFsWXnO-%2BxWhJLLnW5B4R_wPx8pcQ%40mail.gmail.com

Thanks,
Shlok Kyal

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dean Rasheed 2026-11-23 12:32:08 Re: Fix stale source values in MERGE RETURNING after a cross-partition update
Previous Message Markos Fountoulakis 2026-11-23 12:20:12 Re: enhancing pg_basebackup speeds up to ~23Gbps (small fixes + io_uring/Direct I/O)