Re: Restrict publishing of partitioned table with a foreign table as partition

From: Shlok Kyal <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
To: Sergey Tatarintsev <s(dot)tatarintsev(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Restrict publishing of partitioned table with a foreign table as partition
Date: 2025-01-30 12:02:30
Message-ID: CANhcyEWmD18iRFE_aatDoT3tuUEHG6-__BtUaHktiTR4Rey=vQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 29 Jan 2025 at 19:21, Sergey Tatarintsev
<s(dot)tatarintsev(at)postgrespro(dot)ru> wrote:
>
>
> 29.01.2025 12:16, Shlok Kyal пишет:
> > Hi,
> >
> > As part of a discussion in [1], I am starting this thread to address
> > the issue reported for foreign tables.
> >
> > Logical replication of foreign tables is not supported, and we throw
> > an error in this case. But when we create a publication on a
> > partitioned table that has a foreign table as a partition, the initial
> > sync of such a table is successful. We should also throw an error in
> > such cases.
> > With this patch, we will throw an error when we try to create a
> > publication on (or add to an existing publication) a partitioned table
> > with a foreign table as its partition or attach such a table to
> > existing published tables.
> >
> > [1] : https://www.postgresql.org/message-id/CAA4eK1Lhh4SgiYQLNiWSNKGdVSzbd53%3Dsr2tQCKooEphDkUtgw%40mail.gmail.com
> >
> > Thanks and Regards,
> > Shlok Kyal
> Hi!
>
> Thanks for patch.
>
> I reviewed it and made some changes.
>
> 1. we should check foreign tables (not partitioned)
> 2. added checking for foreign table creation
> 3. some little corrections
>
> See attach
>

Hi Sergey,

I have added most of the changes in v2-0002 with small changes except
one change.

@@ -1428,6 +1427,12 @@ check_foreign_tables_in_schema(Oid schemaid)
errdetail("foreign table \"%s\" is a partition of
partitioned table \"%s\"",
get_rel_name(foreign_tbl_relid), parent_name)));
}
+ else if (relForm->relkind == RELKIND_FOREIGN_TABLE)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("cannot add relation \"%s\" to publication",
+ get_rel_name(relForm->oid)),
+ errdetail_relkind_not_supported(RELKIND_FOREIGN_TABLE)));
}

We should only throw error when foreign table is part of a partition
table in case of 'FOR TABLES IN SCHEMA' . We should not throw an error
otherwise because in case of 'FOR TABLES IN SCHEMA' foreign tables are
not published by default.

I have added the changes in v3-0001.

Thanks and Regards,
Shlok Kyal

Attachment Content-Type Size
v3-0001-Restrict-publishing-of-partitioned-table-with-a-f.patch application/octet-stream 16.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nazir Bilal Yavuz 2025-01-30 13:18:54 Re: Windows CFBot is broken because ecpg dec_test.c error
Previous Message Oliver Ford 2025-01-30 12:02:19 Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options