2013-02-21 11:26:23 +01:00
|
|
|
<!-- doc/src/sgml/postgres-fdw.sgml -->
|
|
|
|
|
|
|
|
<sect1 id="postgres-fdw" xreflabel="postgres_fdw">
|
|
|
|
<title>postgres_fdw</title>
|
|
|
|
|
|
|
|
<indexterm zone="postgres-fdw">
|
|
|
|
<primary>postgres_fdw</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The <filename>postgres_fdw</filename> module provides the foreign-data wrapper
|
2013-02-21 11:26:23 +01:00
|
|
|
<literal>postgres_fdw</literal>, which can be used to access data
|
|
|
|
stored in external <productname>PostgreSQL</productname> servers.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The functionality provided by this module overlaps substantially
|
2017-11-23 15:39:47 +01:00
|
|
|
with the functionality of the older <xref linkend="dblink"/> module.
|
2017-10-09 03:44:17 +02:00
|
|
|
But <filename>postgres_fdw</filename> provides more transparent and
|
2013-02-21 11:26:23 +01:00
|
|
|
standards-compliant syntax for accessing remote tables, and can give
|
|
|
|
better performance in many cases.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
To prepare for remote access using <filename>postgres_fdw</filename>:
|
2013-02-21 11:26:23 +01:00
|
|
|
<orderedlist spacing="compact">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Install the <filename>postgres_fdw</filename> extension using <xref
|
2017-11-23 15:39:47 +01:00
|
|
|
linkend="sql-createextension"/>.
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
Create a foreign server object, using <xref linkend="sql-createserver"/>,
|
2013-02-21 11:26:23 +01:00
|
|
|
to represent each remote database you want to connect to.
|
|
|
|
Specify connection information, except <literal>user</literal> and
|
|
|
|
<literal>password</literal>, as options of the server object.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
Create a user mapping, using <xref linkend="sql-createusermapping"/>, for
|
2013-02-21 11:26:23 +01:00
|
|
|
each database user you want to allow to access each foreign server.
|
|
|
|
Specify the remote user name and password to use as
|
|
|
|
<literal>user</literal> and <literal>password</literal> options of the
|
|
|
|
user mapping.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
Create a foreign table, using <xref linkend="sql-createforeigntable"/>
|
|
|
|
or <xref linkend="sql-importforeignschema"/>,
|
2013-02-21 11:26:23 +01:00
|
|
|
for each remote table you want to access. The columns of the foreign
|
|
|
|
table must match the referenced remote table. You can, however, use
|
|
|
|
table and/or column names different from the remote table's, if you
|
|
|
|
specify the correct remote names as options of the foreign table object.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</orderedlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Now you need only <command>SELECT</command> from a foreign table to access
|
2013-03-10 19:14:53 +01:00
|
|
|
the data stored in its underlying remote table. You can also modify
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
the remote table using <command>INSERT</command>, <command>UPDATE</command>,
|
2022-02-16 07:15:00 +01:00
|
|
|
<command>DELETE</command>, <command>COPY</command>, or
|
|
|
|
<command>TRUNCATE</command>.
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
(Of course, the remote user you have specified in your user mapping must
|
|
|
|
have privileges to do these things.)
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
|
2021-04-27 07:41:27 +02:00
|
|
|
<para>
|
|
|
|
Note that the <literal>ONLY</literal> option specified in
|
|
|
|
<command>SELECT</command>, <command>UPDATE</command>,
|
|
|
|
<command>DELETE</command> or <command>TRUNCATE</command>
|
|
|
|
has no effect when accessing or modifying the remote table.
|
|
|
|
</para>
|
|
|
|
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Note that <filename>postgres_fdw</filename> currently lacks support for
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
<command>INSERT</command> statements with an <literal>ON CONFLICT DO
|
2017-10-09 03:44:17 +02:00
|
|
|
UPDATE</literal> clause. However, the <literal>ON CONFLICT DO NOTHING</literal>
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
clause is supported, provided a unique index inference specification
|
|
|
|
is omitted.
|
2019-04-24 11:31:50 +02:00
|
|
|
Note also that <filename>postgres_fdw</filename> supports row movement
|
|
|
|
invoked by <command>UPDATE</command> statements executed on partitioned
|
|
|
|
tables, but it currently does not handle the case where a remote partition
|
|
|
|
chosen to insert a moved row into is also an <command>UPDATE</command>
|
Rework planning and execution of UPDATE and DELETE.
This patch makes two closely related sets of changes:
1. For UPDATE, the subplan of the ModifyTable node now only delivers
the new values of the changed columns (i.e., the expressions computed
in the query's SET clause) plus row identity information such as CTID.
ModifyTable must re-fetch the original tuple to merge in the old
values of any unchanged columns. The core advantage of this is that
the changed columns are uniform across all tables of an inherited or
partitioned target relation, whereas the other columns might not be.
A secondary advantage, when the UPDATE involves joins, is that less
data needs to pass through the plan tree. The disadvantage of course
is an extra fetch of each tuple to be updated. However, that seems to
be very nearly free in context; even worst-case tests don't show it to
add more than a couple percent to the total query cost. At some point
it might be interesting to combine the re-fetch with the tuple access
that ModifyTable must do anyway to mark the old tuple dead; but that
would require a good deal of refactoring and it seems it wouldn't buy
all that much, so this patch doesn't attempt it.
2. For inherited UPDATE/DELETE, instead of generating a separate
subplan for each target relation, we now generate a single subplan
that is just exactly like a SELECT's plan, then stick ModifyTable
on top of that. To let ModifyTable know which target relation a
given incoming row refers to, a tableoid junk column is added to
the row identity information. This gets rid of the horrid hack
that was inheritance_planner(), eliminating O(N^2) planning cost
and memory consumption in cases where there were many unprunable
target relations.
Point 2 of course requires point 1, so that there is a uniform
definition of the non-junk columns to be returned by the subplan.
We can't insist on uniform definition of the row identity junk
columns however, if we want to keep the ability to have both
plain and foreign tables in a partitioning hierarchy. Since
it wouldn't scale very far to have every child table have its
own row identity column, this patch includes provisions to merge
similar row identity columns into one column of the subplan result.
In particular, we can merge the whole-row Vars typically used as
row identity by FDWs into one column by pretending they are type
RECORD. (It's still okay for the actual composite Datums to be
labeled with the table's rowtype OID, though.)
There is more that can be done to file down residual inefficiencies
in this patch, but it seems to be committable now.
FDW authors should note several API changes:
* The argument list for AddForeignUpdateTargets() has changed, and so
has the method it must use for adding junk columns to the query. Call
add_row_identity_var() instead of manipulating the parse tree directly.
You might want to reconsider exactly what you're adding, too.
* PlanDirectModify() must now work a little harder to find the
ForeignScan plan node; if the foreign table is part of a partitioning
hierarchy then the ForeignScan might not be the direct child of
ModifyTable. See postgres_fdw for sample code.
* To check whether a relation is a target relation, it's no
longer sufficient to compare its relid to root->parse->resultRelation.
Instead, check it against all_result_relids or leaf_result_relids,
as appropriate.
Amit Langote and Tom Lane
Discussion: https://postgr.es/m/CA+HiwqHpHdqdDn48yCEhynnniahH78rwcrv1rEX65-fsZGBOLQ@mail.gmail.com
2021-03-31 17:52:34 +02:00
|
|
|
target partition that will be updated elsewhere in the same command.
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
</para>
|
|
|
|
|
2013-02-21 11:26:23 +01:00
|
|
|
<para>
|
|
|
|
It is generally recommended that the columns of a foreign table be declared
|
|
|
|
with exactly the same data types, and collations if applicable, as the
|
2017-10-09 03:44:17 +02:00
|
|
|
referenced columns of the remote table. Although <filename>postgres_fdw</filename>
|
2013-02-21 11:26:23 +01:00
|
|
|
is currently rather forgiving about performing data type conversions at
|
|
|
|
need, surprising semantic anomalies may arise when types or collations do
|
2021-09-25 16:53:54 +02:00
|
|
|
not match, due to the remote server interpreting query conditions
|
|
|
|
differently from the local server.
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that a foreign table can be declared with fewer columns, or with a
|
|
|
|
different column order, than its underlying remote table has. Matching
|
|
|
|
of columns to the remote table is by name, not position.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>FDW Options of postgres_fdw</title>
|
|
|
|
|
|
|
|
<sect3>
|
|
|
|
<title>Connection Options</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
A foreign server using the <filename>postgres_fdw</filename> foreign data wrapper
|
|
|
|
can have the same options that <application>libpq</application> accepts in
|
2017-11-23 15:39:47 +01:00
|
|
|
connection strings, as described in <xref linkend="libpq-paramkeywords"/>,
|
2020-01-09 09:09:54 +01:00
|
|
|
except that these options are not allowed or have special handling:
|
2013-02-21 11:26:23 +01:00
|
|
|
|
|
|
|
<itemizedlist spacing="compact">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2019-11-30 21:27:13 +01:00
|
|
|
<literal>user</literal>, <literal>password</literal> and <literal>sslpassword</literal> (specify these
|
2020-01-09 09:09:54 +01:00
|
|
|
in a user mapping, instead, or use a service file)
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>client_encoding</literal> (this is automatically set from the local
|
2013-02-21 11:26:23 +01:00
|
|
|
server encoding)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2021-12-24 08:55:11 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
<literal>application_name</literal> - this may appear in
|
|
|
|
<emphasis>either or both</emphasis> a connection and
|
|
|
|
<xref linkend="guc-pgfdw-application-name"/>.
|
|
|
|
If both are present, <varname>postgres_fdw.application_name</varname>
|
|
|
|
overrides the connection setting.
|
|
|
|
Unlike <application>libpq</application>,
|
|
|
|
<filename>postgres_fdw</filename> allows
|
|
|
|
<varname>application_name</varname> to include
|
|
|
|
<quote>escape sequences</quote>.
|
|
|
|
See <xref linkend="guc-pgfdw-application-name"/> for details.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>fallback_application_name</literal> (always set to
|
|
|
|
<literal>postgres_fdw</literal>)
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
2020-01-09 09:09:54 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-01-13 08:38:09 +01:00
|
|
|
<literal>sslkey</literal> and <literal>sslcert</literal> - these may
|
2020-01-09 09:09:54 +01:00
|
|
|
appear in <emphasis>either or both</emphasis> a connection and a user
|
|
|
|
mapping. If both are present, the user mapping setting overrides the
|
|
|
|
connection setting.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
2013-02-21 11:26:23 +01:00
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
|
2020-01-13 08:38:09 +01:00
|
|
|
<para>
|
|
|
|
Only superusers may create or modify user mappings with the
|
|
|
|
<literal>sslcert</literal> or <literal>sslkey</literal> settings.
|
|
|
|
</para>
|
2013-02-21 11:26:23 +01:00
|
|
|
<para>
|
|
|
|
Only superusers may connect to foreign servers without password
|
|
|
|
authentication, so always specify the <literal>password</literal> option
|
|
|
|
for user mappings belonging to non-superusers.
|
|
|
|
</para>
|
2019-12-20 06:53:34 +01:00
|
|
|
<para>
|
|
|
|
A superuser may override this check on a per-user-mapping basis by setting
|
2020-09-01 00:33:37 +02:00
|
|
|
the user mapping option <literal>password_required 'false'</literal>, e.g.,
|
2020-05-14 13:14:58 +02:00
|
|
|
<programlisting>
|
|
|
|
ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw
|
|
|
|
OPTIONS (ADD password_required 'false');
|
|
|
|
</programlisting>
|
2019-12-20 06:53:34 +01:00
|
|
|
To prevent unprivileged users from exploiting the authentication rights
|
|
|
|
of the unix user the postgres server is running as to escalate to superuser
|
|
|
|
rights, only the superuser may set this option on a user mapping.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Care is required to ensure that this does not allow the mapped
|
|
|
|
user the ability to connect as superuser to the mapped database per
|
|
|
|
CVE-2007-3278 and CVE-2007-6601. Don't set
|
|
|
|
<literal>password_required=false</literal>
|
|
|
|
on the <literal>public</literal> role. Keep in mind that the mapped
|
|
|
|
user can potentially use any client certificates,
|
|
|
|
<filename>.pgpass</filename>,
|
|
|
|
<filename>.pg_service.conf</filename> etc in the unix home directory of the
|
|
|
|
system user the postgres server runs as. They can also use any trust
|
|
|
|
relationship granted by authentication modes like <literal>peer</literal>
|
|
|
|
or <literal>ident</literal> authentication.
|
|
|
|
</para>
|
2013-02-21 11:26:23 +01:00
|
|
|
</sect3>
|
|
|
|
|
|
|
|
<sect3>
|
|
|
|
<title>Object Name Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
These options can be used to control the names used in SQL statements
|
|
|
|
sent to the remote <productname>PostgreSQL</productname> server. These
|
|
|
|
options are needed when a foreign table is created with names different
|
|
|
|
from the underlying remote table's names.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>schema_name</literal> (<type>string</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option, which can be specified for a foreign table, gives the
|
|
|
|
schema name to use for the foreign table on the remote server. If this
|
|
|
|
option is omitted, the name of the foreign table's schema is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>table_name</literal> (<type>string</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option, which can be specified for a foreign table, gives the
|
|
|
|
table name to use for the foreign table on the remote server. If this
|
|
|
|
option is omitted, the foreign table's name is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>column_name</literal> (<type>string</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option, which can be specified for a column of a foreign table,
|
|
|
|
gives the column name to use for the column on the remote server.
|
|
|
|
If this option is omitted, the column's name is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
</sect3>
|
|
|
|
|
|
|
|
<sect3>
|
|
|
|
<title>Cost Estimation Options</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> retrieves remote data by executing queries
|
2013-02-21 11:26:23 +01:00
|
|
|
against remote servers, so ideally the estimated cost of scanning a
|
|
|
|
foreign table should be whatever it costs to be done on the remote
|
|
|
|
server, plus some overhead for communication. The most reliable way to
|
|
|
|
get such an estimate is to ask the remote server and then add something
|
|
|
|
for overhead — but for simple queries, it may not be worth the cost
|
|
|
|
of an additional remote query to get a cost estimate.
|
2017-10-09 03:44:17 +02:00
|
|
|
So <filename>postgres_fdw</filename> provides the following options to control
|
2013-02-21 11:26:23 +01:00
|
|
|
how cost estimation is done:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>use_remote_estimate</literal> (<type>boolean</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option, which can be specified for a foreign table or a foreign
|
2017-10-09 03:44:17 +02:00
|
|
|
server, controls whether <filename>postgres_fdw</filename> issues remote
|
2013-02-21 11:26:23 +01:00
|
|
|
<command>EXPLAIN</command> commands to obtain cost estimates.
|
|
|
|
A setting for a foreign table overrides any setting for its server,
|
|
|
|
but only for that table.
|
|
|
|
The default is <literal>false</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>fdw_startup_cost</literal> (<type>floating point</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
postgres_fdw: Tighten up allowed values for batch_size, fetch_size options.
Previously the values such as '100$%$#$#', '9,223,372,' were accepted and
treated as valid integers for postgres_fdw options batch_size and fetch_size.
Whereas this is not the case with fdw_startup_cost and fdw_tuple_cost options
for which an error is thrown. This was because endptr was not used
while converting strings to integers using strtol.
This commit changes the logic so that it uses parse_int function
instead of strtol as it serves the purpose by returning false in case
if it is unable to convert the string to integer. Note that
this function also rounds off the values such as '100.456' to 100 and
'100.567' or '100.678' to 101.
While on this, use parse_real for fdw_startup_cost and fdw_tuple_cost options.
Since parse_int and parse_real are being used for reloptions and GUCs,
it is more appropriate to use in postgres_fdw rather than using strtol
and strtod directly.
Back-patch to v14.
Author: Bharath Rupireddy
Reviewed-by: Ashutosh Bapat, Tom Lane, Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACVMO6wY5Pc4oe1OCgUOAtdjHuFsBDw8R5uoYR86eWFQDA@mail.gmail.com
2021-07-07 04:13:40 +02:00
|
|
|
This option, which can be specified for a foreign server, is a floating
|
|
|
|
point value that is added to the estimated startup cost of any
|
|
|
|
foreign-table scan on that server. This represents the additional
|
|
|
|
overhead of establishing a connection, parsing and planning the query on
|
|
|
|
the remote side, etc.
|
2013-02-21 11:26:23 +01:00
|
|
|
The default value is <literal>100</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>fdw_tuple_cost</literal> (<type>floating point</type>)</term>
|
2013-02-21 11:26:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
postgres_fdw: Tighten up allowed values for batch_size, fetch_size options.
Previously the values such as '100$%$#$#', '9,223,372,' were accepted and
treated as valid integers for postgres_fdw options batch_size and fetch_size.
Whereas this is not the case with fdw_startup_cost and fdw_tuple_cost options
for which an error is thrown. This was because endptr was not used
while converting strings to integers using strtol.
This commit changes the logic so that it uses parse_int function
instead of strtol as it serves the purpose by returning false in case
if it is unable to convert the string to integer. Note that
this function also rounds off the values such as '100.456' to 100 and
'100.567' or '100.678' to 101.
While on this, use parse_real for fdw_startup_cost and fdw_tuple_cost options.
Since parse_int and parse_real are being used for reloptions and GUCs,
it is more appropriate to use in postgres_fdw rather than using strtol
and strtod directly.
Back-patch to v14.
Author: Bharath Rupireddy
Reviewed-by: Ashutosh Bapat, Tom Lane, Kyotaro Horiguchi, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACVMO6wY5Pc4oe1OCgUOAtdjHuFsBDw8R5uoYR86eWFQDA@mail.gmail.com
2021-07-07 04:13:40 +02:00
|
|
|
This option, which can be specified for a foreign server, is a floating
|
|
|
|
point value that is used as extra cost per-tuple for foreign-table
|
2013-02-21 11:26:23 +01:00
|
|
|
scans on that server. This represents the additional overhead of
|
|
|
|
data transfer between servers. You might increase or decrease this
|
|
|
|
number to reflect higher or lower network delay to the remote server.
|
|
|
|
The default value is <literal>0.01</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When <literal>use_remote_estimate</literal> is true,
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> obtains row count and cost estimates from the
|
2013-02-21 11:26:23 +01:00
|
|
|
remote server and then adds <literal>fdw_startup_cost</literal> and
|
|
|
|
<literal>fdw_tuple_cost</literal> to the cost estimates. When
|
|
|
|
<literal>use_remote_estimate</literal> is false,
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> performs local row count and cost estimation
|
2013-02-21 11:26:23 +01:00
|
|
|
and then adds <literal>fdw_startup_cost</literal> and
|
|
|
|
<literal>fdw_tuple_cost</literal> to the cost estimates. This local
|
|
|
|
estimation is unlikely to be very accurate unless local copies of the
|
|
|
|
remote table's statistics are available. Running
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="sql-analyze"/> on the foreign table is the way to update
|
2013-02-21 11:26:23 +01:00
|
|
|
the local statistics; this will perform a scan of the remote table and
|
|
|
|
then calculate and store statistics just as though the table were local.
|
|
|
|
Keeping local statistics can be a useful way to reduce per-query planning
|
|
|
|
overhead for a remote table — but if the remote table is
|
|
|
|
frequently updated, the local statistics will soon be obsolete.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</sect3>
|
2013-06-12 23:52:54 +02:00
|
|
|
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
<sect3>
|
|
|
|
<title>Remote Execution Options</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
By default, only <literal>WHERE</literal> clauses using built-in operators and
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
functions will be considered for execution on the remote server. Clauses
|
|
|
|
involving non-built-in functions are checked locally after rows are
|
|
|
|
fetched. If such functions are available on the remote server and can be
|
|
|
|
relied on to produce the same results as they do locally, performance can
|
2017-10-09 03:44:17 +02:00
|
|
|
be improved by sending such <literal>WHERE</literal> clauses for remote
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
execution. This behavior can be controlled using the following option:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>extensions</literal> (<type>string</type>)</term>
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option is a comma-separated list of names
|
2017-10-09 03:44:17 +02:00
|
|
|
of <productname>PostgreSQL</productname> extensions that are installed, in
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
compatible versions, on both the local and remote servers. Functions
|
|
|
|
and operators that are immutable and belong to a listed extension will
|
|
|
|
be considered shippable to the remote server.
|
|
|
|
This option can only be specified for foreign servers, not per-table.
|
|
|
|
</para>
|
2016-02-03 15:01:59 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
When using the <literal>extensions</literal> option, <emphasis>it is the
|
2017-10-09 03:44:17 +02:00
|
|
|
user's responsibility</emphasis> that the listed extensions exist and behave
|
2016-02-03 15:01:59 +01:00
|
|
|
identically on both the local and remote servers. Otherwise, remote
|
|
|
|
queries may fail or behave unexpectedly.
|
|
|
|
</para>
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-02-03 15:01:59 +01:00
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>fetch_size</literal> (<type>integer</type>)</term>
|
2016-02-03 15:01:59 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This option specifies the number of rows <filename>postgres_fdw</filename>
|
2016-02-03 15:01:59 +01:00
|
|
|
should get in each fetch operation. It can be specified for a foreign
|
|
|
|
table or a foreign server. The option specified on a table overrides
|
|
|
|
an option specified for the server.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default is <literal>100</literal>.
|
2016-02-03 15:01:59 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
|
2021-01-20 23:05:46 +01:00
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>batch_size</literal> (<type>integer</type>)</term>
|
2021-01-20 23:05:46 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option specifies the number of rows <filename>postgres_fdw</filename>
|
|
|
|
should insert in each insert operation. It can be specified for a
|
|
|
|
foreign table or a foreign server. The option specified on a table
|
|
|
|
overrides an option specified for the server.
|
|
|
|
The default is <literal>1</literal>.
|
|
|
|
</para>
|
2021-06-08 20:22:18 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Note the actual number of rows <filename>postgres_fdw</filename> inserts at
|
|
|
|
once depends on the number of columns and the provided
|
|
|
|
<literal>batch_size</literal> value. The batch is executed as a single
|
|
|
|
query, and the libpq protocol (which <filename>postgres_fdw</filename>
|
|
|
|
uses to connect to a remote server) limits the number of parameters in a
|
|
|
|
single query to 65535. When the number of columns * <literal>batch_size</literal>
|
|
|
|
exceeds the limit, the <literal>batch_size</literal> will be adjusted to
|
|
|
|
avoid an error.
|
|
|
|
</para>
|
2021-01-20 23:05:46 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-02-03 15:01:59 +01:00
|
|
|
</variablelist>
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
|
|
|
|
</sect3>
|
|
|
|
|
Add support for asynchronous execution.
This implements asynchronous execution, which runs multiple parts of a
non-parallel-aware Append concurrently rather than serially to improve
performance when possible. Currently, the only node type that can be
run concurrently is a ForeignScan that is an immediate child of such an
Append. In the case where such ForeignScans access data on different
remote servers, this would run those ForeignScans concurrently, and
overlap the remote operations to be performed simultaneously, so it'll
improve the performance especially when the operations involve
time-consuming ones such as remote join and remote aggregation.
We may extend this to other node types such as joins or aggregates over
ForeignScans in the future.
This also adds the support for postgres_fdw, which is enabled by the
table-level/server-level option "async_capable". The default is false.
Robert Haas, Kyotaro Horiguchi, Thomas Munro, and myself. This commit
is mostly based on the patch proposed by Robert Haas, but also uses
stuff from the patch proposed by Kyotaro Horiguchi and from the patch
proposed by Thomas Munro. Reviewed by Kyotaro Horiguchi, Konstantin
Knizhnik, Andrey Lepikhov, Movead Li, Thomas Munro, Justin Pryzby, and
others.
Discussion: https://postgr.es/m/CA%2BTgmoaXQEt4tZ03FtQhnzeDEMzBck%2BLrni0UWHVVgOTnA6C1w%40mail.gmail.com
Discussion: https://postgr.es/m/CA%2BhUKGLBRyu0rHrDCMC4%3DRn3252gogyp1SjOgG8SEKKZv%3DFwfQ%40mail.gmail.com
Discussion: https://postgr.es/m/20200228.170650.667613673625155850.horikyota.ntt%40gmail.com
2021-03-31 11:45:00 +02:00
|
|
|
<sect3>
|
|
|
|
<title>Asynchronous Execution Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<filename>postgres_fdw</filename> supports asynchronous execution, which
|
|
|
|
runs multiple parts of an <structname>Append</structname> node
|
|
|
|
concurrently rather than serially to improve performance.
|
2021-06-04 13:39:40 +02:00
|
|
|
This execution can be controlled using the following option:
|
Add support for asynchronous execution.
This implements asynchronous execution, which runs multiple parts of a
non-parallel-aware Append concurrently rather than serially to improve
performance when possible. Currently, the only node type that can be
run concurrently is a ForeignScan that is an immediate child of such an
Append. In the case where such ForeignScans access data on different
remote servers, this would run those ForeignScans concurrently, and
overlap the remote operations to be performed simultaneously, so it'll
improve the performance especially when the operations involve
time-consuming ones such as remote join and remote aggregation.
We may extend this to other node types such as joins or aggregates over
ForeignScans in the future.
This also adds the support for postgres_fdw, which is enabled by the
table-level/server-level option "async_capable". The default is false.
Robert Haas, Kyotaro Horiguchi, Thomas Munro, and myself. This commit
is mostly based on the patch proposed by Robert Haas, but also uses
stuff from the patch proposed by Kyotaro Horiguchi and from the patch
proposed by Thomas Munro. Reviewed by Kyotaro Horiguchi, Konstantin
Knizhnik, Andrey Lepikhov, Movead Li, Thomas Munro, Justin Pryzby, and
others.
Discussion: https://postgr.es/m/CA%2BTgmoaXQEt4tZ03FtQhnzeDEMzBck%2BLrni0UWHVVgOTnA6C1w%40mail.gmail.com
Discussion: https://postgr.es/m/CA%2BhUKGLBRyu0rHrDCMC4%3DRn3252gogyp1SjOgG8SEKKZv%3DFwfQ%40mail.gmail.com
Discussion: https://postgr.es/m/20200228.170650.667613673625155850.horikyota.ntt%40gmail.com
2021-03-31 11:45:00 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>async_capable</literal> (<type>boolean</type>)</term>
|
Add support for asynchronous execution.
This implements asynchronous execution, which runs multiple parts of a
non-parallel-aware Append concurrently rather than serially to improve
performance when possible. Currently, the only node type that can be
run concurrently is a ForeignScan that is an immediate child of such an
Append. In the case where such ForeignScans access data on different
remote servers, this would run those ForeignScans concurrently, and
overlap the remote operations to be performed simultaneously, so it'll
improve the performance especially when the operations involve
time-consuming ones such as remote join and remote aggregation.
We may extend this to other node types such as joins or aggregates over
ForeignScans in the future.
This also adds the support for postgres_fdw, which is enabled by the
table-level/server-level option "async_capable". The default is false.
Robert Haas, Kyotaro Horiguchi, Thomas Munro, and myself. This commit
is mostly based on the patch proposed by Robert Haas, but also uses
stuff from the patch proposed by Kyotaro Horiguchi and from the patch
proposed by Thomas Munro. Reviewed by Kyotaro Horiguchi, Konstantin
Knizhnik, Andrey Lepikhov, Movead Li, Thomas Munro, Justin Pryzby, and
others.
Discussion: https://postgr.es/m/CA%2BTgmoaXQEt4tZ03FtQhnzeDEMzBck%2BLrni0UWHVVgOTnA6C1w%40mail.gmail.com
Discussion: https://postgr.es/m/CA%2BhUKGLBRyu0rHrDCMC4%3DRn3252gogyp1SjOgG8SEKKZv%3DFwfQ%40mail.gmail.com
Discussion: https://postgr.es/m/20200228.170650.667613673625155850.horikyota.ntt%40gmail.com
2021-03-31 11:45:00 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option controls whether <filename>postgres_fdw</filename> allows
|
|
|
|
foreign tables to be scanned concurrently for asynchronous execution.
|
|
|
|
It can be specified for a foreign table or a foreign server.
|
|
|
|
A table-level option overrides a server-level option.
|
|
|
|
The default is <literal>false</literal>.
|
|
|
|
</para>
|
2021-05-17 10:30:00 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
In order to ensure that the data being returned from a foreign server
|
|
|
|
is consistent, <filename>postgres_fdw</filename> will only open one
|
|
|
|
connection for a given foreign server and will run all queries against
|
|
|
|
that server sequentially even if there are multiple foreign tables
|
|
|
|
involved, unless those tables are subject to different user mappings.
|
|
|
|
In such a case, it may be more performant to disable this option to
|
|
|
|
eliminate the overhead associated with running queries asynchronously.
|
|
|
|
</para>
|
2021-06-08 06:45:00 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Asynchronous execution is applied even when an
|
|
|
|
<structname>Append</structname> node contains subplan(s) executed
|
|
|
|
synchronously as well as subplan(s) executed asynchronously.
|
|
|
|
In such a case, if the asynchronous subplans are ones processed using
|
|
|
|
<filename>postgres_fdw</filename>, tuples from the asynchronous
|
|
|
|
subplans are not returned until after at least one synchronous subplan
|
|
|
|
returns all tuples, as that subplan is executed while the asynchronous
|
|
|
|
subplans are waiting for the results of asynchronous queries sent to
|
|
|
|
foreign servers.
|
|
|
|
This behavior might change in a future release.
|
|
|
|
</para>
|
Add support for asynchronous execution.
This implements asynchronous execution, which runs multiple parts of a
non-parallel-aware Append concurrently rather than serially to improve
performance when possible. Currently, the only node type that can be
run concurrently is a ForeignScan that is an immediate child of such an
Append. In the case where such ForeignScans access data on different
remote servers, this would run those ForeignScans concurrently, and
overlap the remote operations to be performed simultaneously, so it'll
improve the performance especially when the operations involve
time-consuming ones such as remote join and remote aggregation.
We may extend this to other node types such as joins or aggregates over
ForeignScans in the future.
This also adds the support for postgres_fdw, which is enabled by the
table-level/server-level option "async_capable". The default is false.
Robert Haas, Kyotaro Horiguchi, Thomas Munro, and myself. This commit
is mostly based on the patch proposed by Robert Haas, but also uses
stuff from the patch proposed by Kyotaro Horiguchi and from the patch
proposed by Thomas Munro. Reviewed by Kyotaro Horiguchi, Konstantin
Knizhnik, Andrey Lepikhov, Movead Li, Thomas Munro, Justin Pryzby, and
others.
Discussion: https://postgr.es/m/CA%2BTgmoaXQEt4tZ03FtQhnzeDEMzBck%2BLrni0UWHVVgOTnA6C1w%40mail.gmail.com
Discussion: https://postgr.es/m/CA%2BhUKGLBRyu0rHrDCMC4%3DRn3252gogyp1SjOgG8SEKKZv%3DFwfQ%40mail.gmail.com
Discussion: https://postgr.es/m/20200228.170650.667613673625155850.horikyota.ntt%40gmail.com
2021-03-31 11:45:00 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</sect3>
|
|
|
|
|
2022-02-24 06:30:00 +01:00
|
|
|
<sect3>
|
|
|
|
<title>Transaction Management Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
When multiple remote (sub)transactions are involved in a local
|
|
|
|
(sub)transaction, by default <filename>postgres_fdw</filename> commits
|
|
|
|
those remote (sub)transactions one by one when the local (sub)transaction
|
|
|
|
commits.
|
|
|
|
Performance can be improved with the following option:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>parallel_commit</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option controls whether <filename>postgres_fdw</filename> commits
|
|
|
|
remote (sub)transactions opened on a foreign server in a local
|
|
|
|
(sub)transaction in parallel when the local (sub)transaction commits.
|
|
|
|
This option can only be specified for foreign servers, not per-table.
|
|
|
|
The default is <literal>false</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
If multiple foreign servers with this option enabled are involved in
|
|
|
|
a local (sub)transaction, multiple remote (sub)transactions opened on
|
|
|
|
those foreign servers in the local (sub)transaction are committed in
|
|
|
|
parallel across those foreign servers when the local (sub)transaction
|
|
|
|
commits.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For a foreign server with this option enabled, if many remote
|
|
|
|
(sub)transactions are opened on the foreign server in a local
|
2022-04-11 10:48:48 +02:00
|
|
|
(sub)transaction, this option might increase the remote server's load
|
2022-02-24 06:30:00 +01:00
|
|
|
when the local (sub)transaction commits, so be careful when using this
|
|
|
|
option.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
</sect3>
|
|
|
|
|
2013-06-12 23:52:54 +02:00
|
|
|
<sect3>
|
|
|
|
<title>Updatability Options</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
By default all foreign tables using <filename>postgres_fdw</filename> are assumed
|
2013-06-12 23:52:54 +02:00
|
|
|
to be updatable. This may be overridden using the following option:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>updatable</literal> (<type>boolean</type>)</term>
|
2013-06-12 23:52:54 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This option controls whether <filename>postgres_fdw</filename> allows foreign
|
|
|
|
tables to be modified using <command>INSERT</command>, <command>UPDATE</command> and
|
|
|
|
<command>DELETE</command> commands. It can be specified for a foreign table
|
2013-06-12 23:52:54 +02:00
|
|
|
or a foreign server. A table-level option overrides a server-level
|
|
|
|
option.
|
2017-10-09 03:44:17 +02:00
|
|
|
The default is <literal>true</literal>.
|
2013-06-12 23:52:54 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Of course, if the remote table is not in fact updatable, an error
|
|
|
|
would occur anyway. Use of this option primarily allows the error to
|
|
|
|
be thrown locally without querying the remote server. Note however
|
2017-10-09 03:44:17 +02:00
|
|
|
that the <literal>information_schema</literal> views will report a
|
|
|
|
<filename>postgres_fdw</filename> foreign table to be updatable (or not)
|
2013-06-12 23:52:54 +02:00
|
|
|
according to the setting of this option, without any check of the
|
|
|
|
remote server.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</sect3>
|
2014-07-10 21:01:31 +02:00
|
|
|
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
<sect3>
|
|
|
|
<title>Truncatability Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
By default all foreign tables using <filename>postgres_fdw</filename> are assumed
|
|
|
|
to be truncatable. This may be overridden using the following option:
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>truncatable</literal> (<type>boolean</type>)</term>
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option controls whether <filename>postgres_fdw</filename> allows
|
2021-04-27 11:39:30 +02:00
|
|
|
foreign tables to be truncated using the <command>TRUNCATE</command>
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
command. It can be specified for a foreign table or a foreign server.
|
|
|
|
A table-level option overrides a server-level option.
|
|
|
|
The default is <literal>true</literal>.
|
|
|
|
</para>
|
2021-04-27 11:39:30 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Of course, if the remote table is not in fact truncatable, an error
|
|
|
|
would occur anyway. Use of this option primarily allows the error to
|
|
|
|
be thrown locally without querying the remote server.
|
|
|
|
</para>
|
Allow TRUNCATE command to truncate foreign tables.
This commit introduces new foreign data wrapper API for TRUNCATE.
It extends TRUNCATE command so that it accepts foreign tables as
the targets to truncate and invokes that API. Also it extends postgres_fdw
so that it can issue TRUNCATE command to foreign servers, by adding
new routine for that TRUNCATE API.
The information about options specified in TRUNCATE command, e.g.,
ONLY, CACADE, etc is passed to FDW via API. The list of foreign tables to
truncate is also passed to FDW. FDW truncates the foreign data sources
that the passed foreign tables specify, based on those information.
For example, postgres_fdw constructs TRUNCATE command using them
and issues it to the foreign server.
For performance, TRUNCATE command invokes the FDW routine for
TRUNCATE once per foreign server that foreign tables to truncate belong to.
Author: Kazutaka Onishi, Kohei KaiGai, slightly modified by Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier, Zhihong Yu, Alvaro Herrera, Stephen Frost, Ashutosh Bapat, Amit Langote, Daniel Gustafsson, Ibrar Ahmed, Fujii Masao
Discussion: https://postgr.es/m/CAOP8fzb_gkReLput7OvOK+8NHgw-RKqNv59vem7=524krQTcWA@mail.gmail.com
Discussion: https://postgr.es/m/CAJuF6cMWDDqU-vn_knZgma+2GMaout68YUgn1uyDnexRhqqM5Q@mail.gmail.com
2021-04-08 13:56:08 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</sect3>
|
|
|
|
|
2014-07-10 21:01:31 +02:00
|
|
|
<sect3>
|
|
|
|
<title>Importing Options</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> is able to import foreign table definitions
|
2017-11-23 15:39:47 +01:00
|
|
|
using <xref linkend="sql-importforeignschema"/>. This command creates
|
2014-07-10 21:01:31 +02:00
|
|
|
foreign table definitions on the local server that match tables or
|
|
|
|
views present on the remote server. If the remote tables to be imported
|
2015-05-25 20:12:51 +02:00
|
|
|
have columns of user-defined data types, the local server must have
|
|
|
|
compatible types of the same names.
|
2014-07-10 21:01:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Importing behavior can be customized with the following options
|
2017-10-09 03:44:17 +02:00
|
|
|
(given in the <command>IMPORT FOREIGN SCHEMA</command> command):
|
2014-07-10 21:01:31 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>import_collate</literal> (<type>boolean</type>)</term>
|
2014-07-10 21:01:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This option controls whether column <literal>COLLATE</literal> options
|
2014-07-10 21:01:31 +02:00
|
|
|
are included in the definitions of foreign tables imported
|
2017-10-09 03:44:17 +02:00
|
|
|
from a foreign server. The default is <literal>true</literal>. You might
|
2014-07-10 21:01:31 +02:00
|
|
|
need to turn this off if the remote server has a different set of
|
|
|
|
collation names than the local server does, which is likely to be the
|
|
|
|
case if it's running on a different operating system.
|
2021-09-25 16:53:54 +02:00
|
|
|
If you do so, however, there is a very severe risk that the imported
|
|
|
|
table columns' collations will not match the underlying data, resulting
|
|
|
|
in anomalous query behavior.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Even when this parameter is set to <literal>true</literal>, importing
|
|
|
|
columns whose collation is the remote server's default can be risky.
|
|
|
|
They will be imported with <literal>COLLATE "default"</literal>, which
|
|
|
|
will select the local server's default collation, which could be
|
|
|
|
different.
|
2014-07-10 21:01:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>import_default</literal> (<type>boolean</type>)</term>
|
2014-07-10 21:01:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This option controls whether column <literal>DEFAULT</literal> expressions
|
2014-07-10 21:01:31 +02:00
|
|
|
are included in the definitions of foreign tables imported
|
2017-10-09 03:44:17 +02:00
|
|
|
from a foreign server. The default is <literal>false</literal>. If you
|
2014-07-10 21:01:31 +02:00
|
|
|
enable this option, be wary of defaults that might get computed
|
|
|
|
differently on the local server than they would be on the remote
|
2017-10-09 03:44:17 +02:00
|
|
|
server; <function>nextval()</function> is a common source of problems.
|
|
|
|
The <command>IMPORT</command> will fail altogether if an imported default
|
2014-07-10 21:01:31 +02:00
|
|
|
expression uses a function or operator that does not exist locally.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-08-05 13:00:00 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>import_generated</literal> (<type>boolean</type>)</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option controls whether column <literal>GENERATED</literal> expressions
|
|
|
|
are included in the definitions of foreign tables imported
|
|
|
|
from a foreign server. The default is <literal>true</literal>.
|
|
|
|
The <command>IMPORT</command> will fail altogether if an imported generated
|
|
|
|
expression uses a function or operator that does not exist locally.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2014-07-10 21:01:31 +02:00
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>import_not_null</literal> (<type>boolean</type>)</term>
|
2014-07-10 21:01:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This option controls whether column <literal>NOT NULL</literal>
|
2014-07-10 21:01:31 +02:00
|
|
|
constraints are included in the definitions of foreign tables imported
|
2017-10-09 03:44:17 +02:00
|
|
|
from a foreign server. The default is <literal>true</literal>.
|
2014-07-10 21:01:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
Note that constraints other than <literal>NOT NULL</literal> will never be
|
|
|
|
imported from the remote tables. Although <productname>PostgreSQL</productname>
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
does support check constraints on foreign tables, there is no
|
2015-05-25 20:12:51 +02:00
|
|
|
provision for importing them automatically, because of the risk that a
|
|
|
|
constraint expression could evaluate differently on the local and remote
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
servers. Any such inconsistency in the behavior of a check
|
2015-05-25 20:12:51 +02:00
|
|
|
constraint could lead to hard-to-detect errors in query optimization.
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
So if you wish to import check constraints, you must do so
|
2015-05-25 20:12:51 +02:00
|
|
|
manually, and you should verify the semantics of each one carefully.
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
For more detail about the treatment of check constraints on
|
2017-11-23 15:39:47 +01:00
|
|
|
foreign tables, see <xref linkend="sql-createforeigntable"/>.
|
2014-07-10 21:01:31 +02:00
|
|
|
</para>
|
2017-03-31 21:01:35 +02:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Tables or foreign tables which are partitions of some other table are
|
2021-04-06 19:32:10 +02:00
|
|
|
imported only when they are explicitly specified in
|
|
|
|
<literal>LIMIT TO</literal> clause. Otherwise they are automatically
|
|
|
|
excluded from <xref linkend="sql-importforeignschema"/>.
|
|
|
|
Since all data can be accessed through the partitioned table
|
|
|
|
which is the root of the partitioning hierarchy, importing only
|
|
|
|
partitioned tables should allow access to all the data without
|
2017-03-31 21:01:35 +02:00
|
|
|
creating extra objects.
|
|
|
|
</para>
|
|
|
|
|
2014-07-10 21:01:31 +02:00
|
|
|
</sect3>
|
2021-04-02 12:45:42 +02:00
|
|
|
|
|
|
|
<sect3>
|
|
|
|
<title>Connection Management Options</title>
|
|
|
|
|
|
|
|
<para>
|
2021-04-09 06:53:07 +02:00
|
|
|
By default, all connections that <filename>postgres_fdw</filename>
|
|
|
|
establishes to foreign servers are kept open in the local session
|
|
|
|
for re-use.
|
2021-04-02 12:45:42 +02:00
|
|
|
</para>
|
2021-09-25 16:53:54 +02:00
|
|
|
|
2021-04-02 12:45:42 +02:00
|
|
|
<variablelist>
|
2021-09-25 16:53:54 +02:00
|
|
|
|
2021-04-02 12:45:42 +02:00
|
|
|
<varlistentry>
|
2021-06-30 12:33:18 +02:00
|
|
|
<term><literal>keep_connections</literal> (<type>boolean</type>)</term>
|
2021-04-02 12:45:42 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This option controls whether <filename>postgres_fdw</filename> keeps
|
2021-04-09 06:53:07 +02:00
|
|
|
the connections to the foreign server open so that subsequent
|
2021-04-02 12:45:42 +02:00
|
|
|
queries can re-use them. It can only be specified for a foreign server.
|
|
|
|
The default is <literal>on</literal>. If set to <literal>off</literal>,
|
|
|
|
all connections to this foreign server will be discarded at the end of
|
2021-04-09 06:53:07 +02:00
|
|
|
each transaction.
|
2021-04-02 12:45:42 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-09-25 16:53:54 +02:00
|
|
|
|
2021-04-02 12:45:42 +02:00
|
|
|
</variablelist>
|
|
|
|
</sect3>
|
2013-02-21 11:26:23 +01:00
|
|
|
</sect2>
|
|
|
|
|
2021-01-18 07:11:08 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Functions</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><function>postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</function></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This function returns the foreign server names of all the open
|
|
|
|
connections that <filename>postgres_fdw</filename> established from
|
|
|
|
the local session to the foreign servers. It also returns whether
|
|
|
|
each connection is valid or not. <literal>false</literal> is returned
|
|
|
|
if the foreign server connection is used in the current local
|
|
|
|
transaction but its foreign server or user mapping is changed or
|
2021-01-18 16:56:10 +01:00
|
|
|
dropped (Note that server name of an invalid connection will be
|
|
|
|
<literal>NULL</literal> if the server is dropped),
|
|
|
|
and then such invalid connection will be closed at
|
2021-01-18 07:11:08 +01:00
|
|
|
the end of that transaction. <literal>true</literal> is returned
|
|
|
|
otherwise. If there are no open connections, no record is returned.
|
|
|
|
Example usage of the function:
|
2021-01-25 19:54:46 +01:00
|
|
|
<screen>
|
2021-01-18 07:11:08 +01:00
|
|
|
postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;
|
|
|
|
server_name | valid
|
|
|
|
-------------+-------
|
|
|
|
loopback1 | t
|
|
|
|
loopback2 | f
|
|
|
|
</screen>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-01-25 19:54:46 +01:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><function>postgres_fdw_disconnect(server_name text) returns boolean</function></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This function discards the open connections that are established by
|
|
|
|
<filename>postgres_fdw</filename> from the local session to
|
|
|
|
the foreign server with the given name. Note that there can be
|
|
|
|
multiple connections to the given server using different user mappings.
|
|
|
|
If the connections are used in the current local transaction,
|
|
|
|
they are not disconnected and warning messages are reported.
|
|
|
|
This function returns <literal>true</literal> if it disconnects
|
|
|
|
at least one connection, otherwise <literal>false</literal>.
|
|
|
|
If no foreign server with the given name is found, an error is reported.
|
|
|
|
Example usage of the function:
|
|
|
|
<screen>
|
|
|
|
postgres=# SELECT postgres_fdw_disconnect('loopback1');
|
|
|
|
postgres_fdw_disconnect
|
|
|
|
-------------------------
|
|
|
|
t
|
|
|
|
</screen>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><function>postgres_fdw_disconnect_all() returns boolean</function></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
This function discards all the open connections that are established by
|
|
|
|
<filename>postgres_fdw</filename> from the local session to
|
2021-02-24 08:13:17 +01:00
|
|
|
foreign servers. If the connections are used in the current local
|
2021-01-25 19:54:46 +01:00
|
|
|
transaction, they are not disconnected and warning messages are reported.
|
|
|
|
This function returns <literal>true</literal> if it disconnects
|
|
|
|
at least one connection, otherwise <literal>false</literal>.
|
|
|
|
Example usage of the function:
|
|
|
|
<screen>
|
|
|
|
postgres=# SELECT postgres_fdw_disconnect_all();
|
|
|
|
postgres_fdw_disconnect_all
|
|
|
|
-----------------------------
|
|
|
|
t
|
|
|
|
</screen>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2021-01-18 07:11:08 +01:00
|
|
|
</variablelist>
|
|
|
|
|
|
|
|
</sect2>
|
|
|
|
|
2013-02-21 11:26:23 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Connection Management</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<filename>postgres_fdw</filename> establishes a connection to a
|
|
|
|
foreign server during the first query that uses a foreign table
|
2021-04-02 12:45:42 +02:00
|
|
|
associated with the foreign server. By default this connection
|
|
|
|
is kept and re-used for subsequent queries in the same session.
|
|
|
|
This behavior can be controlled using
|
|
|
|
<literal>keep_connections</literal> option for a foreign server. If
|
2013-02-21 11:26:23 +01:00
|
|
|
multiple user identities (user mappings) are used to access the foreign
|
|
|
|
server, a connection is established for each user mapping.
|
|
|
|
</para>
|
2021-01-25 19:54:46 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
When changing the definition of or removing a foreign server or
|
2021-02-24 08:13:17 +01:00
|
|
|
a user mapping, the associated connections are closed.
|
|
|
|
But note that if any connections are in use in the current local transaction,
|
|
|
|
they are kept until the end of the transaction.
|
|
|
|
Closed connections will be re-established when they are necessary
|
|
|
|
by future queries using a foreign table.
|
2021-01-25 19:54:46 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Once a connection to a foreign server has been established,
|
2021-04-02 12:45:42 +02:00
|
|
|
it's by default kept until the local or corresponding remote
|
2021-01-25 19:54:46 +01:00
|
|
|
session exits. To disconnect a connection explicitly,
|
2021-04-02 12:45:42 +02:00
|
|
|
<literal>keep_connections</literal> option for a foreign server
|
|
|
|
may be disabled, or
|
2021-01-25 19:54:46 +01:00
|
|
|
<function>postgres_fdw_disconnect</function> and
|
|
|
|
<function>postgres_fdw_disconnect_all</function> functions
|
2021-02-24 08:13:17 +01:00
|
|
|
may be used. For example, these are useful to close
|
|
|
|
connections that are no longer necessary, thereby releasing
|
|
|
|
connections on the foreign server.
|
2021-01-25 19:54:46 +01:00
|
|
|
</para>
|
2013-02-21 11:26:23 +01:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Transaction Management</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
During a query that references any remote tables on a foreign server,
|
|
|
|
<filename>postgres_fdw</filename> opens a transaction on the
|
|
|
|
remote server if one is not already open corresponding to the current
|
|
|
|
local transaction. The remote transaction is committed or aborted when
|
|
|
|
the local transaction commits or aborts. Savepoints are similarly
|
|
|
|
managed by creating corresponding remote savepoints.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The remote transaction uses <literal>SERIALIZABLE</literal>
|
|
|
|
isolation level when the local transaction has <literal>SERIALIZABLE</literal>
|
|
|
|
isolation level; otherwise it uses <literal>REPEATABLE READ</literal>
|
2013-02-21 11:26:23 +01:00
|
|
|
isolation level. This choice ensures that if a query performs multiple
|
|
|
|
table scans on the remote server, it will get snapshot-consistent results
|
|
|
|
for all the scans. A consequence is that successive queries within a
|
|
|
|
single transaction will see the same data from the remote server, even if
|
|
|
|
concurrent updates are occurring on the remote server due to other
|
|
|
|
activities. That behavior would be expected anyway if the local
|
2017-10-09 03:44:17 +02:00
|
|
|
transaction uses <literal>SERIALIZABLE</literal> or <literal>REPEATABLE READ</literal>
|
2013-02-21 11:26:23 +01:00
|
|
|
isolation level, but it might be surprising for a <literal>READ
|
2017-10-09 03:44:17 +02:00
|
|
|
COMMITTED</literal> local transaction. A future
|
2013-02-21 11:26:23 +01:00
|
|
|
<productname>PostgreSQL</productname> release might modify these rules.
|
|
|
|
</para>
|
2019-11-08 09:00:30 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that it is currently not supported by
|
|
|
|
<filename>postgres_fdw</filename> to prepare the remote transaction for
|
|
|
|
two-phase commit.
|
|
|
|
</para>
|
2013-02-21 11:26:23 +01:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Remote Query Optimization</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> attempts to optimize remote queries to reduce
|
2013-02-21 11:26:23 +01:00
|
|
|
the amount of data transferred from foreign servers. This is done by
|
2017-10-09 03:44:17 +02:00
|
|
|
sending query <literal>WHERE</literal> clauses to the remote server for
|
2013-02-21 11:26:23 +01:00
|
|
|
execution, and by not retrieving table columns that are not needed for
|
|
|
|
the current query. To reduce the risk of misexecution of queries,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>WHERE</literal> clauses are not sent to the remote server unless they use
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
only data types, operators, and functions that are built-in or belong to an
|
2017-10-09 03:44:17 +02:00
|
|
|
extension that's listed in the foreign server's <literal>extensions</literal>
|
Allow postgres_fdw to ship extension funcs/operators for remote execution.
The user can whitelist specified extension(s) in the foreign server's
options, whereupon we will treat immutable functions and operators of those
extensions as candidates to be sent for remote execution.
Whitelisting an extension in this way basically promises that the extension
exists on the remote server and behaves compatibly with the local instance.
We have no way to prove that formally, so we have to rely on the user to
get it right. But this seems like something that people can usually get
right in practice.
We might in future allow functions and operators to be whitelisted
individually, but extension granularity is a very convenient special case,
so it got done first.
The patch as-committed lacks any regression tests, which is unfortunate,
but introducing dependencies on other extensions for testing purposes
would break "make installcheck" scenarios, which is worse. I have some
ideas about klugy ways around that, but it seems like material for a
separate patch. For the moment, leave the problem open.
Paul Ramsey, hacked up a bit more by me
2015-11-04 00:42:02 +01:00
|
|
|
option. Operators and functions in such clauses must
|
2017-10-09 03:44:17 +02:00
|
|
|
be <literal>IMMUTABLE</literal> as well.
|
|
|
|
For an <command>UPDATE</command> or <command>DELETE</command> query,
|
|
|
|
<filename>postgres_fdw</filename> attempts to optimize the query execution by
|
2016-03-18 18:48:58 +01:00
|
|
|
sending the whole query to the remote server if there are no query
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>WHERE</literal> clauses that cannot be sent to the remote server,
|
|
|
|
no local joins for the query, no row-level local <literal>BEFORE</literal> or
|
2019-09-18 11:50:00 +02:00
|
|
|
<literal>AFTER</literal> triggers or stored generated columns on the target
|
|
|
|
table, and no <literal>CHECK OPTION</literal> constraints from parent
|
|
|
|
views. In <command>UPDATE</command>,
|
2016-03-18 18:48:58 +01:00
|
|
|
expressions to assign to target columns must use only built-in data types,
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>IMMUTABLE</literal> operators, or <literal>IMMUTABLE</literal> functions,
|
2016-03-18 18:48:58 +01:00
|
|
|
to reduce the risk of misexecution of the query.
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
|
2016-02-09 20:00:50 +01:00
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
When <filename>postgres_fdw</filename> encounters a join between foreign tables on
|
2016-02-09 20:00:50 +01:00
|
|
|
the same foreign server, it sends the entire join to the foreign server,
|
|
|
|
unless for some reason it believes that it will be more efficient to fetch
|
|
|
|
rows from each table individually, or unless the table references involved
|
2017-10-09 03:44:17 +02:00
|
|
|
are subject to different user mappings. While sending the <literal>JOIN</literal>
|
2016-02-09 20:00:50 +01:00
|
|
|
clauses, it takes the same precautions as mentioned above for the
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>WHERE</literal> clauses.
|
2016-02-09 20:00:50 +01:00
|
|
|
</para>
|
|
|
|
|
2013-02-21 11:26:23 +01:00
|
|
|
<para>
|
|
|
|
The query that is actually sent to the remote server for execution can
|
2017-10-09 03:44:17 +02:00
|
|
|
be examined using <command>EXPLAIN VERBOSE</command>.
|
2013-02-21 11:26:23 +01:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2015-08-15 20:31:04 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Remote Query Execution Environment</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
In the remote sessions opened by <filename>postgres_fdw</filename>,
|
2017-11-23 15:39:47 +01:00
|
|
|
the <xref linkend="guc-search-path"/> parameter is set to
|
2017-10-09 03:44:17 +02:00
|
|
|
just <literal>pg_catalog</literal>, so that only built-in objects are visible
|
2015-08-15 20:31:04 +02:00
|
|
|
without schema qualification. This is not an issue for queries
|
2017-10-09 03:44:17 +02:00
|
|
|
generated by <filename>postgres_fdw</filename> itself, because it always
|
2015-08-15 20:31:04 +02:00
|
|
|
supplies such qualification. However, this can pose a hazard for
|
|
|
|
functions that are executed on the remote server via triggers or rules
|
|
|
|
on remote tables. For example, if a remote table is actually a view,
|
|
|
|
any functions used in that view will be executed with the restricted
|
|
|
|
search path. It is recommended to schema-qualify all names in such
|
2017-10-09 03:44:17 +02:00
|
|
|
functions, or else attach <literal>SET search_path</literal> options
|
2017-11-23 15:39:47 +01:00
|
|
|
(see <xref linkend="sql-createfunction"/>) to such functions
|
2015-08-15 20:31:04 +02:00
|
|
|
to establish their expected search path environment.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> likewise establishes remote session settings
|
2019-04-08 22:27:35 +02:00
|
|
|
for various parameters:
|
2017-03-07 16:57:46 +01:00
|
|
|
<itemizedlist spacing="compact">
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-timezone"/> is set to <literal>UTC</literal>
|
2017-03-07 16:57:46 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-datestyle"/> is set to <literal>ISO</literal>
|
2017-03-07 16:57:46 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-intervalstyle"/> is set to <literal>postgres</literal>
|
2017-03-07 16:57:46 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="guc-extra-float-digits"/> is set to <literal>3</literal> for remote
|
2017-10-09 03:44:17 +02:00
|
|
|
servers 9.0 and newer and is set to <literal>2</literal> for older versions
|
2017-03-07 16:57:46 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2017-10-09 03:44:17 +02:00
|
|
|
These are less likely to be problematic than <varname>search_path</varname>, but
|
|
|
|
can be handled with function <literal>SET</literal> options if the need arises.
|
2015-08-15 20:31:04 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
It is <emphasis>not</emphasis> recommended that you override this behavior by
|
2015-08-15 20:31:04 +02:00
|
|
|
changing the session-level settings of these parameters; that is likely
|
2017-10-09 03:44:17 +02:00
|
|
|
to cause <filename>postgres_fdw</filename> to malfunction.
|
2015-08-15 20:31:04 +02:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2013-03-22 22:22:31 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Cross-Version Compatibility</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>postgres_fdw</filename> can be used with remote servers dating back
|
|
|
|
to <productname>PostgreSQL</productname> 8.3. Read-only capability is available
|
|
|
|
back to 8.1. A limitation however is that <filename>postgres_fdw</filename>
|
2013-03-22 22:22:31 +01:00
|
|
|
generally assumes that immutable built-in functions and operators are
|
|
|
|
safe to send to the remote server for execution, if they appear in a
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>WHERE</literal> clause for a foreign table. Thus, a built-in
|
2013-03-22 22:22:31 +01:00
|
|
|
function that was added since the remote server's release might be sent
|
2017-10-09 03:44:17 +02:00
|
|
|
to it for execution, resulting in <quote>function does not exist</quote> or
|
2013-03-22 22:22:31 +01:00
|
|
|
a similar error. This type of failure can be worked around by
|
|
|
|
rewriting the query, for example by embedding the foreign table
|
2017-10-09 03:44:17 +02:00
|
|
|
reference in a sub-<literal>SELECT</literal> with <literal>OFFSET 0</literal> as an
|
2013-03-22 22:22:31 +01:00
|
|
|
optimization fence, and placing the problematic function or operator
|
2017-10-09 03:44:17 +02:00
|
|
|
outside the sub-<literal>SELECT</literal>.
|
2013-03-22 22:22:31 +01:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2021-09-07 05:27:30 +02:00
|
|
|
<sect2>
|
|
|
|
<title>Configuration Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
2021-12-24 08:55:11 +01:00
|
|
|
<varlistentry id="guc-pgfdw-application-name" xreflabel="postgres_fdw.application_name">
|
2021-09-07 05:27:30 +02:00
|
|
|
<term>
|
|
|
|
<varname>postgres_fdw.application_name</varname> (<type>string</type>)
|
|
|
|
<indexterm>
|
|
|
|
<primary><varname>postgres_fdw.application_name</varname> configuration parameter</primary>
|
|
|
|
</indexterm>
|
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies a value for <xref linkend="guc-application-name"/>
|
|
|
|
configuration parameter used when <filename>postgres_fdw</filename>
|
|
|
|
establishes a connection to a foreign server. This overrides
|
|
|
|
<varname>application_name</varname> option of the server object.
|
|
|
|
Note that change of this parameter doesn't affect any existing
|
|
|
|
connections until they are re-established.
|
|
|
|
</para>
|
2021-12-16 07:18:30 +01:00
|
|
|
<para>
|
|
|
|
<varname>postgres_fdw.application_name</varname> can be any string
|
|
|
|
of any length and contain even non-ASCII characters. However when
|
|
|
|
it's passed to and used as <varname>application_name</varname>
|
|
|
|
in a foreign server, note that it will be truncated to less than
|
2022-01-25 01:40:04 +01:00
|
|
|
<symbol>NAMEDATALEN</symbol> characters and anything other than
|
2022-03-15 03:29:23 +01:00
|
|
|
printable ASCII characters will be replaced with question
|
2021-12-16 07:18:30 +01:00
|
|
|
marks (<literal>?</literal>).
|
|
|
|
See <xref linkend="guc-application-name"/> for details.
|
|
|
|
</para>
|
2021-12-24 08:55:11 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
<literal>%</literal> characters begin <quote>escape sequences</quote>
|
|
|
|
that are replaced with status information as outlined below.
|
|
|
|
Unrecognized escapes are ignored. Other characters are copied straight
|
|
|
|
to the application name. Note that it's not allowed to specify a
|
|
|
|
plus/minus sign or a numeric literal after the <literal>%</literal>
|
|
|
|
and before the option, for alignment and padding.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Escape</entry>
|
|
|
|
<entry>Effect</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry><literal>%a</literal></entry>
|
2022-01-25 01:40:04 +01:00
|
|
|
<entry>Application name on local server</entry>
|
2021-12-24 08:55:11 +01:00
|
|
|
</row>
|
2022-02-18 03:38:12 +01:00
|
|
|
<row>
|
|
|
|
<entry><literal>%c</literal></entry>
|
|
|
|
<entry>
|
|
|
|
Session ID on local server
|
|
|
|
(see <xref linkend="guc-log-line-prefix"/> for details)
|
|
|
|
</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>%C</literal></entry>
|
|
|
|
<entry>
|
2022-04-11 10:48:48 +02:00
|
|
|
Cluster name on local server
|
2022-02-18 03:38:12 +01:00
|
|
|
(see <xref linkend="guc-cluster-name"/> for details)
|
|
|
|
</entry>
|
|
|
|
</row>
|
2021-12-24 08:55:11 +01:00
|
|
|
<row>
|
|
|
|
<entry><literal>%u</literal></entry>
|
2022-01-25 01:40:04 +01:00
|
|
|
<entry>User name on local server</entry>
|
2021-12-24 08:55:11 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>%d</literal></entry>
|
2022-01-25 01:40:04 +01:00
|
|
|
<entry>Database name on local server</entry>
|
2021-12-24 08:55:11 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>%p</literal></entry>
|
2022-01-25 01:40:04 +01:00
|
|
|
<entry>Process ID of backend on local server</entry>
|
2021-12-24 08:55:11 +01:00
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>%%</literal></entry>
|
|
|
|
<entry>Literal %</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
For example, suppose user <literal>local_user</literal> establishes
|
|
|
|
a connection from database <literal>local_db</literal> to
|
|
|
|
<literal>foreign_db</literal> as user <literal>foreign_user</literal>,
|
|
|
|
the setting <literal>'db=%d, user=%u'</literal> is replaced with
|
|
|
|
<literal>'db=local_db, user=local_user'</literal>.
|
|
|
|
</para>
|
|
|
|
|
2021-09-07 05:27:30 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</sect2>
|
|
|
|
|
2014-01-31 23:27:50 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Here is an example of creating a foreign table with
|
2017-10-09 03:44:17 +02:00
|
|
|
<literal>postgres_fdw</literal>. First install the extension:
|
2014-01-31 23:27:50 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE EXTENSION postgres_fdw;
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
Then create a foreign server using <xref linkend="sql-createserver"/>.
|
2017-10-09 03:44:17 +02:00
|
|
|
In this example we wish to connect to a <productname>PostgreSQL</productname> server
|
2014-01-31 23:27:50 +01:00
|
|
|
on host <literal>192.83.123.89</literal> listening on
|
|
|
|
port <literal>5432</literal>. The database to which the connection is made
|
|
|
|
is named <literal>foreign_db</literal> on the remote server:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE SERVER foreign_server
|
|
|
|
FOREIGN DATA WRAPPER postgres_fdw
|
|
|
|
OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
A user mapping, defined with <xref linkend="sql-createusermapping"/>, is
|
2014-01-31 23:27:50 +01:00
|
|
|
needed as well to identify the role that will be used on the remote
|
|
|
|
server:
|
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE USER MAPPING FOR local_user
|
|
|
|
SERVER foreign_server
|
|
|
|
OPTIONS (user 'foreign_user', password 'password');
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Now it is possible to create a foreign table with
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="sql-createforeigntable"/>. In this example we
|
2017-10-09 03:44:17 +02:00
|
|
|
wish to access the table named <structname>some_schema.some_table</structname>
|
2014-01-31 23:27:50 +01:00
|
|
|
on the remote server. The local name for it will
|
2017-10-09 03:44:17 +02:00
|
|
|
be <structname>foreign_table</structname>:
|
2014-01-31 23:27:50 +01:00
|
|
|
|
|
|
|
<programlisting>
|
|
|
|
CREATE FOREIGN TABLE foreign_table (
|
2014-07-10 21:01:31 +02:00
|
|
|
id integer NOT NULL,
|
2014-01-31 23:27:50 +01:00
|
|
|
data text
|
|
|
|
)
|
|
|
|
SERVER foreign_server
|
|
|
|
OPTIONS (schema_name 'some_schema', table_name 'some_table');
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
It's essential that the data types and other properties of the columns
|
2017-10-09 03:44:17 +02:00
|
|
|
declared in <command>CREATE FOREIGN TABLE</command> match the actual remote table.
|
|
|
|
Column names must match as well, unless you attach <literal>column_name</literal>
|
2014-01-31 23:27:50 +01:00
|
|
|
options to the individual columns to show how they are named in the remote
|
|
|
|
table.
|
Improve <xref> vs. <command> formatting in the documentation
SQL commands are generally marked up as <command>, except when a link
to a reference page is used using <xref>. But the latter doesn't
create monospace markup, so this looks strange especially when a
paragraph contains a mix of links and non-links.
We considered putting <command> in the <refentrytitle> on the target
side, but that creates some formatting side effects elsewhere.
Generally, it seems safer to solve this on the link source side.
We can't put the <xref> inside the <command>; the DTD doesn't allow
this. DocBook 5 would allow the <command> to have the linkend
attribute itself, but we are not there yet.
So to solve this for now, convert the <xref>s to <link> plus
<command>. This gives the correct look and also gives some more
flexibility what we can put into the link text (e.g., subcommands or
other clauses). In the future, these could then be converted to
DocBook 5 style.
I haven't converted absolutely all xrefs to SQL command reference
pages, only those where we care about the appearance of the link text
or where it was otherwise appropriate to make the appearance match a
bit better. Also in some cases, the links where repetitive, so in
those cases the links where just removed and replaced by a plain
<command>. In cases where we just want the link and don't
specifically care about the generated link text (typically phrased
"for further information see <xref ...>") the xref is kept.
Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/87o8pco34z.fsf@wibble.ilmari.org
2020-10-03 16:16:51 +02:00
|
|
|
In many cases, use of <link linkend="sql-importforeignschema"><command>IMPORT FOREIGN SCHEMA</command></link> is
|
2014-07-10 21:01:31 +02:00
|
|
|
preferable to constructing foreign table definitions manually.
|
2014-01-31 23:27:50 +01:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
2013-02-21 11:26:23 +01:00
|
|
|
<sect2>
|
|
|
|
<title>Author</title>
|
|
|
|
<para>
|
|
|
|
Shigeru Hanada <email>shigeru.hanada@gmail.com</email>
|
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|