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