{"Entry":{"collection":"fdw","key":"postgres_fdw","name":"postgres_fdw","aliases":[],"metadata":{"aliases":[],"category":"Remote PostgreSQL","content_hash":"508c923290815097efdade63f651f1fa196d04e4b5396a864eb15461f7466418","imported_at":"2026-09-30T00:40:37.121281+08:00","name":"postgres_fdw","name_zh":"Remote PostgreSQL","slug":"postgres_fdw","summary":"Accesses tables in remote PostgreSQL servers through foreign tables."}},"Definition":{"Collection":"fdw","Key":"postgres_fdw","SourceDatabase":"center","Version":"18","SourceTable":"foreign_data_wrapper","SourceKey":"postgres_fdw","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"callbacks":{"AddForeignUpdateTargets":"postgresAddForeignUpdateTargets","AnalyzeForeignTable":"postgresAnalyzeForeignTable","BeginDirectModify":"postgresBeginDirectModify","BeginForeignInsert":"postgresBeginForeignInsert","BeginForeignModify":"postgresBeginForeignModify","BeginForeignScan":"postgresBeginForeignScan","EndDirectModify":"postgresEndDirectModify","EndForeignInsert":"postgresEndForeignInsert","EndForeignModify":"postgresEndForeignModify","EndForeignScan":"postgresEndForeignScan","ExecForeignBatchInsert":"postgresExecForeignBatchInsert","ExecForeignDelete":"postgresExecForeignDelete","ExecForeignInsert":"postgresExecForeignInsert","ExecForeignTruncate":"postgresExecForeignTruncate","ExecForeignUpdate":"postgresExecForeignUpdate","ExplainDirectModify":"postgresExplainDirectModify","ExplainForeignModify":"postgresExplainForeignModify","ExplainForeignScan":"postgresExplainForeignScan","ForeignAsyncConfigureWait":"postgresForeignAsyncConfigureWait","ForeignAsyncNotify":"postgresForeignAsyncNotify","ForeignAsyncRequest":"postgresForeignAsyncRequest","GetForeignJoinPaths":"postgresGetForeignJoinPaths","GetForeignModifyBatchSize":"postgresGetForeignModifyBatchSize","GetForeignPaths":"postgresGetForeignPaths","GetForeignPlan":"postgresGetForeignPlan","GetForeignRelSize":"postgresGetForeignRelSize","GetForeignUpperPaths":"postgresGetForeignUpperPaths","ImportForeignSchema":"postgresImportForeignSchema","IsForeignPathAsyncCapable":"postgresIsForeignPathAsyncCapable","IsForeignRelUpdatable":"postgresIsForeignRelUpdatable","IterateDirectModify":"postgresIterateDirectModify","IterateForeignScan":"postgresIterateForeignScan","PlanDirectModify":"postgresPlanDirectModify","PlanForeignModify":"postgresPlanForeignModify","ReScanForeignScan":"postgresReScanForeignScan","RecheckForeignScan":"postgresRecheckForeignScan"},"comparison_data":{"callbacks":{"AddForeignUpdateTargets":"postgresAddForeignUpdateTargets","AnalyzeForeignTable":"postgresAnalyzeForeignTable","BeginDirectModify":"postgresBeginDirectModify","BeginForeignInsert":"postgresBeginForeignInsert","BeginForeignModify":"postgresBeginForeignModify","BeginForeignScan":"postgresBeginForeignScan","EndDirectModify":"postgresEndDirectModify","EndForeignInsert":"postgresEndForeignInsert","EndForeignModify":"postgresEndForeignModify","EndForeignScan":"postgresEndForeignScan","ExecForeignBatchInsert":"postgresExecForeignBatchInsert","ExecForeignDelete":"postgresExecForeignDelete","ExecForeignInsert":"postgresExecForeignInsert","ExecForeignTruncate":"postgresExecForeignTruncate","ExecForeignUpdate":"postgresExecForeignUpdate","ExplainDirectModify":"postgresExplainDirectModify","ExplainForeignModify":"postgresExplainForeignModify","ExplainForeignScan":"postgresExplainForeignScan","ForeignAsyncConfigureWait":"postgresForeignAsyncConfigureWait","ForeignAsyncNotify":"postgresForeignAsyncNotify","ForeignAsyncRequest":"postgresForeignAsyncRequest","GetForeignJoinPaths":"postgresGetForeignJoinPaths","GetForeignModifyBatchSize":"postgresGetForeignModifyBatchSize","GetForeignPaths":"postgresGetForeignPaths","GetForeignPlan":"postgresGetForeignPlan","GetForeignRelSize":"postgresGetForeignRelSize","GetForeignUpperPaths":"postgresGetForeignUpperPaths","ImportForeignSchema":"postgresImportForeignSchema","IsForeignPathAsyncCapable":"postgresIsForeignPathAsyncCapable","IsForeignRelUpdatable":"postgresIsForeignRelUpdatable","IterateDirectModify":"postgresIterateDirectModify","IterateForeignScan":"postgresIterateForeignScan","PlanDirectModify":"postgresPlanDirectModify","PlanForeignModify":"postgresPlanForeignModify","ReScanForeignScan":"postgresReScanForeignScan","RecheckForeignScan":"postgresRecheckForeignScan"},"options":[{"definition":"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.","name":"schema_name"},{"definition":"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.","name":"table_name"},{"definition":"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.","name":"column_name"},{"definition":"This option, which can be specified for a foreign table or a foreign server, controls whether postgres_fdw issues remote EXPLAIN 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 false .","name":"use_remote_estimate"},{"definition":"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. The default value is 100 .","name":"fdw_startup_cost"},{"definition":"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 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 0.2 .","name":"fdw_tuple_cost"},{"definition":"This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are off , random , system , bernoulli and auto . off disables remote sampling, so all data are transferred and sampled locally. random performs remote sampling using the random() function to choose returned rows, while system and bernoulli rely on the built-in TABLESAMPLE methods of those names. random works on all remote server versions, while TABLESAMPLE is supported only since 9.5. auto (the default) picks the recommended sampling method automatically; currently it means either bernoulli or random depending on the remote server version.","name":"analyze_sampling"},{"definition":"This option is a comma-separated list of names of PostgreSQL extensions that are installed, in 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. When using the extensions option, it is the user's responsibility that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.","name":"extensions"},{"definition":"This option specifies the number of rows postgres_fdw 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. The default is 100 .","name":"fetch_size"},{"definition":"This option specifies the number of rows postgres_fdw 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 1 . Note the actual number of rows postgres_fdw inserts at once depends on the number of columns and the provided batch_size value. The batch is executed as a single query, and the libpq protocol (which postgres_fdw uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * batch_size exceeds the limit, the batch_size will be adjusted to avoid an error. This option also applies when copying into foreign tables. In that case the actual number of rows postgres_fdw copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the COPY command.","name":"batch_size"},{"definition":"This option controls whether postgres_fdw 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 false . In order to ensure that the data being returned from a foreign server is consistent, postgres_fdw 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. Asynchronous execution is applied even when an Append 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 postgres_fdw , 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.","name":"async_capable"},{"definition":"This option controls whether postgres_fdw commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_commit"},{"definition":"This option controls whether postgres_fdw aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_abort"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be modified using INSERT , UPDATE and DELETE commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is true . 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 that the information_schema views will report a postgres_fdw foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.","name":"updatable"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be truncated using the TRUNCATE 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 true . 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.","name":"truncatable"},{"definition":"This option controls whether column COLLATE options are included in the definitions of foreign tables imported from a foreign server. The default is true . You might 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. 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. Even when this parameter is set to true , importing columns whose collation is the remote server's default can be risky. They will be imported with COLLATE \"default\" , which will select the local server's default collation, which could be different.","name":"import_collate"},{"definition":"This option controls whether column DEFAULT expressions are included in the definitions of foreign tables imported from a foreign server. The default is false . If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; nextval() is a common source of problems. The IMPORT will fail altogether if an imported default expression uses a function or operator that does not exist locally.","name":"import_default"},{"definition":"This option controls whether column GENERATED expressions are included in the definitions of foreign tables imported from a foreign server. The default is true . The IMPORT will fail altogether if an imported generated expression uses a function or operator that does not exist locally.","name":"import_generated"},{"definition":"This option controls whether column NOT NULL constraints are included in the definitions of foreign tables imported from a foreign server. The default is true .","name":"import_not_null"},{"definition":"This option controls whether postgres_fdw keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is on . If set to off , all connections to this foreign server will be discarded at the end of each transaction.","name":"keep_connections"},{"definition":"This option controls whether postgres_fdw will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, postgres_fdw uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs. To use SCRAM pass-through authentication: The remote server must request the scram-sha-256 authentication method; otherwise, the connection will fail. The remote server can be of any PostgreSQL version that supports SCRAM. Support for use_scram_passthrough is only required on the client side (FDW side). The user mapping password is not used. The server running postgres_fdw and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on postgres_fdw to authenticate on the foreign server (same salt and iterations, not merely the same password). As a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved. The current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence “ pass-through ” : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.","name":"use_scram_passthrough"}],"protocol_versions":{},"source_options":[]},"comparison_hash":"b8cfe64df86ef92c7aa383c99b1ce6ddc0c195b32004bf9a4ec0ea46bb7e9ba8","description":["Accesses tables in remote PostgreSQL servers through foreign tables."],"evidence_kind":"source and documentation","facts":[{"label":"Interface family","value":"Foreign-data wrapper"},{"label":"Handler or routine","value":"postgres_fdw_handler"},{"label":"Recorded callbacks","value":"36"},{"label":"Data source","value":"Remote PostgreSQL servers"}],"manual_html":"\u003cdiv class=\"sect1\" id=\"POSTGRES-FDW\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003eF.38. postgres_fdw — access data stored in external \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e servers \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e module provides the foreign-data wrapper \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e, which can be used to access data stored in external \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e servers.\u003c/p\u003e\n\u003cp\u003eThe functionality provided by this module overlaps substantially with the functionality of the older \u003ca class=\"xref\" href=\"/docs/18/dblink.html\" title=\"F.11. dblink — connect to other PostgreSQL databases\"\u003edblink\u003c/a\u003e module. But \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.\u003c/p\u003e\n\u003cp\u003eTo prepare for remote access using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv class=\"orderedlist\"\u003e\n\u003col class=\"orderedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eInstall the \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e extension using \u003ca class=\"xref\" href=\"/docs/18/sql-createextension.html\" title=\"CREATE EXTENSION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE EXTENSION\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a foreign server object, using \u003ca class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e, to represent each remote database you want to connect to. Specify connection information, except \u003ccode class=\"literal\"\u003euser\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e, as options of the server object.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a user mapping, using \u003ca class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as \u003ccode class=\"literal\"\u003euser\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e options of the user mapping.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a foreign table, using \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e or \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e, 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003cp\u003eNow you need only \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e, or \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)\u003c/p\u003e\n\u003cp\u003eNote that the \u003ccode class=\"literal\"\u003eONLY\u003c/code\u003e option specified in \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e or \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e has no effect when accessing or modifying the remote table.\u003c/p\u003e\n\u003cp\u003eNote that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e currently lacks support for \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e statements with an \u003ccode class=\"literal\"\u003eON CONFLICT DO UPDATE\u003c/code\u003e clause. However, the \u003ccode class=\"literal\"\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause is supported, provided a unique index inference specification is omitted. Note also that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e supports row movement invoked by \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e 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 \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e target partition that will be updated elsewhere in the same command.\u003c/p\u003e\n\u003cp\u003eIt is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e is currently rather forgiving about performing data type conversions at need, surprising semantic anomalies may arise when types or collations do not match, due to the remote server interpreting query conditions differently from the local server.\u003c/p\u003e\n\u003cp\u003eNote 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.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.1. FDW Options of postgres_fdw \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.1. Connection Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA foreign server using the \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e foreign data wrapper can have the same options that \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e accepts in connection strings, as described in \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2. Parameter Key Words\"\u003eSection 32.1.2\u003c/a\u003e, except that these options are not allowed or have special handling:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003euser\u003c/code\u003e, \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e and \u003ccode class=\"literal\"\u003esslpassword\u003c/code\u003e (specify these in a user mapping instead, or use a service file)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003eclient_encoding\u003c/code\u003e (this is automatically set from the local server encoding)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003eapplication_name\u003c/code\u003e - this may appear in \u003cspan class=\"emphasis\"\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\"\u003epostgres_fdw.application_name\u003c/a\u003e. If both are present, \u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e overrides the connection setting. Unlike \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e to include \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e. See \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\"\u003epostgres_fdw.application_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003efallback_application_name\u003c/code\u003e (always set to \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003esslkey\u003c/code\u003e and \u003ccode class=\"literal\"\u003esslcert\u003c/code\u003e - these may appear in \u003cspan class=\"emphasis\"\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eOnly superusers may create or modify user mappings with the \u003ccode class=\"literal\"\u003esslcert\u003c/code\u003e or \u003ccode class=\"literal\"\u003esslkey\u003c/code\u003e settings.\u003c/p\u003e\n\u003cp\u003eNon-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e option for user mappings belonging to non-superusers where password authentication is required.\u003c/p\u003e\n\u003cp\u003eA superuser may override this check on a per-user-mapping basis by setting the user mapping option \u003ccode class=\"literal\"\u003epassword_required 'false'\u003c/code\u003e, e.g.,\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n\u003c/pre\u003e\n\u003cp\u003eTo 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.\u003c/p\u003e\n\u003cp\u003eCare 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 \u003ccode class=\"literal\"\u003epassword_required=false\u003c/code\u003e on the \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e role. Keep in mind that the mapped user can potentially use any client certificates, \u003ccode class=\"filename\"\u003e.pgpass\u003c/code\u003e, \u003ccode class=\"filename\"\u003e.pg_service.conf\u003c/code\u003e etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e.) They can also use any trust relationship granted by authentication modes like \u003ccode class=\"literal\"\u003epeer\u003c/code\u003e or \u003ccode class=\"literal\"\u003eident\u003c/code\u003e authentication.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.2. Object Name Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThese options can be used to control the names used in SQL statements sent to the remote \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server. These options are needed when a foreign table is created with names different from the underlying remote table's names.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eschema_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003etable_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ecolumn_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.3. Cost Estimation Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e retrieves remote data by executing queries 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. So \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e provides the following options to control how cost estimation is done:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e issues remote \u003ccode class=\"command\"\u003eEXPLAIN\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e (\u003ccode class=\"type\"\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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. The default value is \u003ccode class=\"literal\"\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e (\u003ccode class=\"type\"\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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 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 \u003ccode class=\"literal\"\u003e0.2\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eWhen \u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e is true, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e obtains row count and cost estimates from the remote server and then adds \u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e and \u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e to the cost estimates. When \u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e is false, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e performs local row count and cost estimation and then adds \u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e and \u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e 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 \u003ca class=\"xref\" href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"\u003e\u003cspan class=\"refentrytitle\"\u003eANALYZE\u003c/span\u003e\u003c/a\u003e on the foreign table is the way to update 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.\u003c/p\u003e\n\u003cp\u003eThe following option controls how such an \u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e operation behaves:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eanalyze_sampling\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, determines if \u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e, \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e, \u003ccode class=\"literal\"\u003esystem\u003c/code\u003e, \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e and \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e. \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e disables remote sampling, so all data are transferred and sampled locally. \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e performs remote sampling using the \u003ccode class=\"literal\"\u003erandom()\u003c/code\u003e function to choose returned rows, while \u003ccode class=\"literal\"\u003esystem\u003c/code\u003e and \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e rely on the built-in \u003ccode class=\"literal\"\u003eTABLESAMPLE\u003c/code\u003e methods of those names. \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e works on all remote server versions, while \u003ccode class=\"literal\"\u003eTABLESAMPLE\u003c/code\u003e is supported only since 9.5. \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e (the default) picks the recommended sampling method automatically; currently it means either \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e or \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e depending on the remote server version.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.4. Remote Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, only \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses using built-in operators and 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 be improved by sending such \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses for remote execution. This behavior can be controlled using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option is a comma-separated list of names of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extensions that are installed, in 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.\u003c/p\u003e\n\u003cp\u003eWhen using the \u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e option, \u003cspan class=\"emphasis\"\u003e\u003cem\u003eit is the user's responsibility\u003c/em\u003e\u003c/span\u003e that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efetch_size\u003c/code\u003e (\u003ccode class=\"type\"\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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. The default is \u003ccode class=\"literal\"\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e (\u003ccode class=\"type\"\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003e1\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eNote the actual number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e inserts at once depends on the number of columns and the provided \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e value. The batch is executed as a single query, and the libpq protocol (which \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e exceeds the limit, the \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e will be adjusted to avoid an error.\u003c/p\u003e\n\u003cp\u003eThis option also applies when copying into foreign tables. In that case the actual number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e command.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.5. Asynchronous Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e supports asynchronous execution, which runs multiple parts of an \u003ccode class=\"structname\"\u003eAppend\u003c/code\u003e node concurrently rather than serially to improve performance. This execution can be controlled using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003easync_capable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn order to ensure that the data being returned from a foreign server is consistent, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eAsynchronous execution is applied even when an \u003ccode class=\"structname\"\u003eAppend\u003c/code\u003e 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 \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e, 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.6. Transaction Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eAs described in the Transaction Management section, in \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e transactions are managed by creating corresponding remote transactions, and subtransactions are managed by creating corresponding remote subtransactions. When multiple remote transactions are involved in the current local transaction, by default \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote transactions serially when the local transaction is committed or aborted. When multiple remote subtransactions are involved in the current local subtransaction, by default \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eparallel_commit\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eparallel_abort\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eIf multiple foreign servers with these options enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed or aborted in parallel across those foreign servers when the local transaction is committed or aborted.\u003c/p\u003e\n\u003cp\u003eWhen these options are enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed or aborted.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.7. Updatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e are assumed to be updatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eupdatable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be modified using \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e and \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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 that the \u003ccode class=\"literal\"\u003einformation_schema\u003c/code\u003e views will report a \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.8. Truncatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e are assumed to be truncatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003etruncatable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be truncated using the \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.9. Importing Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e is able to import foreign table definitions using \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. This command creates foreign table definitions on the local server that match tables or views present on the remote server. If the remote tables to be imported have columns of user-defined data types, the local server must have compatible types of the same names.\u003c/p\u003e\n\u003cp\u003eImporting behavior can be customized with the following options (given in the \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command):\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_collate\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eCOLLATE\u003c/code\u003e options are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e. You might 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. 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.\u003c/p\u003e\n\u003cp\u003eEven when this parameter is set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, importing columns whose collation is the remote server's default can be risky. They will be imported with \u003ccode class=\"literal\"\u003eCOLLATE \"default\"\u003c/code\u003e, which will select the local server's default collation, which could be different.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_default\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; \u003ccode class=\"function\"\u003enextval()\u003c/code\u003e is a common source of problems. The \u003ccode class=\"command\"\u003eIMPORT\u003c/code\u003e will fail altogether if an imported default expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_generated\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eGENERATED\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e. The \u003ccode class=\"command\"\u003eIMPORT\u003c/code\u003e will fail altogether if an imported generated expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_not_null\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eNOT NULL\u003c/code\u003e constraints are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eNote that constraints other than \u003ccode class=\"literal\"\u003eNOT NULL\u003c/code\u003e will never be imported from the remote tables. Although \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e does support check constraints on foreign tables, there is no provision for importing them automatically, because of the risk that a constraint expression could evaluate differently on the local and remote servers. Any such inconsistency in the behavior of a check constraint could lead to hard-to-detect errors in query optimization. So if you wish to import check constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of check constraints on foreign tables, see \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eTables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in \u003ccode class=\"literal\"\u003eLIMIT TO\u003c/code\u003e clause. Otherwise they are automatically excluded from \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. 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 creating extra objects.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.10. Connection Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, all connections that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes to foreign servers are kept open in the local session for re-use.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is \u003ccode class=\"literal\"\u003eon\u003c/code\u003e. If set to \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e, all connections to this foreign server will be discarded at the end of each transaction.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003euse_scram_passthrough\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs.\u003c/p\u003e\n\u003cp\u003eTo use SCRAM pass-through authentication:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe remote server must request the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e authentication method; otherwise, the connection will fail.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe remote server can be of any PostgreSQL version that supports SCRAM. Support for \u003ccode class=\"literal\"\u003euse_scram_passthrough\u003c/code\u003e is only required on the client side (FDW side).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe user mapping password is not used.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe server running \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to authenticate on the foreign server (same salt and iterations, not merely the same password).\u003c/p\u003e\n\u003cp\u003eAs a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003epass-through\u003c/span\u003e”\u003c/span\u003e: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.2. Functions \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_get_connections( IN check_conn boolean DEFAULT false, OUT server_name text, OUT user_name text, OUT valid boolean, OUT used_in_xact boolean, OUT closed boolean, OUT remote_backend_pid int4) returns setof record\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function returns information about all open connections postgres_fdw has established from the local session to foreign servers. If there are no open connections, no records are returned.\u003c/p\u003e\n\u003cp\u003eIf \u003ccode class=\"literal\"\u003echeck_conn\u003c/code\u003e is set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, the function checks the status of each connection and shows the result in the \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e column. This feature is currently available only on systems that support the non-standard \u003ccode class=\"symbol\"\u003ePOLLRDHUP\u003c/code\u003e extension to the \u003ccode class=\"symbol\"\u003epoll\u003c/code\u003e system call, including Linux. This is useful to check if all connections used within a transaction are still open. If any connections are closed, the transaction cannot be committed successfully, so it is better to roll back as soon as a closed connection is detected, rather than continuing to the end. Users can roll back the transaction immediately if the function reports connections where both \u003ccode class=\"literal\"\u003eused_in_xact\u003c/code\u003e and \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e are \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExample usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT * FROM postgres_fdw_get_connections(true);\n server_name | user_name | valid | used_in_xact | closed | remote_backend_pid\n-------------+-----------+-------+--------------+-----------------------------\n loopback1   | postgres  | t     | t            | f      |            1353340\n loopback2   | public    | t     | t            | f      |            1353120\n loopback3   |           | f     | t            | f      |            1353156\n\u003c/pre\u003e\n\u003cp\u003eThe output columns are described in \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table F.28. postgres_fdw_get_connections Output Columns\"\u003eTable F.28\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable F.28. \u003ccode class=\"function\"\u003epostgres_fdw_get_connections\u003c/code\u003e Output Columns\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eColumn\u003c/th\u003e\n\u003cth\u003eType\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eserver_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eThe foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003euser_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eName of the local user mapped to the foreign server of this connection, or \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e if a public mapping is used. If the user mapping is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003evalid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eFalse if this connection is invalid, meaning it is used in the current transaction, but its foreign server or user mapping has been changed or dropped. The invalid connection will be closed at the end of the transaction. True is returned otherwise.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eused_in_xact\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is used in the current transaction.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eclosed\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is closed, false otherwise. \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e is returned if \u003ccode class=\"literal\"\u003echeck_conn\u003c/code\u003e is set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e or if the connection status check is not available on this platform.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eremote_backend_pid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eint4\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e), this still shows the process ID of the terminated backend.\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_disconnect(server_name text) returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards the open connections that are established by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If no foreign server with the given name is found, an error is reported. Example usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_disconnect_all() returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards all the open connections that are established by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e from the local session to foreign servers. If the connections are used in the current local transaction, they are not disconnected and warning messages are reported. This function returns \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. Example usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.3. Connection Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server during the first query that uses a foreign table 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 \u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e option for a foreign server. If multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.\u003c/p\u003e\n\u003cp\u003eWhen changing the definition of or removing a foreign server or 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.\u003c/p\u003e\n\u003cp\u003eOnce a connection to a foreign server has been established, it's by default kept until the local or corresponding remote session exits. To disconnect a connection explicitly, \u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e option for a foreign server may be disabled, or \u003ccode class=\"function\"\u003epostgres_fdw_disconnect\u003c/code\u003e and \u003ccode class=\"function\"\u003epostgres_fdw_disconnect_all\u003c/code\u003e functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.4. Transaction Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eDuring a query that references any remote tables on a foreign server, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eThe remote transaction uses \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e isolation level when the local transaction has \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e isolation level; otherwise it uses \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e 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 transaction uses \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e or \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e isolation level, but it might be surprising for a \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e local transaction. A future \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e release might modify these rules.\u003c/p\u003e\n\u003cp\u003eNote that it is currently not supported by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to prepare the remote transaction for two-phase commit.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.5. Remote Query Optimization \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses to the remote server for execution, and by not retrieving table columns that are not needed for the current query. To reduce the risk of misexecution of queries, \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses are not sent to the remote server unless they use only data types, operators, and functions that are built-in or belong to an extension that's listed in the foreign server's \u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e option. Operators and functions in such clauses must be \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e as well. For an \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e or \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e query, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e attempts to optimize the query execution by sending the whole query to the remote server if there are no query \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses that cannot be sent to the remote server, no local joins for the query, no row-level local \u003ccode class=\"literal\"\u003eBEFORE\u003c/code\u003e or \u003ccode class=\"literal\"\u003eAFTER\u003c/code\u003e triggers or stored generated columns on the target table, and no \u003ccode class=\"literal\"\u003eCHECK OPTION\u003c/code\u003e constraints from parent views. In \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, expressions to assign to target columns must use only built-in data types, \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e operators, or \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e functions, to reduce the risk of misexecution of the query.\u003c/p\u003e\n\u003cp\u003eWhen \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e encounters a join between foreign tables on 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 are subject to different user mappings. While sending the \u003ccode class=\"literal\"\u003eJOIN\u003c/code\u003e clauses, it takes the same precautions as mentioned above for the \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses.\u003c/p\u003e\n\u003cp\u003eThe query that is actually sent to the remote server for execution can be examined using \u003ccode class=\"command\"\u003eEXPLAIN VERBOSE\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.6. Remote Query Execution Environment \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eIn the remote sessions opened by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e, the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-SEARCH-PATH\"\u003esearch_path\u003c/a\u003e parameter is set to just \u003ccode class=\"literal\"\u003epg_catalog\u003c/code\u003e, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e itself, because it always 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 functions, or else attach \u003ccode class=\"literal\"\u003eSET search_path\u003c/code\u003e options (see \u003ca class=\"xref\" href=\"/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e) to such functions to establish their expected search path environment.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e likewise establishes remote session settings for various parameters:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-TIMEZONE\"\u003eTimeZone\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003eUTC\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-DATESTYLE\"\u003eDateStyle\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003eISO\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-INTERVALSTYLE\"\u003eIntervalStyle\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003epostgres\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\"\u003eextra_float_digits\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003e3\u003c/code\u003e for remote servers 9.0 and newer and is set to \u003ccode class=\"literal\"\u003e2\u003c/code\u003e for older versions\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThese are less likely to be problematic than \u003ccode class=\"varname\"\u003esearch_path\u003c/code\u003e, but can be handled with function \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e options if the need arises.\u003c/p\u003e\n\u003cp\u003eIt is \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to malfunction.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.7. Cross-Version Compatibility \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e can be used with remote servers dating back to \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 8.3. Read-only capability is available back to 8.1.\u003c/p\u003e\n\u003cp\u003eA limitation however is that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clause for a foreign table. Thus, a built-in function that was added since the remote server's release might be sent to it for execution, resulting in \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003efunction does not exist\u003c/span\u003e”\u003c/span\u003e or a similar error. This type of failure can be worked around by rewriting the query, for example by embedding the foreign table reference in a sub-\u003ccode class=\"literal\"\u003eSELECT\u003c/code\u003e with \u003ccode class=\"literal\"\u003eOFFSET 0\u003c/code\u003e as an optimization fence, and placing the problematic function or operator outside the sub-\u003ccode class=\"literal\"\u003eSELECT\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAnother limitation is that when executing \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e statements with an \u003ccode class=\"literal\"\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause on a foreign table, the remote server must be running \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.5 or later, as earlier versions do not support this feature.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.8. Wait Events \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e can report the following wait events under the wait event type \u003ccode class=\"literal\"\u003eExtension\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwCleanupResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting for transaction abort on remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwConnect\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to establish a connection to a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwGetResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to receive the results of a query from a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.9. Configuration Parameters \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt id=\"GUC-PGFDW-APPLICATION-NAME\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e) \u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eSpecifies a value for \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\"\u003eapplication_name\u003c/a\u003e configuration parameter used when \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server. This overrides \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e in a foreign server, note that it will be truncated to less than \u003ccode class=\"symbol\"\u003eNAMEDATALEN\u003c/code\u003e characters. Anything other than printable ASCII characters are replaced with \u003ca class=\"link\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2. String Constants with C-Style Escapes\"\u003eC-style hexadecimal escapes\u003c/a\u003e. See \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\"\u003eapplication_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003e%\u003c/code\u003e characters begin \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e 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 \u003ccode class=\"literal\"\u003e%\u003c/code\u003e and before the option, for alignment and padding.\u003c/p\u003e\n\u003cdiv class=\"informaltable\"\u003e\n\u003ctable class=\"informaltable\"\u003e\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eEscape\u003c/th\u003e\n\u003cth\u003eEffect\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%a\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eApplication name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%c\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eSession ID on local server (see \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\"\u003elog_line_prefix\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%C\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eCluster name on local server (see \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-CLUSTER-NAME\"\u003ecluster_name\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%u\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eUser name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%d\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eDatabase name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%p\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of backend on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%%\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eLiteral %\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003cp\u003eFor example, suppose user \u003ccode class=\"literal\"\u003elocal_user\u003c/code\u003e establishes a connection from database \u003ccode class=\"literal\"\u003elocal_db\u003c/code\u003e to \u003ccode class=\"literal\"\u003eforeign_db\u003c/code\u003e as user \u003ccode class=\"literal\"\u003eforeign_user\u003c/code\u003e, the setting \u003ccode class=\"literal\"\u003e'db=%d, user=%u'\u003c/code\u003e is replaced with \u003ccode class=\"literal\"\u003e'db=local_db, user=local_user'\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.10. Examples \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eHere is an example of creating a foreign table with \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e. First install the extension:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE EXTENSION postgres_fdw;\n\u003c/pre\u003e\n\u003cp\u003eThen create a foreign server using \u003ca class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e. In this example we wish to connect to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server on host \u003ccode class=\"literal\"\u003e192.83.123.89\u003c/code\u003e listening on port \u003ccode class=\"literal\"\u003e5432\u003c/code\u003e. The database to which the connection is made is named \u003ccode class=\"literal\"\u003eforeign_db\u003c/code\u003e on the remote server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n\u003c/pre\u003e\n\u003cp\u003eA user mapping, defined with \u003ca class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, is needed as well to identify the role that will be used on the remote server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n\u003c/pre\u003e\n\u003cp\u003eNow it is possible to create a foreign table with \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e. In this example we wish to access the table named \u003ccode class=\"structname\"\u003esome_schema.some_table\u003c/code\u003e on the remote server. The local name for it will be \u003ccode class=\"structname\"\u003eforeign_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN TABLE foreign_table (\n        id integer NOT NULL,\n        data text\n)\n        SERVER foreign_server\n        OPTIONS (schema_name 'some_schema', table_name 'some_table');\n\u003c/pre\u003e\n\u003cp\u003eIt's essential that the data types and other properties of the columns declared in \u003ccode class=\"command\"\u003eCREATE FOREIGN TABLE\u003c/code\u003e match the actual remote table. Column names must match as well, unless you attach \u003ccode class=\"literal\"\u003ecolumn_name\u003c/code\u003e options to the individual columns to show how they are named in the remote table. In many cases, use of \u003ca class=\"link\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e\u003c/a\u003e is preferable to constructing foreign table definitions manually.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.11. Author \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eShigeru Hanada \u003ccode class=\"email\"\u003e\u0026lt;\u003ca class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\"\u003eshigeru.hanada@gmail.com\u003c/a\u003e\u0026gt;\u003c/code\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","manual_path":"/docs/18/postgres-fdw.html","related":[{"label":"Foreign-data wrapper catalog","url":"/wiki/catalog/pg_foreign_data_wrapper/?v=18"},{"label":"Existing extension catalogue identity","url":"/e/postgres_fdw/"},{"label":"Foreign Scan plan node","url":"/wiki/plan/foreign-scan/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.","The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."],"title":"Interface and capability boundaries"},{"paragraphs":["postgres_fdw supports asynchronous execution, which runs multiple parts of an Append node concurrently rather than serially to improve performance. This execution can be controlled using the following option:"],"title":"Asynchronous Execution Options"},{"paragraphs":["As described in the Transaction Management section, in postgres_fdw transactions are managed by creating corresponding remote transactions, and subtransactions are managed by creating corresponding remote subtransactions. When multiple remote transactions are involved in the current local transaction, by default postgres_fdw commits or aborts those remote transactions serially when the local transaction is committed or aborted. When multiple remote subtransactions are involved in the current local subtransaction, by default postgres_fdw commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:","If multiple foreign servers with these options enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed or aborted in parallel across those foreign servers when the local transaction is committed or aborted.","When these options are enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed or aborted."],"title":"Transaction Management Options"},{"paragraphs":["During a query that references any remote tables on a foreign server, postgres_fdw 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.","The remote transaction uses SERIALIZABLE isolation level when the local transaction has SERIALIZABLE isolation level; otherwise it uses REPEATABLE READ 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 transaction uses SERIALIZABLE or REPEATABLE READ isolation level, but it might be surprising for a READ COMMITTED local transaction. A future PostgreSQL release might modify these rules.","Note that it is currently not supported by postgres_fdw to prepare the remote transaction for two-phase commit."],"title":"Transaction Management"},{"paragraphs":["postgres_fdw attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query WHERE clauses to the remote server for execution, and by not retrieving table columns that are not needed for the current query. To reduce the risk of misexecution of queries, WHERE clauses are not sent to the remote server unless they use only data types, operators, and functions that are built-in or belong to an extension that's listed in the foreign server's extensions option. Operators and functions in such clauses must be IMMUTABLE as well. For an UPDATE or DELETE query, postgres_fdw attempts to optimize the query execution by sending the whole query to the remote server if there are no query WHERE clauses that cannot be sent to the remote server, no local joins for the query, no row-level local BEFORE or AFTER triggers or stored generated columns on the target table, and no CHECK OPTION constraints from parent views. In UPDATE , expressions to assign to target columns must use only built-in data types, IMMUTABLE operators, or IMMUTABLE functions, to reduce the risk of misexecution of the query.","When postgres_fdw encounters a join between foreign tables on 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 are subject to different user mappings. While sending the JOIN clauses, it takes the same precautions as mentioned above for the WHERE clauses.","The query that is actually sent to the remote server for execution can be examined using EXPLAIN VERBOSE ."],"title":"Remote Query Optimization"},{"paragraphs":["postgres_fdw can be used with remote servers dating back to PostgreSQL 8.3. Read-only capability is available back to 8.1.","A limitation however is that postgres_fdw generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a WHERE clause for a foreign table. Thus, a built-in function that was added since the remote server's release might be sent to it for execution, resulting in “ function does not exist ” or a similar error. This type of failure can be worked around by rewriting the query, for example by embedding the foreign table reference in a sub- SELECT with OFFSET 0 as an optimization fence, and placing the problematic function or operator outside the sub- SELECT .","Another limitation is that when executing INSERT statements with an ON CONFLICT DO NOTHING clause on a foreign table, the remote server must be running PostgreSQL 9.5 or later, as earlier versions do not support this feature."],"title":"Cross-Version Compatibility"},{"code":"{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine-\u003eGetForeignRelSize = postgresGetForeignRelSize;\n\troutine-\u003eGetForeignPaths = postgresGetForeignPaths;\n\troutine-\u003eGetForeignPlan = postgresGetForeignPlan;\n\troutine-\u003eBeginForeignScan = postgresBeginForeignScan;\n\troutine-\u003eIterateForeignScan = postgresIterateForeignScan;\n\troutine-\u003eReScanForeignScan = postgresReScanForeignScan;\n\troutine-\u003eEndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine-\u003eAddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine-\u003ePlanForeignModify = postgresPlanForeignModify;\n\troutine-\u003eBeginForeignModify = postgresBeginForeignModify;\n\troutine-\u003eExecForeignInsert = postgresExecForeignInsert;\n\troutine-\u003eExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine-\u003eGetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine-\u003eExecForeignUpdate = postgresExecForeignUpdate;\n\troutine-\u003eExecForeignDelete = postgresExecForeignDelete;\n\troutine-\u003eEndForeignModify = postgresEndForeignModify;\n\troutine-\u003eBeginForeignInsert = postgresBeginForeignInsert;\n\troutine-\u003eEndForeignInsert = postgresEndForeignInsert;\n\troutine-\u003eIsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine-\u003ePlanDirectModify = postgresPlanDirectModify;\n\troutine-\u003eBeginDirectModify = postgresBeginDirectModify;\n\troutine-\u003eIterateDirectModify = postgresIterateDirectModify;\n\troutine-\u003eEndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine-\u003eRecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine-\u003eExplainForeignScan = postgresExplainForeignScan;\n\troutine-\u003eExplainForeignModify = postgresExplainForeignModify;\n\troutine-\u003eExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine-\u003eExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine-\u003eAnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine-\u003eImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine-\u003eGetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine-\u003eGetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine-\u003eIsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine-\u003eForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine-\u003eForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine-\u003eForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}","title":"Registered implementation in core source"}],"sources":[{"label":"PostgreSQL 18 English manual","path":"postgres-fdw.html","sha256":"a7833ebac1e9581de25695443eaec67d16d32ef33107783cdfb940fefa5f66a3","url":"/docs/18/postgres-fdw.html"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"contrib/postgres_fdw/postgres_fdw.c:557","line":557,"path":"contrib/postgres_fdw/postgres_fdw.c","sha256":"5f61f89fc1f9d67a204c47fd993db575b2d619449e5238b536b9fb1877037db6","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"tables":[{"columns":[{"key":"feature","label":"Interface operation"},{"key":"state","label":"Source observation"},{"key":"callback","label":"Callback"},{"key":"implementation","label":"Implementation"}],"key":"callbacks","rows":[{"callback":"IterateForeignScan","feature":"Scan rows","implementation":"postgresIterateForeignScan","state":"Handler registered; conditions apply"},{"callback":"ExecForeignInsert","feature":"INSERT","implementation":"postgresExecForeignInsert","state":"Handler registered; conditions apply"},{"callback":"ExecForeignUpdate","feature":"UPDATE","implementation":"postgresExecForeignUpdate","state":"Handler registered; conditions apply"},{"callback":"ExecForeignDelete","feature":"DELETE","implementation":"postgresExecForeignDelete","state":"Handler registered; conditions apply"},{"callback":"ExecForeignTruncate","feature":"TRUNCATE","implementation":"postgresExecForeignTruncate","state":"Handler registered; conditions apply"},{"callback":"GetForeignJoinPaths","feature":"Join path pushdown","implementation":"postgresGetForeignJoinPaths","state":"Handler registered; conditions apply"},{"callback":"GetForeignUpperPaths","feature":"Upper paths, including aggregation","implementation":"postgresGetForeignUpperPaths","state":"Handler registered; conditions apply"},{"callback":"ExecForeignBatchInsert","feature":"Batch insert","implementation":"postgresExecForeignBatchInsert","state":"Handler registered; conditions apply"},{"callback":"ForeignAsyncRequest","feature":"Asynchronous append execution","implementation":"postgresForeignAsyncRequest","state":"Handler registered; conditions apply"},{"callback":"ImportForeignSchema","feature":"Import schema","implementation":"postgresImportForeignSchema","state":"Handler registered; conditions apply"}],"title":"Registered interface handlers"},{"columns":[{"key":"name","label":"Option"},{"key":"definition","label":"Same-version definition"}],"key":"options","rows":[{"definition":"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.","name":"schema_name"},{"definition":"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.","name":"table_name"},{"definition":"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.","name":"column_name"},{"definition":"This option, which can be specified for a foreign table or a foreign server, controls whether postgres_fdw issues remote EXPLAIN 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 false .","name":"use_remote_estimate"},{"definition":"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. The default value is 100 .","name":"fdw_startup_cost"},{"definition":"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 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 0.2 .","name":"fdw_tuple_cost"},{"definition":"This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are off , random , system , bernoulli and auto . off disables remote sampling, so all data are transferred and sampled locally. random performs remote sampling using the random() function to choose returned rows, while system and bernoulli rely on the built-in TABLESAMPLE methods of those names. random works on all remote server versions, while TABLESAMPLE is supported only since 9.5. auto (the default) picks the recommended sampling method automatically; currently it means either bernoulli or random depending on the remote server version.","name":"analyze_sampling"},{"definition":"This option is a comma-separated list of names of PostgreSQL extensions that are installed, in 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. When using the extensions option, it is the user's responsibility that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.","name":"extensions"},{"definition":"This option specifies the number of rows postgres_fdw 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. The default is 100 .","name":"fetch_size"},{"definition":"This option specifies the number of rows postgres_fdw 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 1 . Note the actual number of rows postgres_fdw inserts at once depends on the number of columns and the provided batch_size value. The batch is executed as a single query, and the libpq protocol (which postgres_fdw uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * batch_size exceeds the limit, the batch_size will be adjusted to avoid an error. This option also applies when copying into foreign tables. In that case the actual number of rows postgres_fdw copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the COPY command.","name":"batch_size"},{"definition":"This option controls whether postgres_fdw 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 false . In order to ensure that the data being returned from a foreign server is consistent, postgres_fdw 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. Asynchronous execution is applied even when an Append 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 postgres_fdw , 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.","name":"async_capable"},{"definition":"This option controls whether postgres_fdw commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_commit"},{"definition":"This option controls whether postgres_fdw aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_abort"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be modified using INSERT , UPDATE and DELETE commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is true . 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 that the information_schema views will report a postgres_fdw foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.","name":"updatable"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be truncated using the TRUNCATE 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 true . 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.","name":"truncatable"},{"definition":"This option controls whether column COLLATE options are included in the definitions of foreign tables imported from a foreign server. The default is true . You might 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. 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. Even when this parameter is set to true , importing columns whose collation is the remote server's default can be risky. They will be imported with COLLATE \"default\" , which will select the local server's default collation, which could be different.","name":"import_collate"},{"definition":"This option controls whether column DEFAULT expressions are included in the definitions of foreign tables imported from a foreign server. The default is false . If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; nextval() is a common source of problems. The IMPORT will fail altogether if an imported default expression uses a function or operator that does not exist locally.","name":"import_default"},{"definition":"This option controls whether column GENERATED expressions are included in the definitions of foreign tables imported from a foreign server. The default is true . The IMPORT will fail altogether if an imported generated expression uses a function or operator that does not exist locally.","name":"import_generated"},{"definition":"This option controls whether column NOT NULL constraints are included in the definitions of foreign tables imported from a foreign server. The default is true .","name":"import_not_null"},{"definition":"This option controls whether postgres_fdw keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is on . If set to off , all connections to this foreign server will be discarded at the end of each transaction.","name":"keep_connections"},{"definition":"This option controls whether postgres_fdw will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, postgres_fdw uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs. To use SCRAM pass-through authentication: The remote server must request the scram-sha-256 authentication method; otherwise, the connection will fail. The remote server can be of any PostgreSQL version that supports SCRAM. Support for use_scram_passthrough is only required on the client side (FDW side). The user mapping password is not used. The server running postgres_fdw and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on postgres_fdw to authenticate on the foreign server (same salt and iterations, not merely the same password). As a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved. The current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence “ pass-through ” : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.","name":"use_scram_passthrough"}],"title":"Documented options"}]},"ManualEvidence":{"manual_path":"/docs/18/postgres-fdw.html","release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"label":"PostgreSQL 18 English manual","path":"postgres-fdw.html","sha256":"a7833ebac1e9581de25695443eaec67d16d32ef33107783cdfb940fefa5f66a3","url":"/docs/18/postgres-fdw.html"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"contrib/postgres_fdw/postgres_fdw.c:557","line":557,"path":"contrib/postgres_fdw/postgres_fdw.c","sha256":"5f61f89fc1f9d67a204c47fd993db575b2d619449e5238b536b9fb1877037db6","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"fdw","Key":"postgres_fdw","SourceDatabase":"center","Version":"18","Locale":"en","Title":"postgres_fdw","Summary":"Accesses tables in remote PostgreSQL servers through foreign tables.","BodyHTML":"\u003cdiv id=\"POSTGRES-FDW\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003eF.38. postgres_fdw — access data stored in external \u003cspan\u003ePostgreSQL\u003c/span\u003e servers \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode\u003epostgres_fdw\u003c/code\u003e module provides the foreign-data wrapper \u003ccode\u003epostgres_fdw\u003c/code\u003e, which can be used to access data stored in external \u003cspan\u003ePostgreSQL\u003c/span\u003e servers.\u003c/p\u003e\n\u003cp\u003eThe functionality provided by this module overlaps substantially with the functionality of the older \u003ca href=\"/docs/18/dblink.html\" rel=\"nofollow\"\u003edblink\u003c/a\u003e module. But \u003ccode\u003epostgres_fdw\u003c/code\u003e provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.\u003c/p\u003e\n\u003cp\u003eTo prepare for remote access using \u003ccode\u003epostgres_fdw\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cp\u003eInstall the \u003ccode\u003epostgres_fdw\u003c/code\u003e extension using \u003ca href=\"/docs/18/sql-createextension.html\" title=\"CREATE EXTENSION\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE EXTENSION\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCreate a foreign server object, using \u003ca href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e, to represent each remote database you want to connect to. Specify connection information, except \u003ccode\u003euser\u003c/code\u003e and \u003ccode\u003epassword\u003c/code\u003e, as options of the server object.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCreate a user mapping, using \u003ca href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as \u003ccode\u003euser\u003c/code\u003e and \u003ccode\u003epassword\u003c/code\u003e options of the user mapping.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eCreate a foreign table, using \u003ca href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e or \u003ca href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\" rel=\"nofollow\"\u003e\u003cspan\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e, 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\u0026#39;s, if you specify the correct remote names as options of the foreign table object.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003cp\u003eNow you need only \u003ccode\u003eSELECT\u003c/code\u003e from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using \u003ccode\u003eINSERT\u003c/code\u003e, \u003ccode\u003eUPDATE\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e, \u003ccode\u003eCOPY\u003c/code\u003e, or \u003ccode\u003eTRUNCATE\u003c/code\u003e. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)\u003c/p\u003e\n\u003cp\u003eNote that the \u003ccode\u003eONLY\u003c/code\u003e option specified in \u003ccode\u003eSELECT\u003c/code\u003e, \u003ccode\u003eUPDATE\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e or \u003ccode\u003eTRUNCATE\u003c/code\u003e has no effect when accessing or modifying the remote table.\u003c/p\u003e\n\u003cp\u003eNote that \u003ccode\u003epostgres_fdw\u003c/code\u003e currently lacks support for \u003ccode\u003eINSERT\u003c/code\u003e statements with an \u003ccode\u003eON CONFLICT DO UPDATE\u003c/code\u003e clause. However, the \u003ccode\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause is supported, provided a unique index inference specification is omitted. Note also that \u003ccode\u003epostgres_fdw\u003c/code\u003e supports row movement invoked by \u003ccode\u003eUPDATE\u003c/code\u003e 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 \u003ccode\u003eUPDATE\u003c/code\u003e target partition that will be updated elsewhere in the same command.\u003c/p\u003e\n\u003cp\u003eIt is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although \u003ccode\u003epostgres_fdw\u003c/code\u003e is currently rather forgiving about performing data type conversions at need, surprising semantic anomalies may arise when types or collations do not match, due to the remote server interpreting query conditions differently from the local server.\u003c/p\u003e\n\u003cp\u003eNote 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.\u003c/p\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.1. FDW Options of postgres_fdw \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-CONNECTION\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.1. Connection Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA foreign server using the \u003ccode\u003epostgres_fdw\u003c/code\u003e foreign data wrapper can have the same options that \u003cspan\u003elibpq\u003c/span\u003e accepts in connection strings, as described in \u003ca href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" rel=\"nofollow\"\u003eSection 32.1.2\u003c/a\u003e, except that these options are not allowed or have special handling:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003euser\u003c/code\u003e, \u003ccode\u003epassword\u003c/code\u003e and \u003ccode\u003esslpassword\u003c/code\u003e (specify these in a user mapping instead, or use a service file)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003eclient_encoding\u003c/code\u003e (this is automatically set from the local server encoding)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003eapplication_name\u003c/code\u003e - this may appear in \u003cspan\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and \u003ca href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\" rel=\"nofollow\"\u003epostgres_fdw.application_name\u003c/a\u003e. If both are present, \u003ccode\u003epostgres_fdw.application_name\u003c/code\u003e overrides the connection setting. Unlike \u003cspan\u003elibpq\u003c/span\u003e, \u003ccode\u003epostgres_fdw\u003c/code\u003e allows \u003ccode\u003eapplication_name\u003c/code\u003e to include \u003cspan\u003e“\u003cspan\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e. See \u003ca href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\" rel=\"nofollow\"\u003epostgres_fdw.application_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003efallback_application_name\u003c/code\u003e (always set to \u003ccode\u003epostgres_fdw\u003c/code\u003e)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ccode\u003esslkey\u003c/code\u003e and \u003ccode\u003esslcert\u003c/code\u003e - these may appear in \u003cspan\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eOnly superusers may create or modify user mappings with the \u003ccode\u003esslcert\u003c/code\u003e or \u003ccode\u003esslkey\u003c/code\u003e settings.\u003c/p\u003e\n\u003cp\u003eNon-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the \u003ccode\u003epassword\u003c/code\u003e option for user mappings belonging to non-superusers where password authentication is required.\u003c/p\u003e\n\u003cp\u003eA superuser may override this check on a per-user-mapping basis by setting the user mapping option \u003ccode\u003epassword_required \u0026#39;false\u0026#39;\u003c/code\u003e, e.g.,\u003c/p\u003e\n\u003cpre\u003eALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required \u0026#39;false\u0026#39;);\n\u003c/pre\u003e\n\u003cp\u003eTo 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.\u003c/p\u003e\n\u003cp\u003eCare 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\u0026#39;t set \u003ccode\u003epassword_required=false\u003c/code\u003e on the \u003ccode\u003epublic\u003c/code\u003e role. Keep in mind that the mapped user can potentially use any client certificates, \u003ccode\u003e.pgpass\u003c/code\u003e, \u003ccode\u003e.pg_service.conf\u003c/code\u003e etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see \u003ca href=\"/docs/18/libpq-pgpass.html\" rel=\"nofollow\"\u003eSection 32.16\u003c/a\u003e.) They can also use any trust relationship granted by authentication modes like \u003ccode\u003epeer\u003c/code\u003e or \u003ccode\u003eident\u003c/code\u003e authentication.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.2. Object Name Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThese options can be used to control the names used in SQL statements sent to the remote \u003cspan\u003ePostgreSQL\u003c/span\u003e server. These options are needed when a foreign table is created with names different from the underlying remote table\u0026#39;s names.\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eschema_name\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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\u0026#39;s schema is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003etable_name\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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\u0026#39;s name is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ecolumn_name\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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\u0026#39;s name is used.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.3. Cost Estimation Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e retrieves remote data by executing queries 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. So \u003ccode\u003epostgres_fdw\u003c/code\u003e provides the following options to control how cost estimation is done:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003euse_remote_estimate\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e issues remote \u003ccode\u003eEXPLAIN\u003c/code\u003e 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 \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003efdw_startup_cost\u003c/code\u003e (\u003ccode\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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. The default value is \u003ccode\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003efdw_tuple_cost\u003c/code\u003e (\u003ccode\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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 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 \u003ccode\u003e0.2\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eWhen \u003ccode\u003euse_remote_estimate\u003c/code\u003e is true, \u003ccode\u003epostgres_fdw\u003c/code\u003e obtains row count and cost estimates from the remote server and then adds \u003ccode\u003efdw_startup_cost\u003c/code\u003e and \u003ccode\u003efdw_tuple_cost\u003c/code\u003e to the cost estimates. When \u003ccode\u003euse_remote_estimate\u003c/code\u003e is false, \u003ccode\u003epostgres_fdw\u003c/code\u003e performs local row count and cost estimation and then adds \u003ccode\u003efdw_startup_cost\u003c/code\u003e and \u003ccode\u003efdw_tuple_cost\u003c/code\u003e to the cost estimates. This local estimation is unlikely to be very accurate unless local copies of the remote table\u0026#39;s statistics are available. Running \u003ca href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\" rel=\"nofollow\"\u003e\u003cspan\u003eANALYZE\u003c/span\u003e\u003c/a\u003e on the foreign table is the way to update 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.\u003c/p\u003e\n\u003cp\u003eThe following option controls how such an \u003ccode\u003eANALYZE\u003c/code\u003e operation behaves:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eanalyze_sampling\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, determines if \u003ccode\u003eANALYZE\u003c/code\u003e on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are \u003ccode\u003eoff\u003c/code\u003e, \u003ccode\u003erandom\u003c/code\u003e, \u003ccode\u003esystem\u003c/code\u003e, \u003ccode\u003ebernoulli\u003c/code\u003e and \u003ccode\u003eauto\u003c/code\u003e. \u003ccode\u003eoff\u003c/code\u003e disables remote sampling, so all data are transferred and sampled locally. \u003ccode\u003erandom\u003c/code\u003e performs remote sampling using the \u003ccode\u003erandom()\u003c/code\u003e function to choose returned rows, while \u003ccode\u003esystem\u003c/code\u003e and \u003ccode\u003ebernoulli\u003c/code\u003e rely on the built-in \u003ccode\u003eTABLESAMPLE\u003c/code\u003e methods of those names. \u003ccode\u003erandom\u003c/code\u003e works on all remote server versions, while \u003ccode\u003eTABLESAMPLE\u003c/code\u003e is supported only since 9.5. \u003ccode\u003eauto\u003c/code\u003e (the default) picks the recommended sampling method automatically; currently it means either \u003ccode\u003ebernoulli\u003c/code\u003e or \u003ccode\u003erandom\u003c/code\u003e depending on the remote server version.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.4. Remote Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, only \u003ccode\u003eWHERE\u003c/code\u003e clauses using built-in operators and 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 be improved by sending such \u003ccode\u003eWHERE\u003c/code\u003e clauses for remote execution. This behavior can be controlled using the following option:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eextensions\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option is a comma-separated list of names of \u003cspan\u003ePostgreSQL\u003c/span\u003e extensions that are installed, in 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.\u003c/p\u003e\n\u003cp\u003eWhen using the \u003ccode\u003eextensions\u003c/code\u003e option, \u003cspan\u003e\u003cem\u003eit is the user\u0026#39;s responsibility\u003c/em\u003e\u003c/span\u003e that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003efetch_size\u003c/code\u003e (\u003ccode\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode\u003epostgres_fdw\u003c/code\u003e 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. The default is \u003ccode\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ebatch_size\u003c/code\u003e (\u003ccode\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode\u003e1\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eNote the actual number of rows \u003ccode\u003epostgres_fdw\u003c/code\u003e inserts at once depends on the number of columns and the provided \u003ccode\u003ebatch_size\u003c/code\u003e value. The batch is executed as a single query, and the libpq protocol (which \u003ccode\u003epostgres_fdw\u003c/code\u003e uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * \u003ccode\u003ebatch_size\u003c/code\u003e exceeds the limit, the \u003ccode\u003ebatch_size\u003c/code\u003e will be adjusted to avoid an error.\u003c/p\u003e\n\u003cp\u003eThis option also applies when copying into foreign tables. In that case the actual number of rows \u003ccode\u003epostgres_fdw\u003c/code\u003e copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the \u003ccode\u003eCOPY\u003c/code\u003e command.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.5. Asynchronous Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e supports asynchronous execution, which runs multiple parts of an \u003ccode\u003eAppend\u003c/code\u003e node concurrently rather than serially to improve performance. This execution can be controlled using the following option:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003easync_capable\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn order to ensure that the data being returned from a foreign server is consistent, \u003ccode\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eAsynchronous execution is applied even when an \u003ccode\u003eAppend\u003c/code\u003e 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 \u003ccode\u003epostgres_fdw\u003c/code\u003e, 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.6. Transaction Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eAs described in the Transaction Management section, in \u003ccode\u003epostgres_fdw\u003c/code\u003e transactions are managed by creating corresponding remote transactions, and subtransactions are managed by creating corresponding remote subtransactions. When multiple remote transactions are involved in the current local transaction, by default \u003ccode\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote transactions serially when the local transaction is committed or aborted. When multiple remote subtransactions are involved in the current local subtransaction, by default \u003ccode\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eparallel_commit\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eparallel_abort\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eIf multiple foreign servers with these options enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed or aborted in parallel across those foreign servers when the local transaction is committed or aborted.\u003c/p\u003e\n\u003cp\u003eWhen these options are enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed or aborted.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.7. Updatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode\u003epostgres_fdw\u003c/code\u003e are assumed to be updatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eupdatable\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be modified using \u003ccode\u003eINSERT\u003c/code\u003e, \u003ccode\u003eUPDATE\u003c/code\u003e and \u003ccode\u003eDELETE\u003c/code\u003e commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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 that the \u003ccode\u003einformation_schema\u003c/code\u003e views will report a \u003ccode\u003epostgres_fdw\u003c/code\u003e foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.8. Truncatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode\u003epostgres_fdw\u003c/code\u003e are assumed to be truncatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003etruncatable\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be truncated using the \u003ccode\u003eTRUNCATE\u003c/code\u003e 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 \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-IMPORTING\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.9. Importing Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e is able to import foreign table definitions using \u003ca href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\" rel=\"nofollow\"\u003e\u003cspan\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. This command creates foreign table definitions on the local server that match tables or views present on the remote server. If the remote tables to be imported have columns of user-defined data types, the local server must have compatible types of the same names.\u003c/p\u003e\n\u003cp\u003eImporting behavior can be customized with the following options (given in the \u003ccode\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command):\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eimport_collate\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode\u003eCOLLATE\u003c/code\u003e options are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode\u003etrue\u003c/code\u003e. You might 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\u0026#39;s running on a different operating system. If you do so, however, there is a very severe risk that the imported table columns\u0026#39; collations will not match the underlying data, resulting in anomalous query behavior.\u003c/p\u003e\n\u003cp\u003eEven when this parameter is set to \u003ccode\u003etrue\u003c/code\u003e, importing columns whose collation is the remote server\u0026#39;s default can be risky. They will be imported with \u003ccode\u003eCOLLATE \u0026#34;default\u0026#34;\u003c/code\u003e, which will select the local server\u0026#39;s default collation, which could be different.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eimport_default\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode\u003eDEFAULT\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode\u003efalse\u003c/code\u003e. If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; \u003ccode\u003enextval()\u003c/code\u003e is a common source of problems. The \u003ccode\u003eIMPORT\u003c/code\u003e will fail altogether if an imported default expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eimport_generated\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode\u003eGENERATED\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode\u003etrue\u003c/code\u003e. The \u003ccode\u003eIMPORT\u003c/code\u003e will fail altogether if an imported generated expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003eimport_not_null\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode\u003eNOT NULL\u003c/code\u003e constraints are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eNote that constraints other than \u003ccode\u003eNOT NULL\u003c/code\u003e will never be imported from the remote tables. Although \u003cspan\u003ePostgreSQL\u003c/span\u003e does support check constraints on foreign tables, there is no provision for importing them automatically, because of the risk that a constraint expression could evaluate differently on the local and remote servers. Any such inconsistency in the behavior of a check constraint could lead to hard-to-detect errors in query optimization. So if you wish to import check constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of check constraints on foreign tables, see \u003ca href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eTables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in \u003ccode\u003eLIMIT TO\u003c/code\u003e clause. Otherwise they are automatically excluded from \u003ca href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\" rel=\"nofollow\"\u003e\u003cspan\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. 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 creating extra objects.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4\u003eF.38.1.10. Connection Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, all connections that \u003ccode\u003epostgres_fdw\u003c/code\u003e establishes to foreign servers are kept open in the local session for re-use.\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"\u003e\u003cspan\u003e\u003ccode\u003ekeep_connections\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is \u003ccode\u003eon\u003c/code\u003e. If set to \u003ccode\u003eoff\u003c/code\u003e, all connections to this foreign server will be discarded at the end of each transaction.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"\u003e\u003cspan\u003e\u003ccode\u003euse_scram_passthrough\u003c/code\u003e (\u003ccode\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode\u003epostgres_fdw\u003c/code\u003e will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, \u003ccode\u003epostgres_fdw\u003c/code\u003e uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs.\u003c/p\u003e\n\u003cp\u003eTo use SCRAM pass-through authentication:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eThe remote server must request the \u003ccode\u003escram-sha-256\u003c/code\u003e authentication method; otherwise, the connection will fail.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eThe remote server can be of any PostgreSQL version that supports SCRAM. Support for \u003ccode\u003euse_scram_passthrough\u003c/code\u003e is only required on the client side (FDW side).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eThe user mapping password is not used.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eThe server running \u003ccode\u003epostgres_fdw\u003c/code\u003e and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on \u003ccode\u003epostgres_fdw\u003c/code\u003e to authenticate on the foreign server (same salt and iterations, not merely the same password).\u003c/p\u003e\n\u003cp\u003eAs a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eThe current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence \u003cspan\u003e“\u003cspan\u003epass-through\u003c/span\u003e”\u003c/span\u003e: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-FUNCTIONS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.2. Functions \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003epostgres_fdw_get_connections( IN check_conn boolean DEFAULT false, OUT server_name text, OUT user_name text, OUT valid boolean, OUT used_in_xact boolean, OUT closed boolean, OUT remote_backend_pid int4) returns setof record\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function returns information about all open connections postgres_fdw has established from the local session to foreign servers. If there are no open connections, no records are returned.\u003c/p\u003e\n\u003cp\u003eIf \u003ccode\u003echeck_conn\u003c/code\u003e is set to \u003ccode\u003etrue\u003c/code\u003e, the function checks the status of each connection and shows the result in the \u003ccode\u003eclosed\u003c/code\u003e column. This feature is currently available only on systems that support the non-standard \u003ccode\u003ePOLLRDHUP\u003c/code\u003e extension to the \u003ccode\u003epoll\u003c/code\u003e system call, including Linux. This is useful to check if all connections used within a transaction are still open. If any connections are closed, the transaction cannot be committed successfully, so it is better to roll back as soon as a closed connection is detected, rather than continuing to the end. Users can roll back the transaction immediately if the function reports connections where both \u003ccode\u003eused_in_xact\u003c/code\u003e and \u003ccode\u003eclosed\u003c/code\u003e are \u003ccode\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExample usage of the function:\u003c/p\u003e\n\u003cpre\u003epostgres=# SELECT * FROM postgres_fdw_get_connections(true);\n server_name | user_name | valid | used_in_xact | closed | remote_backend_pid\n-------------+-----------+-------+--------------+-----------------------------\n loopback1   | postgres  | t     | t            | f      |            1353340\n loopback2   | public    | t     | t            | f      |            1353120\n loopback3   |           | f     | t            | f      |            1353156\n\u003c/pre\u003e\n\u003cp\u003eThe output columns are described in \u003ca href=\"/docs/18/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" rel=\"nofollow\"\u003eTable F.28\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\"\u003e\n\u003cp\u003e\u003cstrong\u003eTable F.28. \u003ccode\u003epostgres_fdw_get_connections\u003c/code\u003e Output Columns\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv\u003e\n\u003ctable\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eColumn\u003c/th\u003e\n\u003cth\u003eType\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eserver_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eThe foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003euser_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eName of the local user mapped to the foreign server of this connection, or \u003ccode\u003epublic\u003c/code\u003e if a public mapping is used. If the user mapping is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003evalid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eFalse if this connection is invalid, meaning it is used in the current transaction, but its foreign server or user mapping has been changed or dropped. The invalid connection will be closed at the end of the transaction. True is returned otherwise.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eused_in_xact\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is used in the current transaction.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eclosed\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is closed, false otherwise. \u003ccode\u003eNULL\u003c/code\u003e is returned if \u003ccode\u003echeck_conn\u003c/code\u003e is set to \u003ccode\u003efalse\u003c/code\u003e or if the connection status check is not available on this platform.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eremote_backend_pid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eint4\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with \u003ccode\u003eclosed\u003c/code\u003e set to \u003ccode\u003etrue\u003c/code\u003e), this still shows the process ID of the terminated backend.\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003epostgres_fdw_disconnect(server_name text) returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards the open connections that are established by \u003ccode\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode\u003efalse\u003c/code\u003e. If no foreign server with the given name is found, an error is reported. Example usage of the function:\u003c/p\u003e\n\u003cpre\u003epostgres=# SELECT postgres_fdw_disconnect(\u0026#39;loopback1\u0026#39;);\n postgres_fdw_disconnect\n-------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003epostgres_fdw_disconnect_all() returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards all the open connections that are established by \u003ccode\u003epostgres_fdw\u003c/code\u003e from the local session to foreign servers. If the connections are used in the current local transaction, they are not disconnected and warning messages are reported. This function returns \u003ccode\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode\u003efalse\u003c/code\u003e. Example usage of the function:\u003c/p\u003e\n\u003cpre\u003epostgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.3. Connection Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server during the first query that uses a foreign table 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 \u003ccode\u003ekeep_connections\u003c/code\u003e option for a foreign server. If multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.\u003c/p\u003e\n\u003cp\u003eWhen changing the definition of or removing a foreign server or 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.\u003c/p\u003e\n\u003cp\u003eOnce a connection to a foreign server has been established, it\u0026#39;s by default kept until the local or corresponding remote session exits. To disconnect a connection explicitly, \u003ccode\u003ekeep_connections\u003c/code\u003e option for a foreign server may be disabled, or \u003ccode\u003epostgres_fdw_disconnect\u003c/code\u003e and \u003ccode\u003epostgres_fdw_disconnect_all\u003c/code\u003e functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.4. Transaction Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eDuring a query that references any remote tables on a foreign server, \u003ccode\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eThe remote transaction uses \u003ccode\u003eSERIALIZABLE\u003c/code\u003e isolation level when the local transaction has \u003ccode\u003eSERIALIZABLE\u003c/code\u003e isolation level; otherwise it uses \u003ccode\u003eREPEATABLE READ\u003c/code\u003e 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 transaction uses \u003ccode\u003eSERIALIZABLE\u003c/code\u003e or \u003ccode\u003eREPEATABLE READ\u003c/code\u003e isolation level, but it might be surprising for a \u003ccode\u003eREAD COMMITTED\u003c/code\u003e local transaction. A future \u003cspan\u003ePostgreSQL\u003c/span\u003e release might modify these rules.\u003c/p\u003e\n\u003cp\u003eNote that it is currently not supported by \u003ccode\u003epostgres_fdw\u003c/code\u003e to prepare the remote transaction for two-phase commit.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.5. Remote Query Optimization \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query \u003ccode\u003eWHERE\u003c/code\u003e clauses to the remote server for execution, and by not retrieving table columns that are not needed for the current query. To reduce the risk of misexecution of queries, \u003ccode\u003eWHERE\u003c/code\u003e clauses are not sent to the remote server unless they use only data types, operators, and functions that are built-in or belong to an extension that\u0026#39;s listed in the foreign server\u0026#39;s \u003ccode\u003eextensions\u003c/code\u003e option. Operators and functions in such clauses must be \u003ccode\u003eIMMUTABLE\u003c/code\u003e as well. For an \u003ccode\u003eUPDATE\u003c/code\u003e or \u003ccode\u003eDELETE\u003c/code\u003e query, \u003ccode\u003epostgres_fdw\u003c/code\u003e attempts to optimize the query execution by sending the whole query to the remote server if there are no query \u003ccode\u003eWHERE\u003c/code\u003e clauses that cannot be sent to the remote server, no local joins for the query, no row-level local \u003ccode\u003eBEFORE\u003c/code\u003e or \u003ccode\u003eAFTER\u003c/code\u003e triggers or stored generated columns on the target table, and no \u003ccode\u003eCHECK OPTION\u003c/code\u003e constraints from parent views. In \u003ccode\u003eUPDATE\u003c/code\u003e, expressions to assign to target columns must use only built-in data types, \u003ccode\u003eIMMUTABLE\u003c/code\u003e operators, or \u003ccode\u003eIMMUTABLE\u003c/code\u003e functions, to reduce the risk of misexecution of the query.\u003c/p\u003e\n\u003cp\u003eWhen \u003ccode\u003epostgres_fdw\u003c/code\u003e encounters a join between foreign tables on 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 are subject to different user mappings. While sending the \u003ccode\u003eJOIN\u003c/code\u003e clauses, it takes the same precautions as mentioned above for the \u003ccode\u003eWHERE\u003c/code\u003e clauses.\u003c/p\u003e\n\u003cp\u003eThe query that is actually sent to the remote server for execution can be examined using \u003ccode\u003eEXPLAIN VERBOSE\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.6. Remote Query Execution Environment \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eIn the remote sessions opened by \u003ccode\u003epostgres_fdw\u003c/code\u003e, the \u003ca href=\"/docs/18/runtime-config-client.html#GUC-SEARCH-PATH\" rel=\"nofollow\"\u003esearch_path\u003c/a\u003e parameter is set to just \u003ccode\u003epg_catalog\u003c/code\u003e, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by \u003ccode\u003epostgres_fdw\u003c/code\u003e itself, because it always 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 functions, or else attach \u003ccode\u003eSET search_path\u003c/code\u003e options (see \u003ca href=\"/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e) to such functions to establish their expected search path environment.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e likewise establishes remote session settings for various parameters:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ca href=\"/docs/18/runtime-config-client.html#GUC-TIMEZONE\" rel=\"nofollow\"\u003eTimeZone\u003c/a\u003e is set to \u003ccode\u003eUTC\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ca href=\"/docs/18/runtime-config-client.html#GUC-DATESTYLE\" rel=\"nofollow\"\u003eDateStyle\u003c/a\u003e is set to \u003ccode\u003eISO\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ca href=\"/docs/18/runtime-config-client.html#GUC-INTERVALSTYLE\" rel=\"nofollow\"\u003eIntervalStyle\u003c/a\u003e is set to \u003ccode\u003epostgres\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003ca href=\"/docs/18/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\" rel=\"nofollow\"\u003eextra_float_digits\u003c/a\u003e is set to \u003ccode\u003e3\u003c/code\u003e for remote servers 9.0 and newer and is set to \u003ccode\u003e2\u003c/code\u003e for older versions\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThese are less likely to be problematic than \u003ccode\u003esearch_path\u003c/code\u003e, but can be handled with function \u003ccode\u003eSET\u003c/code\u003e options if the need arises.\u003c/p\u003e\n\u003cp\u003eIt is \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause \u003ccode\u003epostgres_fdw\u003c/code\u003e to malfunction.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.7. Cross-Version Compatibility \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e can be used with remote servers dating back to \u003cspan\u003ePostgreSQL\u003c/span\u003e 8.3. Read-only capability is available back to 8.1.\u003c/p\u003e\n\u003cp\u003eA limitation however is that \u003ccode\u003epostgres_fdw\u003c/code\u003e generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a \u003ccode\u003eWHERE\u003c/code\u003e clause for a foreign table. Thus, a built-in function that was added since the remote server\u0026#39;s release might be sent to it for execution, resulting in \u003cspan\u003e“\u003cspan\u003efunction does not exist\u003c/span\u003e”\u003c/span\u003e or a similar error. This type of failure can be worked around by rewriting the query, for example by embedding the foreign table reference in a sub-\u003ccode\u003eSELECT\u003c/code\u003e with \u003ccode\u003eOFFSET 0\u003c/code\u003e as an optimization fence, and placing the problematic function or operator outside the sub-\u003ccode\u003eSELECT\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAnother limitation is that when executing \u003ccode\u003eINSERT\u003c/code\u003e statements with an \u003ccode\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause on a foreign table, the remote server must be running \u003cspan\u003ePostgreSQL\u003c/span\u003e 9.5 or later, as earlier versions do not support this feature.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-WAIT-EVENTS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.8. Wait Events \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw\u003c/code\u003e can report the following wait events under the wait event type \u003ccode\u003eExtension\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePostgresFdwCleanupResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting for transaction abort on remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePostgresFdwConnect\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to establish a connection to a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003ePostgresFdwGetResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to receive the results of a query from a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.9. Configuration Parameters \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt id=\"GUC-PGFDW-APPLICATION-NAME\"\u003e\u003cspan\u003e\u003ccode\u003epostgres_fdw.application_name\u003c/code\u003e (\u003ccode\u003estring\u003c/code\u003e) \u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eSpecifies a value for \u003ca href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\" rel=\"nofollow\"\u003eapplication_name\u003c/a\u003e configuration parameter used when \u003ccode\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server. This overrides \u003ccode\u003eapplication_name\u003c/code\u003e option of the server object. Note that change of this parameter doesn\u0026#39;t affect any existing connections until they are re-established.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003epostgres_fdw.application_name\u003c/code\u003e can be any string of any length and contain even non-ASCII characters. However when it\u0026#39;s passed to and used as \u003ccode\u003eapplication_name\u003c/code\u003e in a foreign server, note that it will be truncated to less than \u003ccode\u003eNAMEDATALEN\u003c/code\u003e characters. Anything other than printable ASCII characters are replaced with \u003ca href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" rel=\"nofollow\"\u003eC-style hexadecimal escapes\u003c/a\u003e. See \u003ca href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\" rel=\"nofollow\"\u003eapplication_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e%\u003c/code\u003e characters begin \u003cspan\u003e“\u003cspan\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e 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\u0026#39;s not allowed to specify a plus/minus sign or a numeric literal after the \u003ccode\u003e%\u003c/code\u003e and before the option, for alignment and padding.\u003c/p\u003e\n\u003cdiv\u003e\n\u003ctable\u003e\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eEscape\u003c/th\u003e\n\u003cth\u003eEffect\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%a\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eApplication name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%c\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eSession ID on local server (see \u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\" rel=\"nofollow\"\u003elog_line_prefix\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%C\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eCluster name on local server (see \u003ca href=\"/docs/18/runtime-config-logging.html#GUC-CLUSTER-NAME\" rel=\"nofollow\"\u003ecluster_name\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%u\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eUser name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%d\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eDatabase name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%p\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of backend on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003e%%\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eLiteral %\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003cp\u003eFor example, suppose user \u003ccode\u003elocal_user\u003c/code\u003e establishes a connection from database \u003ccode\u003elocal_db\u003c/code\u003e to \u003ccode\u003eforeign_db\u003c/code\u003e as user \u003ccode\u003eforeign_user\u003c/code\u003e, the setting \u003ccode\u003e\u0026#39;db=%d, user=%u\u0026#39;\u003c/code\u003e is replaced with \u003ccode\u003e\u0026#39;db=local_db, user=local_user\u0026#39;\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-EXAMPLES\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.10. Examples \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eHere is an example of creating a foreign table with \u003ccode\u003epostgres_fdw\u003c/code\u003e. First install the extension:\u003c/p\u003e\n\u003cpre\u003eCREATE EXTENSION postgres_fdw;\n\u003c/pre\u003e\n\u003cp\u003eThen create a foreign server using \u003ca href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e. In this example we wish to connect to a \u003cspan\u003ePostgreSQL\u003c/span\u003e server on host \u003ccode\u003e192.83.123.89\u003c/code\u003e listening on port \u003ccode\u003e5432\u003c/code\u003e. The database to which the connection is made is named \u003ccode\u003eforeign_db\u003c/code\u003e on the remote server:\u003c/p\u003e\n\u003cpre\u003eCREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host \u0026#39;192.83.123.89\u0026#39;, port \u0026#39;5432\u0026#39;, dbname \u0026#39;foreign_db\u0026#39;);\n\u003c/pre\u003e\n\u003cp\u003eA user mapping, defined with \u003ca href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, is needed as well to identify the role that will be used on the remote server:\u003c/p\u003e\n\u003cpre\u003eCREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user \u0026#39;foreign_user\u0026#39;, password \u0026#39;password\u0026#39;);\n\u003c/pre\u003e\n\u003cp\u003eNow it is possible to create a foreign table with \u003ca href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e. In this example we wish to access the table named \u003ccode\u003esome_schema.some_table\u003c/code\u003e on the remote server. The local name for it will be \u003ccode\u003eforeign_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003eCREATE FOREIGN TABLE foreign_table (\n        id integer NOT NULL,\n        data text\n)\n        SERVER foreign_server\n        OPTIONS (schema_name \u0026#39;some_schema\u0026#39;, table_name \u0026#39;some_table\u0026#39;);\n\u003c/pre\u003e\n\u003cp\u003eIt\u0026#39;s essential that the data types and other properties of the columns declared in \u003ccode\u003eCREATE FOREIGN TABLE\u003c/code\u003e match the actual remote table. Column names must match as well, unless you attach \u003ccode\u003ecolumn_name\u003c/code\u003e options to the individual columns to show how they are named in the remote table. In many cases, use of \u003ca href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\" rel=\"nofollow\"\u003e\u003ccode\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e\u003c/a\u003e is preferable to constructing foreign table definitions manually.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"POSTGRES-FDW-AUTHOR\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003eF.38.11. Author \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eShigeru Hanada \u003ccode\u003e\u0026lt;\u003ca href=\"mailto:shigeru.hanada@gmail.com\" rel=\"nofollow\"\u003eshigeru.hanada@gmail.com\u003c/a\u003e\u0026gt;\u003c/code\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"4667d5768bb4307382d0eeaa7a6b2c625eecbdd4689ec5eab81f18086a053f07","Payload":{"description":["Accesses tables in remote PostgreSQL servers through foreign tables."],"manual_html":"\u003cdiv class=\"sect1\" id=\"POSTGRES-FDW\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003eF.38. postgres_fdw — access data stored in external \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e servers \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e module provides the foreign-data wrapper \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e, which can be used to access data stored in external \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e servers.\u003c/p\u003e\n\u003cp\u003eThe functionality provided by this module overlaps substantially with the functionality of the older \u003ca class=\"xref\" href=\"/docs/18/dblink.html\" title=\"F.11. dblink — connect to other PostgreSQL databases\"\u003edblink\u003c/a\u003e module. But \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.\u003c/p\u003e\n\u003cp\u003eTo prepare for remote access using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv class=\"orderedlist\"\u003e\n\u003col class=\"orderedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eInstall the \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e extension using \u003ca class=\"xref\" href=\"/docs/18/sql-createextension.html\" title=\"CREATE EXTENSION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE EXTENSION\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a foreign server object, using \u003ca class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e, to represent each remote database you want to connect to. Specify connection information, except \u003ccode class=\"literal\"\u003euser\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e, as options of the server object.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a user mapping, using \u003ca class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as \u003ccode class=\"literal\"\u003euser\u003c/code\u003e and \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e options of the user mapping.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eCreate a foreign table, using \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e or \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e, 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.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n\u003cp\u003eNow you need only \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e, or \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)\u003c/p\u003e\n\u003cp\u003eNote that the \u003ccode class=\"literal\"\u003eONLY\u003c/code\u003e option specified in \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e or \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e has no effect when accessing or modifying the remote table.\u003c/p\u003e\n\u003cp\u003eNote that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e currently lacks support for \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e statements with an \u003ccode class=\"literal\"\u003eON CONFLICT DO UPDATE\u003c/code\u003e clause. However, the \u003ccode class=\"literal\"\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause is supported, provided a unique index inference specification is omitted. Note also that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e supports row movement invoked by \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e 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 \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e target partition that will be updated elsewhere in the same command.\u003c/p\u003e\n\u003cp\u003eIt is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e is currently rather forgiving about performing data type conversions at need, surprising semantic anomalies may arise when types or collations do not match, due to the remote server interpreting query conditions differently from the local server.\u003c/p\u003e\n\u003cp\u003eNote 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.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.1. FDW Options of postgres_fdw \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.1. Connection Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA foreign server using the \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e foreign data wrapper can have the same options that \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e accepts in connection strings, as described in \u003ca class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2. Parameter Key Words\"\u003eSection 32.1.2\u003c/a\u003e, except that these options are not allowed or have special handling:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003euser\u003c/code\u003e, \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e and \u003ccode class=\"literal\"\u003esslpassword\u003c/code\u003e (specify these in a user mapping instead, or use a service file)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003eclient_encoding\u003c/code\u003e (this is automatically set from the local server encoding)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003eapplication_name\u003c/code\u003e - this may appear in \u003cspan class=\"emphasis\"\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\"\u003epostgres_fdw.application_name\u003c/a\u003e. If both are present, \u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e overrides the connection setting. Unlike \u003cspan class=\"application\"\u003elibpq\u003c/span\u003e, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e to include \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e. See \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\"\u003epostgres_fdw.application_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003efallback_application_name\u003c/code\u003e (always set to \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e)\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003esslkey\u003c/code\u003e and \u003ccode class=\"literal\"\u003esslcert\u003c/code\u003e - these may appear in \u003cspan class=\"emphasis\"\u003e\u003cem\u003eeither or both\u003c/em\u003e\u003c/span\u003e a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eOnly superusers may create or modify user mappings with the \u003ccode class=\"literal\"\u003esslcert\u003c/code\u003e or \u003ccode class=\"literal\"\u003esslkey\u003c/code\u003e settings.\u003c/p\u003e\n\u003cp\u003eNon-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the \u003ccode class=\"literal\"\u003epassword\u003c/code\u003e option for user mappings belonging to non-superusers where password authentication is required.\u003c/p\u003e\n\u003cp\u003eA superuser may override this check on a per-user-mapping basis by setting the user mapping option \u003ccode class=\"literal\"\u003epassword_required 'false'\u003c/code\u003e, e.g.,\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n\u003c/pre\u003e\n\u003cp\u003eTo 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.\u003c/p\u003e\n\u003cp\u003eCare 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 \u003ccode class=\"literal\"\u003epassword_required=false\u003c/code\u003e on the \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e role. Keep in mind that the mapped user can potentially use any client certificates, \u003ccode class=\"filename\"\u003e.pgpass\u003c/code\u003e, \u003ccode class=\"filename\"\u003e.pg_service.conf\u003c/code\u003e etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see \u003ca class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16. The Password File\"\u003eSection 32.16\u003c/a\u003e.) They can also use any trust relationship granted by authentication modes like \u003ccode class=\"literal\"\u003epeer\u003c/code\u003e or \u003ccode class=\"literal\"\u003eident\u003c/code\u003e authentication.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.2. Object Name Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThese options can be used to control the names used in SQL statements sent to the remote \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server. These options are needed when a foreign table is created with names different from the underlying remote table's names.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eschema_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003etable_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ecolumn_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.3. Cost Estimation Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e retrieves remote data by executing queries 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. So \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e provides the following options to control how cost estimation is done:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e issues remote \u003ccode class=\"command\"\u003eEXPLAIN\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e (\u003ccode class=\"type\"\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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. The default value is \u003ccode class=\"literal\"\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e (\u003ccode class=\"type\"\u003efloating point\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis 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 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 \u003ccode class=\"literal\"\u003e0.2\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eWhen \u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e is true, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e obtains row count and cost estimates from the remote server and then adds \u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e and \u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e to the cost estimates. When \u003ccode class=\"literal\"\u003euse_remote_estimate\u003c/code\u003e is false, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e performs local row count and cost estimation and then adds \u003ccode class=\"literal\"\u003efdw_startup_cost\u003c/code\u003e and \u003ccode class=\"literal\"\u003efdw_tuple_cost\u003c/code\u003e 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 \u003ca class=\"xref\" href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"\u003e\u003cspan class=\"refentrytitle\"\u003eANALYZE\u003c/span\u003e\u003c/a\u003e on the foreign table is the way to update 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.\u003c/p\u003e\n\u003cp\u003eThe following option controls how such an \u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e operation behaves:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eanalyze_sampling\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option, which can be specified for a foreign table or a foreign server, determines if \u003ccode class=\"command\"\u003eANALYZE\u003c/code\u003e on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e, \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e, \u003ccode class=\"literal\"\u003esystem\u003c/code\u003e, \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e and \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e. \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e disables remote sampling, so all data are transferred and sampled locally. \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e performs remote sampling using the \u003ccode class=\"literal\"\u003erandom()\u003c/code\u003e function to choose returned rows, while \u003ccode class=\"literal\"\u003esystem\u003c/code\u003e and \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e rely on the built-in \u003ccode class=\"literal\"\u003eTABLESAMPLE\u003c/code\u003e methods of those names. \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e works on all remote server versions, while \u003ccode class=\"literal\"\u003eTABLESAMPLE\u003c/code\u003e is supported only since 9.5. \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e (the default) picks the recommended sampling method automatically; currently it means either \u003ccode class=\"literal\"\u003ebernoulli\u003c/code\u003e or \u003ccode class=\"literal\"\u003erandom\u003c/code\u003e depending on the remote server version.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.4. Remote Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, only \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses using built-in operators and 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 be improved by sending such \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses for remote execution. This behavior can be controlled using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option is a comma-separated list of names of \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extensions that are installed, in 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.\u003c/p\u003e\n\u003cp\u003eWhen using the \u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e option, \u003cspan class=\"emphasis\"\u003e\u003cem\u003eit is the user's responsibility\u003c/em\u003e\u003c/span\u003e that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003efetch_size\u003c/code\u003e (\u003ccode class=\"type\"\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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. The default is \u003ccode class=\"literal\"\u003e100\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e (\u003ccode class=\"type\"\u003einteger\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option specifies the number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003e1\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eNote the actual number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e inserts at once depends on the number of columns and the provided \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e value. The batch is executed as a single query, and the libpq protocol (which \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e exceeds the limit, the \u003ccode class=\"literal\"\u003ebatch_size\u003c/code\u003e will be adjusted to avoid an error.\u003c/p\u003e\n\u003cp\u003eThis option also applies when copying into foreign tables. In that case the actual number of rows \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the \u003ccode class=\"command\"\u003eCOPY\u003c/code\u003e command.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.5. Asynchronous Execution Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e supports asynchronous execution, which runs multiple parts of an \u003ccode class=\"structname\"\u003eAppend\u003c/code\u003e node concurrently rather than serially to improve performance. This execution can be controlled using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003easync_capable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eIn order to ensure that the data being returned from a foreign server is consistent, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eAsynchronous execution is applied even when an \u003ccode class=\"structname\"\u003eAppend\u003c/code\u003e 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 \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e, 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.6. Transaction Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eAs described in the Transaction Management section, in \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e transactions are managed by creating corresponding remote transactions, and subtransactions are managed by creating corresponding remote subtransactions. When multiple remote transactions are involved in the current local transaction, by default \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote transactions serially when the local transaction is committed or aborted. When multiple remote subtransactions are involved in the current local subtransaction, by default \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eparallel_commit\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eparallel_abort\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eIf multiple foreign servers with these options enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed or aborted in parallel across those foreign servers when the local transaction is committed or aborted.\u003c/p\u003e\n\u003cp\u003eWhen these options are enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed or aborted.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.7. Updatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e are assumed to be updatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eupdatable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be modified using \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e, \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e and \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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 that the \u003ccode class=\"literal\"\u003einformation_schema\u003c/code\u003e views will report a \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.8. Truncatability Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default all foreign tables using \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e are assumed to be truncatable. This may be overridden using the following option:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003etruncatable\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e allows foreign tables to be truncated using the \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eOf 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.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.9. Importing Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e is able to import foreign table definitions using \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. This command creates foreign table definitions on the local server that match tables or views present on the remote server. If the remote tables to be imported have columns of user-defined data types, the local server must have compatible types of the same names.\u003c/p\u003e\n\u003cp\u003eImporting behavior can be customized with the following options (given in the \u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e command):\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_collate\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eCOLLATE\u003c/code\u003e options are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e. You might 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. 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.\u003c/p\u003e\n\u003cp\u003eEven when this parameter is set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, importing columns whose collation is the remote server's default can be risky. They will be imported with \u003ccode class=\"literal\"\u003eCOLLATE \"default\"\u003c/code\u003e, which will select the local server's default collation, which could be different.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_default\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eDEFAULT\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; \u003ccode class=\"function\"\u003enextval()\u003c/code\u003e is a common source of problems. The \u003ccode class=\"command\"\u003eIMPORT\u003c/code\u003e will fail altogether if an imported default expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_generated\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eGENERATED\u003c/code\u003e expressions are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e. The \u003ccode class=\"command\"\u003eIMPORT\u003c/code\u003e will fail altogether if an imported generated expression uses a function or operator that does not exist locally.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003eimport_not_null\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether column \u003ccode class=\"literal\"\u003eNOT NULL\u003c/code\u003e constraints are included in the definitions of foreign tables imported from a foreign server. The default is \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003cp\u003eNote that constraints other than \u003ccode class=\"literal\"\u003eNOT NULL\u003c/code\u003e will never be imported from the remote tables. Although \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e does support check constraints on foreign tables, there is no provision for importing them automatically, because of the risk that a constraint expression could evaluate differently on the local and remote servers. Any such inconsistency in the behavior of a check constraint could lead to hard-to-detect errors in query optimization. So if you wish to import check constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of check constraints on foreign tables, see \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eTables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in \u003ccode class=\"literal\"\u003eLIMIT TO\u003c/code\u003e clause. Otherwise they are automatically excluded from \u003ca class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003cspan class=\"refentrytitle\"\u003eIMPORT FOREIGN SCHEMA\u003c/span\u003e\u003c/a\u003e. 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 creating extra objects.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch4 class=\"title\"\u003eF.38.1.10. Connection Management Options \u003c/h4\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eBy default, all connections that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes to foreign servers are kept open in the local session for re-use.\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is \u003ccode class=\"literal\"\u003eon\u003c/code\u003e. If set to \u003ccode class=\"literal\"\u003eoff\u003c/code\u003e, all connections to this foreign server will be discarded at the end of each transaction.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003euse_scram_passthrough\u003c/code\u003e (\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e)\u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis option controls whether \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs.\u003c/p\u003e\n\u003cp\u003eTo use SCRAM pass-through authentication:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe remote server must request the \u003ccode class=\"literal\"\u003escram-sha-256\u003c/code\u003e authentication method; otherwise, the connection will fail.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe remote server can be of any PostgreSQL version that supports SCRAM. Support for \u003ccode class=\"literal\"\u003euse_scram_passthrough\u003c/code\u003e is only required on the client side (FDW side).\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe user mapping password is not used.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe server running \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to authenticate on the foreign server (same salt and iterations, not merely the same password).\u003c/p\u003e\n\u003cp\u003eAs a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eThe current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003epass-through\u003c/span\u003e”\u003c/span\u003e: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.2. Functions \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_get_connections( IN check_conn boolean DEFAULT false, OUT server_name text, OUT user_name text, OUT valid boolean, OUT used_in_xact boolean, OUT closed boolean, OUT remote_backend_pid int4) returns setof record\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function returns information about all open connections postgres_fdw has established from the local session to foreign servers. If there are no open connections, no records are returned.\u003c/p\u003e\n\u003cp\u003eIf \u003ccode class=\"literal\"\u003echeck_conn\u003c/code\u003e is set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e, the function checks the status of each connection and shows the result in the \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e column. This feature is currently available only on systems that support the non-standard \u003ccode class=\"symbol\"\u003ePOLLRDHUP\u003c/code\u003e extension to the \u003ccode class=\"symbol\"\u003epoll\u003c/code\u003e system call, including Linux. This is useful to check if all connections used within a transaction are still open. If any connections are closed, the transaction cannot be committed successfully, so it is better to roll back as soon as a closed connection is detected, rather than continuing to the end. Users can roll back the transaction immediately if the function reports connections where both \u003ccode class=\"literal\"\u003eused_in_xact\u003c/code\u003e and \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e are \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eExample usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT * FROM postgres_fdw_get_connections(true);\n server_name | user_name | valid | used_in_xact | closed | remote_backend_pid\n-------------+-----------+-------+--------------+-----------------------------\n loopback1   | postgres  | t     | t            | f      |            1353340\n loopback2   | public    | t     | t            | f      |            1353120\n loopback3   |           | f     | t            | f      |            1353156\n\u003c/pre\u003e\n\u003cp\u003eThe output columns are described in \u003ca class=\"xref\" href=\"/docs/18/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table F.28. postgres_fdw_get_connections Output Columns\"\u003eTable F.28\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable F.28. \u003ccode class=\"function\"\u003epostgres_fdw_get_connections\u003c/code\u003e Output Columns\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eColumn\u003c/th\u003e\n\u003cth\u003eType\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eserver_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eThe foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003euser_name\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003etext\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eName of the local user mapped to the foreign server of this connection, or \u003ccode class=\"literal\"\u003epublic\u003c/code\u003e if a public mapping is used. If the user mapping is dropped but the connection remains open (i.e., marked as invalid), this will be \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003evalid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eFalse if this connection is invalid, meaning it is used in the current transaction, but its foreign server or user mapping has been changed or dropped. The invalid connection will be closed at the end of the transaction. True is returned otherwise.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eused_in_xact\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is used in the current transaction.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eclosed\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eboolean\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eTrue if this connection is closed, false otherwise. \u003ccode class=\"literal\"\u003eNULL\u003c/code\u003e is returned if \u003ccode class=\"literal\"\u003echeck_conn\u003c/code\u003e is set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e or if the connection status check is not available on this platform.\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"structfield\"\u003eremote_backend_pid\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003eint4\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with \u003ccode class=\"literal\"\u003eclosed\u003c/code\u003e set to \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e), this still shows the process ID of the terminated backend.\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_disconnect(server_name text) returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards the open connections that are established by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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 \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If no foreign server with the given name is found, an error is reported. Example usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"function\"\u003epostgres_fdw_disconnect_all() returns boolean\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eThis function discards all the open connections that are established by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e from the local session to foreign servers. If the connections are used in the current local transaction, they are not disconnected and warning messages are reported. This function returns \u003ccode class=\"literal\"\u003etrue\u003c/code\u003e if it disconnects at least one connection, otherwise \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. Example usage of the function:\u003c/p\u003e\n\u003cpre class=\"screen\"\u003epostgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n\u003c/pre\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.3. Connection Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server during the first query that uses a foreign table 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 \u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e option for a foreign server. If multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.\u003c/p\u003e\n\u003cp\u003eWhen changing the definition of or removing a foreign server or 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.\u003c/p\u003e\n\u003cp\u003eOnce a connection to a foreign server has been established, it's by default kept until the local or corresponding remote session exits. To disconnect a connection explicitly, \u003ccode class=\"literal\"\u003ekeep_connections\u003c/code\u003e option for a foreign server may be disabled, or \u003ccode class=\"function\"\u003epostgres_fdw_disconnect\u003c/code\u003e and \u003ccode class=\"function\"\u003epostgres_fdw_disconnect_all\u003c/code\u003e functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.4. Transaction Management \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eDuring a query that references any remote tables on a foreign server, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 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.\u003c/p\u003e\n\u003cp\u003eThe remote transaction uses \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e isolation level when the local transaction has \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e isolation level; otherwise it uses \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e 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 transaction uses \u003ccode class=\"literal\"\u003eSERIALIZABLE\u003c/code\u003e or \u003ccode class=\"literal\"\u003eREPEATABLE READ\u003c/code\u003e isolation level, but it might be surprising for a \u003ccode class=\"literal\"\u003eREAD COMMITTED\u003c/code\u003e local transaction. A future \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e release might modify these rules.\u003c/p\u003e\n\u003cp\u003eNote that it is currently not supported by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to prepare the remote transaction for two-phase commit.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.5. Remote Query Optimization \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses to the remote server for execution, and by not retrieving table columns that are not needed for the current query. To reduce the risk of misexecution of queries, \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses are not sent to the remote server unless they use only data types, operators, and functions that are built-in or belong to an extension that's listed in the foreign server's \u003ccode class=\"literal\"\u003eextensions\u003c/code\u003e option. Operators and functions in such clauses must be \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e as well. For an \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e or \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e query, \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e attempts to optimize the query execution by sending the whole query to the remote server if there are no query \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses that cannot be sent to the remote server, no local joins for the query, no row-level local \u003ccode class=\"literal\"\u003eBEFORE\u003c/code\u003e or \u003ccode class=\"literal\"\u003eAFTER\u003c/code\u003e triggers or stored generated columns on the target table, and no \u003ccode class=\"literal\"\u003eCHECK OPTION\u003c/code\u003e constraints from parent views. In \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, expressions to assign to target columns must use only built-in data types, \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e operators, or \u003ccode class=\"literal\"\u003eIMMUTABLE\u003c/code\u003e functions, to reduce the risk of misexecution of the query.\u003c/p\u003e\n\u003cp\u003eWhen \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e encounters a join between foreign tables on 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 are subject to different user mappings. While sending the \u003ccode class=\"literal\"\u003eJOIN\u003c/code\u003e clauses, it takes the same precautions as mentioned above for the \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clauses.\u003c/p\u003e\n\u003cp\u003eThe query that is actually sent to the remote server for execution can be examined using \u003ccode class=\"command\"\u003eEXPLAIN VERBOSE\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.6. Remote Query Execution Environment \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eIn the remote sessions opened by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e, the \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-SEARCH-PATH\"\u003esearch_path\u003c/a\u003e parameter is set to just \u003ccode class=\"literal\"\u003epg_catalog\u003c/code\u003e, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e itself, because it always 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 functions, or else attach \u003ccode class=\"literal\"\u003eSET search_path\u003c/code\u003e options (see \u003ca class=\"xref\" href=\"/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e) to such functions to establish their expected search path environment.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e likewise establishes remote session settings for various parameters:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist compact\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-TIMEZONE\"\u003eTimeZone\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003eUTC\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-DATESTYLE\"\u003eDateStyle\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003eISO\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-INTERVALSTYLE\"\u003eIntervalStyle\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003epostgres\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003e\u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\"\u003eextra_float_digits\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003e3\u003c/code\u003e for remote servers 9.0 and newer and is set to \u003ccode class=\"literal\"\u003e2\u003c/code\u003e for older versions\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003cp\u003eThese are less likely to be problematic than \u003ccode class=\"varname\"\u003esearch_path\u003c/code\u003e, but can be handled with function \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e options if the need arises.\u003c/p\u003e\n\u003cp\u003eIt is \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e to malfunction.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.7. Cross-Version Compatibility \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e can be used with remote servers dating back to \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 8.3. Read-only capability is available back to 8.1.\u003c/p\u003e\n\u003cp\u003eA limitation however is that \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a \u003ccode class=\"literal\"\u003eWHERE\u003c/code\u003e clause for a foreign table. Thus, a built-in function that was added since the remote server's release might be sent to it for execution, resulting in \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003efunction does not exist\u003c/span\u003e”\u003c/span\u003e or a similar error. This type of failure can be worked around by rewriting the query, for example by embedding the foreign table reference in a sub-\u003ccode class=\"literal\"\u003eSELECT\u003c/code\u003e with \u003ccode class=\"literal\"\u003eOFFSET 0\u003c/code\u003e as an optimization fence, and placing the problematic function or operator outside the sub-\u003ccode class=\"literal\"\u003eSELECT\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eAnother limitation is that when executing \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e statements with an \u003ccode class=\"literal\"\u003eON CONFLICT DO NOTHING\u003c/code\u003e clause on a foreign table, the remote server must be running \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.5 or later, as earlier versions do not support this feature.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.8. Wait Events \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003e\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e can report the following wait events under the wait event type \u003ccode class=\"literal\"\u003eExtension\u003c/code\u003e:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwCleanupResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting for transaction abort on remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwConnect\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to establish a connection to a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"literal\"\u003ePostgresFdwGetResult\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eWaiting to receive the results of a query from a remote server.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.9. Configuration Parameters \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt id=\"GUC-PGFDW-APPLICATION-NAME\"\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e (\u003ccode class=\"type\"\u003estring\u003c/code\u003e) \u003c/span\u003e \u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eSpecifies a value for \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\"\u003eapplication_name\u003c/a\u003e configuration parameter used when \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e establishes a connection to a foreign server. This overrides \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"varname\"\u003epostgres_fdw.application_name\u003c/code\u003e can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as \u003ccode class=\"varname\"\u003eapplication_name\u003c/code\u003e in a foreign server, note that it will be truncated to less than \u003ccode class=\"symbol\"\u003eNAMEDATALEN\u003c/code\u003e characters. Anything other than printable ASCII characters are replaced with \u003ca class=\"link\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2. String Constants with C-Style Escapes\"\u003eC-style hexadecimal escapes\u003c/a\u003e. See \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\"\u003eapplication_name\u003c/a\u003e for details.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"literal\"\u003e%\u003c/code\u003e characters begin \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape sequences\u003c/span\u003e”\u003c/span\u003e 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 \u003ccode class=\"literal\"\u003e%\u003c/code\u003e and before the option, for alignment and padding.\u003c/p\u003e\n\u003cdiv class=\"informaltable\"\u003e\n\u003ctable class=\"informaltable\"\u003e\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eEscape\u003c/th\u003e\n\u003cth\u003eEffect\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%a\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eApplication name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%c\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eSession ID on local server (see \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\"\u003elog_line_prefix\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%C\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eCluster name on local server (see \u003ca class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-CLUSTER-NAME\"\u003ecluster_name\u003c/a\u003e for details)\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%u\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eUser name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%d\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eDatabase name on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%p\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eProcess ID of backend on local server\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e%%\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003eLiteral %\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003cp\u003eFor example, suppose user \u003ccode class=\"literal\"\u003elocal_user\u003c/code\u003e establishes a connection from database \u003ccode class=\"literal\"\u003elocal_db\u003c/code\u003e to \u003ccode class=\"literal\"\u003eforeign_db\u003c/code\u003e as user \u003ccode class=\"literal\"\u003eforeign_user\u003c/code\u003e, the setting \u003ccode class=\"literal\"\u003e'db=%d, user=%u'\u003c/code\u003e is replaced with \u003ccode class=\"literal\"\u003e'db=local_db, user=local_user'\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.10. Examples \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eHere is an example of creating a foreign table with \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e. First install the extension:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE EXTENSION postgres_fdw;\n\u003c/pre\u003e\n\u003cp\u003eThen create a foreign server using \u003ca class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE SERVER\u003c/span\u003e\u003c/a\u003e. In this example we wish to connect to a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e server on host \u003ccode class=\"literal\"\u003e192.83.123.89\u003c/code\u003e listening on port \u003ccode class=\"literal\"\u003e5432\u003c/code\u003e. The database to which the connection is made is named \u003ccode class=\"literal\"\u003eforeign_db\u003c/code\u003e on the remote server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n\u003c/pre\u003e\n\u003cp\u003eA user mapping, defined with \u003ca class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE USER MAPPING\u003c/span\u003e\u003c/a\u003e, is needed as well to identify the role that will be used on the remote server:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n\u003c/pre\u003e\n\u003cp\u003eNow it is possible to create a foreign table with \u003ca class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FOREIGN TABLE\u003c/span\u003e\u003c/a\u003e. In this example we wish to access the table named \u003ccode class=\"structname\"\u003esome_schema.some_table\u003c/code\u003e on the remote server. The local name for it will be \u003ccode class=\"structname\"\u003eforeign_table\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE FOREIGN TABLE foreign_table (\n        id integer NOT NULL,\n        data text\n)\n        SERVER foreign_server\n        OPTIONS (schema_name 'some_schema', table_name 'some_table');\n\u003c/pre\u003e\n\u003cp\u003eIt's essential that the data types and other properties of the columns declared in \u003ccode class=\"command\"\u003eCREATE FOREIGN TABLE\u003c/code\u003e match the actual remote table. Column names must match as well, unless you attach \u003ccode class=\"literal\"\u003ecolumn_name\u003c/code\u003e options to the individual columns to show how they are named in the remote table. In many cases, use of \u003ca class=\"link\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"\u003e\u003ccode class=\"command\"\u003eIMPORT FOREIGN SCHEMA\u003c/code\u003e\u003c/a\u003e is preferable to constructing foreign table definitions manually.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003eF.38.11. Author \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eShigeru Hanada \u003ccode class=\"email\"\u003e\u0026lt;\u003ca class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\"\u003eshigeru.hanada@gmail.com\u003c/a\u003e\u0026gt;\u003c/code\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","related":[{"label":"Foreign-data wrapper catalog","url":"/wiki/catalog/pg_foreign_data_wrapper/?v=18"},{"label":"Existing extension catalogue identity","url":"/e/postgres_fdw/"},{"label":"Foreign Scan plan node","url":"/wiki/plan/foreign-scan/?v=18"}],"sections":[{"paragraphs":["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.","The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."],"title":"Interface and capability boundaries"},{"paragraphs":["postgres_fdw supports asynchronous execution, which runs multiple parts of an Append node concurrently rather than serially to improve performance. This execution can be controlled using the following option:"],"title":"Asynchronous Execution Options"},{"paragraphs":["As described in the Transaction Management section, in postgres_fdw transactions are managed by creating corresponding remote transactions, and subtransactions are managed by creating corresponding remote subtransactions. When multiple remote transactions are involved in the current local transaction, by default postgres_fdw commits or aborts those remote transactions serially when the local transaction is committed or aborted. When multiple remote subtransactions are involved in the current local subtransaction, by default postgres_fdw commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:","If multiple foreign servers with these options enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed or aborted in parallel across those foreign servers when the local transaction is committed or aborted.","When these options are enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed or aborted."],"title":"Transaction Management Options"},{"paragraphs":["During a query that references any remote tables on a foreign server, postgres_fdw 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.","The remote transaction uses SERIALIZABLE isolation level when the local transaction has SERIALIZABLE isolation level; otherwise it uses REPEATABLE READ 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 transaction uses SERIALIZABLE or REPEATABLE READ isolation level, but it might be surprising for a READ COMMITTED local transaction. A future PostgreSQL release might modify these rules.","Note that it is currently not supported by postgres_fdw to prepare the remote transaction for two-phase commit."],"title":"Transaction Management"},{"paragraphs":["postgres_fdw attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query WHERE clauses to the remote server for execution, and by not retrieving table columns that are not needed for the current query. To reduce the risk of misexecution of queries, WHERE clauses are not sent to the remote server unless they use only data types, operators, and functions that are built-in or belong to an extension that's listed in the foreign server's extensions option. Operators and functions in such clauses must be IMMUTABLE as well. For an UPDATE or DELETE query, postgres_fdw attempts to optimize the query execution by sending the whole query to the remote server if there are no query WHERE clauses that cannot be sent to the remote server, no local joins for the query, no row-level local BEFORE or AFTER triggers or stored generated columns on the target table, and no CHECK OPTION constraints from parent views. In UPDATE , expressions to assign to target columns must use only built-in data types, IMMUTABLE operators, or IMMUTABLE functions, to reduce the risk of misexecution of the query.","When postgres_fdw encounters a join between foreign tables on 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 are subject to different user mappings. While sending the JOIN clauses, it takes the same precautions as mentioned above for the WHERE clauses.","The query that is actually sent to the remote server for execution can be examined using EXPLAIN VERBOSE ."],"title":"Remote Query Optimization"},{"paragraphs":["postgres_fdw can be used with remote servers dating back to PostgreSQL 8.3. Read-only capability is available back to 8.1.","A limitation however is that postgres_fdw generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a WHERE clause for a foreign table. Thus, a built-in function that was added since the remote server's release might be sent to it for execution, resulting in “ function does not exist ” or a similar error. This type of failure can be worked around by rewriting the query, for example by embedding the foreign table reference in a sub- SELECT with OFFSET 0 as an optimization fence, and placing the problematic function or operator outside the sub- SELECT .","Another limitation is that when executing INSERT statements with an ON CONFLICT DO NOTHING clause on a foreign table, the remote server must be running PostgreSQL 9.5 or later, as earlier versions do not support this feature."],"title":"Cross-Version Compatibility"},{"code":"{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine-\u003eGetForeignRelSize = postgresGetForeignRelSize;\n\troutine-\u003eGetForeignPaths = postgresGetForeignPaths;\n\troutine-\u003eGetForeignPlan = postgresGetForeignPlan;\n\troutine-\u003eBeginForeignScan = postgresBeginForeignScan;\n\troutine-\u003eIterateForeignScan = postgresIterateForeignScan;\n\troutine-\u003eReScanForeignScan = postgresReScanForeignScan;\n\troutine-\u003eEndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine-\u003eAddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine-\u003ePlanForeignModify = postgresPlanForeignModify;\n\troutine-\u003eBeginForeignModify = postgresBeginForeignModify;\n\troutine-\u003eExecForeignInsert = postgresExecForeignInsert;\n\troutine-\u003eExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine-\u003eGetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine-\u003eExecForeignUpdate = postgresExecForeignUpdate;\n\troutine-\u003eExecForeignDelete = postgresExecForeignDelete;\n\troutine-\u003eEndForeignModify = postgresEndForeignModify;\n\troutine-\u003eBeginForeignInsert = postgresBeginForeignInsert;\n\troutine-\u003eEndForeignInsert = postgresEndForeignInsert;\n\troutine-\u003eIsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine-\u003ePlanDirectModify = postgresPlanDirectModify;\n\troutine-\u003eBeginDirectModify = postgresBeginDirectModify;\n\troutine-\u003eIterateDirectModify = postgresIterateDirectModify;\n\troutine-\u003eEndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine-\u003eRecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine-\u003eExplainForeignScan = postgresExplainForeignScan;\n\troutine-\u003eExplainForeignModify = postgresExplainForeignModify;\n\troutine-\u003eExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine-\u003eExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine-\u003eAnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine-\u003eImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine-\u003eGetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine-\u003eGetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine-\u003eIsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine-\u003eForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine-\u003eForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine-\u003eForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}","title":"Registered implementation in core source"}],"tables":[{"columns":[{"key":"feature","label":"Interface operation"},{"key":"state","label":"Source observation"},{"key":"callback","label":"Callback"},{"key":"implementation","label":"Implementation"}],"key":"callbacks","rows":[{"callback":"IterateForeignScan","feature":"Scan rows","implementation":"postgresIterateForeignScan","state":"Handler registered; conditions apply"},{"callback":"ExecForeignInsert","feature":"INSERT","implementation":"postgresExecForeignInsert","state":"Handler registered; conditions apply"},{"callback":"ExecForeignUpdate","feature":"UPDATE","implementation":"postgresExecForeignUpdate","state":"Handler registered; conditions apply"},{"callback":"ExecForeignDelete","feature":"DELETE","implementation":"postgresExecForeignDelete","state":"Handler registered; conditions apply"},{"callback":"ExecForeignTruncate","feature":"TRUNCATE","implementation":"postgresExecForeignTruncate","state":"Handler registered; conditions apply"},{"callback":"GetForeignJoinPaths","feature":"Join path pushdown","implementation":"postgresGetForeignJoinPaths","state":"Handler registered; conditions apply"},{"callback":"GetForeignUpperPaths","feature":"Upper paths, including aggregation","implementation":"postgresGetForeignUpperPaths","state":"Handler registered; conditions apply"},{"callback":"ExecForeignBatchInsert","feature":"Batch insert","implementation":"postgresExecForeignBatchInsert","state":"Handler registered; conditions apply"},{"callback":"ForeignAsyncRequest","feature":"Asynchronous append execution","implementation":"postgresForeignAsyncRequest","state":"Handler registered; conditions apply"},{"callback":"ImportForeignSchema","feature":"Import schema","implementation":"postgresImportForeignSchema","state":"Handler registered; conditions apply"}],"title":"Registered interface handlers"},{"columns":[{"key":"name","label":"Option"},{"key":"definition","label":"Same-version definition"}],"key":"options","rows":[{"definition":"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.","name":"schema_name"},{"definition":"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.","name":"table_name"},{"definition":"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.","name":"column_name"},{"definition":"This option, which can be specified for a foreign table or a foreign server, controls whether postgres_fdw issues remote EXPLAIN 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 false .","name":"use_remote_estimate"},{"definition":"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. The default value is 100 .","name":"fdw_startup_cost"},{"definition":"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 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 0.2 .","name":"fdw_tuple_cost"},{"definition":"This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table samples the data on the remote side, or reads and transfers all data and performs the sampling locally. The supported values are off , random , system , bernoulli and auto . off disables remote sampling, so all data are transferred and sampled locally. random performs remote sampling using the random() function to choose returned rows, while system and bernoulli rely on the built-in TABLESAMPLE methods of those names. random works on all remote server versions, while TABLESAMPLE is supported only since 9.5. auto (the default) picks the recommended sampling method automatically; currently it means either bernoulli or random depending on the remote server version.","name":"analyze_sampling"},{"definition":"This option is a comma-separated list of names of PostgreSQL extensions that are installed, in 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. When using the extensions option, it is the user's responsibility that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.","name":"extensions"},{"definition":"This option specifies the number of rows postgres_fdw 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. The default is 100 .","name":"fetch_size"},{"definition":"This option specifies the number of rows postgres_fdw 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 1 . Note the actual number of rows postgres_fdw inserts at once depends on the number of columns and the provided batch_size value. The batch is executed as a single query, and the libpq protocol (which postgres_fdw uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * batch_size exceeds the limit, the batch_size will be adjusted to avoid an error. This option also applies when copying into foreign tables. In that case the actual number of rows postgres_fdw copies at once is determined in a similar way to the insert case, but it is limited to at most 1000 due to implementation restrictions of the COPY command.","name":"batch_size"},{"definition":"This option controls whether postgres_fdw 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 false . In order to ensure that the data being returned from a foreign server is consistent, postgres_fdw 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. Asynchronous execution is applied even when an Append 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 postgres_fdw , 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.","name":"async_capable"},{"definition":"This option controls whether postgres_fdw commits, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is committed. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_commit"},{"definition":"This option controls whether postgres_fdw aborts, in parallel, remote transactions opened on a foreign server in a local transaction when the local transaction is aborted. This setting also applies to remote and local subtransactions. This option can only be specified for foreign servers, not per-table. The default is false .","name":"parallel_abort"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be modified using INSERT , UPDATE and DELETE commands. It can be specified for a foreign table or a foreign server. A table-level option overrides a server-level option. The default is true . 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 that the information_schema views will report a postgres_fdw foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.","name":"updatable"},{"definition":"This option controls whether postgres_fdw allows foreign tables to be truncated using the TRUNCATE 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 true . 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.","name":"truncatable"},{"definition":"This option controls whether column COLLATE options are included in the definitions of foreign tables imported from a foreign server. The default is true . You might 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. 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. Even when this parameter is set to true , importing columns whose collation is the remote server's default can be risky. They will be imported with COLLATE \"default\" , which will select the local server's default collation, which could be different.","name":"import_collate"},{"definition":"This option controls whether column DEFAULT expressions are included in the definitions of foreign tables imported from a foreign server. The default is false . If you enable this option, be wary of defaults that might get computed differently on the local server than they would be on the remote server; nextval() is a common source of problems. The IMPORT will fail altogether if an imported default expression uses a function or operator that does not exist locally.","name":"import_default"},{"definition":"This option controls whether column GENERATED expressions are included in the definitions of foreign tables imported from a foreign server. The default is true . The IMPORT will fail altogether if an imported generated expression uses a function or operator that does not exist locally.","name":"import_generated"},{"definition":"This option controls whether column NOT NULL constraints are included in the definitions of foreign tables imported from a foreign server. The default is true .","name":"import_not_null"},{"definition":"This option controls whether postgres_fdw keeps the connections to the foreign server open so that subsequent queries can re-use them. It can only be specified for a foreign server. The default is on . If set to off , all connections to this foreign server will be discarded at the end of each transaction.","name":"keep_connections"},{"definition":"This option controls whether postgres_fdw will use the SCRAM pass-through authentication to connect to the foreign server. It can be specified for a foreign server or a user mapping. A user mapping setting overrides the foreign server setting. With SCRAM pass-through authentication, postgres_fdw uses SCRAM-hashed secrets instead of plain-text user passwords to connect to the remote server. This avoids storing plain-text user passwords in PostgreSQL system catalogs. To use SCRAM pass-through authentication: The remote server must request the scram-sha-256 authentication method; otherwise, the connection will fail. The remote server can be of any PostgreSQL version that supports SCRAM. Support for use_scram_passthrough is only required on the client side (FDW side). The user mapping password is not used. The server running postgres_fdw and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on postgres_fdw to authenticate on the foreign server (same salt and iterations, not merely the same password). As a corollary, if FDW connections to multiple hosts are to be made, for example for partitioned foreign tables/sharding, then all hosts must have identical SCRAM secrets for the users involved. The current session on the PostgreSQL instance that makes the outgoing FDW connections also must also use SCRAM authentication for its incoming client connection. (Hence “ pass-through ” : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.","name":"use_scram_passthrough"}],"title":"Documented options"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
