postgres_fdw: IMPORT FOREIGN SCHEMA ... LIMIT TO (partition)

From: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: postgres_fdw: IMPORT FOREIGN SCHEMA ... LIMIT TO (partition)
Date: 2021-01-21 14:56:07
Message-ID: CAEze2Whwg4i=mzApMe+PXxCEfgoZmHGqdqQFW7J4bmj_5p6t1A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Recently I was trying to copy some of the data of one database to
another through postgres_fdw, and found that it wouldn't import that
partition through IMPORT FOREIGN SCHEMA, even when I explicitly
specified the name of the table that contained the data in the LIMIT
TO clause.

I realised the reason is that currently, postgres_fdw explicitly
disallows importing foreign partitions. This is a reasonable default
when importing a whole schema, but if I wanted to explicitly import
one of a partitioned tables' partitions, that would now require me to
manually copy the foreign table's definitions through the use of
CREATE FOREIGN TABLE, which is a hassle and prone to mistakes.

As such, I propose the attached patch, in which the 'no
partitions'-restriction of postgres_fdw is lifted for the LIMIT TO
clause. This has several benefits, including not holding locks on the
foreign root partition during queries, and less suprising behaviour
for LIMIT TO ("table that happens to be a partition").

Regards,

Matthias van de Meent

Attachment Content-Type Size
v1-0001-Update-postgres_fdw-to-import-partitions-when-nam.patch text/x-patch 6.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Denis Laxalde 2021-01-21 15:23:58 [PATCH] Disable bgworkers during servers start in pg_upgrade
Previous Message Amul Sul 2021-01-21 14:46:46 Re: [Patch] ALTER SYSTEM READ ONLY