{"Entry":{"collection":"fdw","key":"postgres_fdw","name":"postgres_fdw","aliases":[],"metadata":{"aliases":[],"category":"Remote PostgreSQL","content_hash":"508c923290815097efdade63f651f1fa196d04e4b5396a864eb15461f7466418","derived_content_hash":"ac89e19afec2bb005a68255ad7a6e1e3cdf5c2bbcd4b2133ff844c187e950922","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."],"description_zh":"postgres_fdw 模块提供外部数据包装器 postgres_fdw ，可用于访问存储在外部 PostgreSQL 服务器中的数据。 本模块提供的功能与较旧的 dblink 模块在很大程度上重叠。但 postgres_fdw 为访问远程表提供了更透明且符合标准的语法，并且在许多情况下性能更好。 要准备通过 postgres_fdw 进行远程访问： 现在，只需对外部表执行 SELECT ，即可访问其底层远程表中存储的数据。也可以使用 INSERT 、 UPDATE 、 DELETE 、 COPY 或 TRUNCATE 修改远程表。（当然，在用户映射中指定的远程用户必须拥有执行这些操作的权限。）","description_zh_html":"\u003cp\u003e外部数据包装器 postgres_fdw。\u003c/p\u003e\u003ch3\u003e同版本中文手册节选\u003c/h3\u003e\u003cp\u003e\n\u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 模块提供外部数据包装器\n  \u003ccode class=\"literal\"\u003epostgres_fdw\u003c/code\u003e，可用于访问存储在外部\n  \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 服务器中的数据。\n \u003c/p\u003e\u003cp\u003e\n  本模块提供的功能与较旧的 \u003ca class=\"xref\" href=\"/zh/docs/18/dblink.html\"\u003edblink\u003c/a\u003e 模块在很大程度上重叠。但 \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 为访问远程表提供了更透明且符合标准的语法，并且在许多情况下性能更好。\n \u003c/p\u003e\u003cp\u003e\n  要准备通过 \u003ccode class=\"filename\"\u003epostgres_fdw\u003c/code\u003e 进行远程访问：\n  \u003c/p\u003e\u003cp\u003e\n  现在，只需对外部表执行 \u003ccode class=\"command\"\u003eSELECT\u003c/code\u003e，即可访问其底层远程表中存储的数据。也可以使用 \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 或\n  \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e 修改远程表。（当然，在用户映射中指定的远程用户必须拥有执行这些操作的权限。）\n \u003c/p\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/postgres-fdw.html\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","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"}],"facts_zh":[{"label":"接口类别","value":"外部数据包装器"},{"label":"处理函数或例程","value":"postgres_fdw_handler"},{"label":"记录的回调","value":"36"},{"label":"数据源","value":"远程 PostgreSQL 服务器"}],"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"}],"sections_zh":[{"paragraphs":["矩阵记录此源码构建实际注册的回调。注册表明实现了相应接口钩子；操作是否允许还取决于选项、查询形式、权限和提供方规则。","下方保留同版本完整手册，包括配置、约束和示例。不声称已进行运行时能力测试。"],"title":"接口与能力边界"},{"paragraphs":["postgres_fdw 支持异步执行，它可以并发运行 Append 节点的多个部分，而不是串行运行，以提高性能。可以使用以下选项控制这种执行方式："],"title":"异步执行选项"},{"paragraphs":["如“事务管理”一节所述，在 postgres_fdw 中，事务是通过创建对应的远程事务来管理的，子事务则通过创建对应的远程子事务来管理。当当前本地事务涉及多个远程事务时，默认情况下， postgres_fdw 会在本地事务提交或中止时串行提交或中止这些远程事务。当当前本地子事务涉及多个远程子事务时，默认情况下， postgres_fdw 也会在本地子事务提交或中止时串行提交或中止这些远程子事务。使用以下选项可以改善性能：","如果启用了这些选项的多个外部服务器参与同一个本地事务，那么在本地事务提交或中止时，这些外部服务器上的多个远程事务会跨服务器并行提交或中止。","启用这些选项后，若某个外部服务器涉及很多远程事务，则在本地事务提交或中止时，该外部服务器上的性能可能会受到负面影响。"],"title":"事务管理选项"},{"paragraphs":["在引用某个外部服务器上任意远程表的查询期间，如果当前本地事务尚未在该远程服务器上打开对应的事务， postgres_fdw 就会在该远程服务器上打开一个事务。本地事务提交或中止时，远程事务也会提交或中止。保存点也会通过创建对应的远程保存点进行类似管理。","当本地事务的隔离级别为 SERIALIZABLE 时，远程事务使用 SERIALIZABLE ；否则使用 REPEATABLE READ 隔离级别。这一选择确保如果一个查询在远程服务器上执行多次表扫描，所有扫描都能获得快照一致的结果。其结果是，同一事务中的后续查询会看到来自远程服务器的相同数据，即使远程服务器由于其他活动正在发生并发更新。对于使用 SERIALIZABLE 或 REPEATABLE READ 隔离级别的本地事务，这种行为本来就符合预期；但对于 READ COMMITTED 本地事务，则可能令人意外。未来的 PostgreSQL 版本可能会修改这些规则。","请注意， postgres_fdw 当前不支持为两阶段提交预备远程事务。"],"title":"事务管理"},{"paragraphs":["postgres_fdw 会尽力优化远程查询，以减少从外部服务器传输的数据量。这是通过将查询的 WHERE 子句发送到远程服务器执行，以及不获取当前查询不需要的表列来实现的。为降低查询被错误执行的风险，只有当 WHERE 子句使用的所有数据类型、操作符和函数都是内置的，或属于外部服务器 extensions 选项列出的扩展时，才会将该子句发送到远程服务器。这类子句中的操作符和函数还必须是 IMMUTABLE 。对于 UPDATE 或 DELETE 查询， postgres_fdw 会在查询中不存在无法发送到远程服务器的 WHERE 子句、没有本地连接操作、目标表上没有行级本地 BEFORE 或 AFTER 触发器或存储生成列，也没有来自父视图的 CHECK OPTION 约束时，尝试将整个查询发送到远程服务器以优化执行。在 UPDATE 中，为了降低查询被错误执行的风险，赋给目标列的表达式也必须只使用内置数据类型、 IMMUTABLE 操作符或 IMMUTABLE 函数。","当 postgres_fdw 遇到同一外部服务器上的外部表之间的连接时，除非由于某种原因它认为分别从各表取回行会更高效，或者相关表引用受不同用户映射约束，否则会将整个连接发送到远程服务器。在发送 JOIN 子句时，它也会采取与前述 WHERE 子句相同的预防措施。","可以使用 EXPLAIN VERBOSE 查看实际发送给远程服务器执行的查询。"],"title":"远程查询优化"},{"paragraphs":["postgres_fdw 可用于访问 PostgreSQL 8.3 及更新的远程服务器；只读能力可追溯到 8.1。","一个限制是，postgres_fdw 通常认为外部表 WHERE 子句中的不可变内置函数和运算符可以安全地发送到远程服务器执行。因此，远程服务器所用版本之后才加入的内置函数也可能被发送过去，导致“function does not exist”或类似错误。可以通过改写查询绕过此问题，例如将外部表引用放入带 OFFSET 0 的子 SELECT 中，以此形成优化屏障，并将有问题的函数或运算符放在子 SELECT 外部。","另一个限制是，在外部表上执行 INSERT 语句并带有 ON CONFLICT DO NOTHING 子句时，远程服务器必须运行 PostgreSQL 9.5 或更高版本，因为更早版本不支持此特性。"],"title":"跨版本兼容性"},{"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":"核心源码中注册的实现"}],"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"}],"tables_zh":[{"columns":[{"key":"feature","label":"接口操作"},{"key":"state","label":"源码观察"},{"key":"callback","label":"回调"},{"key":"implementation","label":"实现"}],"key":"callbacks","rows":[{"callback":"IterateForeignScan","feature":"扫描数据行","implementation":"postgresIterateForeignScan","state":"已注册处理函数；适用条件限制"},{"callback":"ExecForeignInsert","feature":"INSERT","implementation":"postgresExecForeignInsert","state":"已注册处理函数；适用条件限制"},{"callback":"ExecForeignUpdate","feature":"UPDATE","implementation":"postgresExecForeignUpdate","state":"已注册处理函数；适用条件限制"},{"callback":"ExecForeignDelete","feature":"DELETE","implementation":"postgresExecForeignDelete","state":"已注册处理函数；适用条件限制"},{"callback":"ExecForeignTruncate","feature":"TRUNCATE","implementation":"postgresExecForeignTruncate","state":"已注册处理函数；适用条件限制"},{"callback":"GetForeignJoinPaths","feature":"连接路径下推","implementation":"postgresGetForeignJoinPaths","state":"已注册处理函数；适用条件限制"},{"callback":"GetForeignUpperPaths","feature":"上层路径，包括聚合","implementation":"postgresGetForeignUpperPaths","state":"已注册处理函数；适用条件限制"},{"callback":"ExecForeignBatchInsert","feature":"批量插入","implementation":"postgresExecForeignBatchInsert","state":"已注册处理函数；适用条件限制"},{"callback":"ForeignAsyncRequest","feature":"异步追加执行","implementation":"postgresForeignAsyncRequest","state":"已注册处理函数；适用条件限制"},{"callback":"ImportForeignSchema","feature":"导入模式","implementation":"postgresImportForeignSchema","state":"已注册处理函数；适用条件限制"}],"title":"注册的接口处理函数"},{"columns":[{"key":"name","label":"选项"},{"key":"definition","label":"同版本定义"}],"key":"options","rows":[{"definition":"该选项可为外部表指定，用于给出在远程服务器上为该外部表使用的模式名。如果省略，则使用外部表自身所在模式的名称。","name":"schema_name"},{"definition":"该选项可为外部表指定，用于给出在远程服务器上为该外部表使用的表名。如果省略，则使用外部表自身的名称。","name":"table_name"},{"definition":"该选项可为外部表的某个列指定，用于给出在远程服务器上为该列使用的列名。如果省略，则使用该列自身的名称。","name":"column_name"},{"definition":"该选项可为外部表或外部服务器指定，用于控制 postgres_fdw 是否发出远程 EXPLAIN 命令来获取代价估算。外部表上的设置会覆盖其所属服务器的设置，但只对该表生效。默认值为 false 。","name":"use_remote_estimate"},{"definition":"该选项可为外部服务器指定，是一个浮点值，会被加到该服务器上任何外部表扫描的估计启动代价中。它表示建立连接、在远程端解析并规划查询等额外开销。默认值为 100 。","name":"fdw_startup_cost"},{"definition":"该选项可为外部服务器指定，是一个浮点值，用作该服务器上外部表扫描的每个元组的额外代价。它表示服务器之间数据传输的额外开销。可以增大或减小该数值，以反映到远程服务器更高或更低的网络延迟。默认值为 0.2 。","name":"fdw_tuple_cost"},{"definition":"此选项可在外部表或外部服务器上设置，决定外部表 ANALYZE 是在远程采样，还是读取并传输全部数据后在本地采样。支持 off、random、system、bernoulli 和 auto。off 禁用远程采样，全部数据会传到本地后采样。random 使用 random() 函数在远程选择返回行；system 和 bernoulli 使用同名内置 TABLESAMPLE 方法。random 适用于所有远程服务器版本，TABLESAMPLE 仅从 9.5 起支持。默认值 auto 自动选择推荐方法，目前根据远程服务器版本选择 bernoulli 或 random。","name":"analyze_sampling"},{"definition":"该选项是一个以逗号分隔的 PostgreSQL 扩展名称列表，这些扩展必须在本地和远程服务器上都已安装且版本兼容。属于列出扩展且不可变的函数和操作符，将被视为可下推到远程服务器执行。该选项只能为外部服务器指定，不能按表指定。 使用 extensions 选项时， 确保所列扩展在本地和远程服务器上都存在且行为完全一致，属于用户自己的责任 。否则，远程查询可能失败或出现意外行为。","name":"extensions"},{"definition":"该选项指定 postgres_fdw 在每次取回操作中应获取的行数。它可为外部表或外部服务器指定。表上指定的选项会覆盖服务器上指定的选项。默认值为 100 。","name":"fetch_size"},{"definition":"此选项指定 postgres_fdw 每次插入操作应插入的行数，可在外部表或外部服务器上设置，表级设置覆盖服务器级设置，默认值为 1。实际一次插入的行数取决于列数和 batch_size。一个批次作为一条查询执行，而 postgres_fdw 用于连接远程服务器的 libpq 协议将单条查询的参数数限制为 65535。当列数乘以 batch_size 超出限制时，会调整 batch_size 以避免报错。此选项也适用于向外部表执行 COPY，实际一次复制的行数按类似方式确定，但受 COPY 实现限制，最多为 1000 行。","name":"batch_size"},{"definition":"该选项控制 postgres_fdw 是否允许为异步执行而并发扫描外部表。它可为外部表或外部服务器指定。表级选项会覆盖服务器级选项。默认值为 false 。 为了确保从外部服务器返回的数据保持一致，除非这些表使用不同的用户映射，否则对于同一外部服务器， postgres_fdw 只会打开一个连接，并且即使涉及多个外部表，也会顺序运行针对该服务器的所有查询。在这种情况下，禁用此选项以消除异步运行查询带来的开销，反而可能具有更好的性能。 即使 Append 节点同时包含同步执行和异步执行的子计划，也会应用异步执行。在这种情况下，如果异步子计划是使用 postgres_fdw 处理的，则在至少有一个同步子计划返回全部元组之前，不会返回异步子计划的元组，因为同步子计划执行时，异步子计划仍在等待发送给外部服务器的异步查询结果。这种行为在未来版本中可能会改变。","name":"async_capable"},{"definition":"该选项控制在本地事务提交时， postgres_fdw 是否并行提交该本地事务中在某个外部服务器上打开的远程事务。此设置也适用于远程子事务和本地子事务。该选项只能为外部服务器指定，不能按表指定。默认值为 false 。","name":"parallel_commit"},{"definition":"该选项控制在本地事务中止时， postgres_fdw 是否并行中止该本地事务中在某个外部服务器上打开的远程事务。此设置也适用于远程子事务和本地子事务。该选项只能为外部服务器指定，不能按表指定。默认值为 false 。","name":"parallel_abort"},{"definition":"该选项控制 postgres_fdw 是否允许使用 INSERT 、 UPDATE 和 DELETE 命令修改外部表。它可为外部表或外部服务器指定。表级选项会覆盖服务器级选项。默认值为 true 。 当然，如果远程表实际上不可更新，最终仍会报错。该选项的主要作用是允许在本地直接抛出错误，而无需查询远程服务器。但请注意， information_schema 视图会根据该选项的设置，将 postgres_fdw 外部表报告为可更新（或不可更新），而不会对远程服务器进行任何检查。","name":"updatable"},{"definition":"该选项控制 postgres_fdw 是否允许使用 TRUNCATE 命令截断外部表。它可为外部表或外部服务器指定。表级选项会覆盖服务器级选项。默认值为 true 。 当然，如果远程表实际上不可截断，最终仍会报错。该选项的主要作用是允许在本地直接抛出错误，而无需查询远程服务器。","name":"truncatable"},{"definition":"该选项控制从外部服务器导入的外部表定义中是否包含列的 COLLATE 选项。默认值为 true 。如果远程服务器的排序规则名称集合与本地服务器不同，则可能需要关闭此选项；如果远程服务器运行在不同操作系统上，这种情况尤其可能发生。不过，如果这样做，导入表列的排序规则就存在与底层数据不匹配的严重风险，从而导致查询行为异常。 即使将此参数设置为 true ，导入排序规则为远程服务器默认值的列仍可能有风险。这些列会以 COLLATE \"default\" 导入，这将选择本地服务器的默认排序规则，而它可能并不相同。","name":"import_collate"},{"definition":"该选项控制从外部服务器导入的外部表定义中是否包含列的 DEFAULT 表达式。默认值为 false 。如果启用此选项，需要警惕那些在本地服务器上的计算结果可能与远程服务器不同的默认值； nextval() 是常见的问题来源。如果导入的默认值表达式使用了本地不存在的函数或操作符，则整个 IMPORT 将失败。","name":"import_default"},{"definition":"该选项控制从外部服务器导入的外部表定义中是否包含列的 GENERATED 表达式。默认值为 true 。如果导入的生成表达式使用了本地不存在的函数或操作符，则整个 IMPORT 将失败。","name":"import_generated"},{"definition":"该选项控制从外部服务器导入的外部表定义中是否包含列的 NOT NULL 约束。默认值为 true 。","name":"import_not_null"},{"definition":"该选项控制 postgres_fdw 是否保持与外部服务器的连接处于打开状态，以便后续查询重用它们。该选项只能为外部服务器指定。默认值为 on 。如果设置为 off ，则到该外部服务器的所有连接都会在每个事务结束时被丢弃。","name":"keep_connections"},{"definition":"该选项控制 postgres_fdw 在连接到外部服务器时是否使用 SCRAM 透传认证。该选项可为外部服务器或用户映射指定。用户映射的设置会覆盖外部服务器的设置。使用 SCRAM 透传认证时， postgres_fdw 使用经 SCRAM Hash 处理的凭据，而不是明文用户密码连接远程服务器。这样可以避免在 PostgreSQL 系统目录中存储明文用户密码。 要使用 SCRAM 透传认证： 远程服务器必须请求 scram-sha-256 认证方法；否则连接将失败。 远程服务器可以是任何支持 SCRAM 的 PostgreSQL 版本。对 use_scram_passthrough 的支持只要求客户端一侧（FDW 侧）具备。 用户映射密码不会被使用。 运行 postgres_fdw 的服务器与远程服务器，必须针对用于在 postgres_fdw 上认证到外部服务器的该用户，拥有完全相同的 SCRAM 凭据（加密密码）（盐值和迭代次数都必须相同，而不仅仅是密码相同）。 因而，如果要建立到多个主机的 FDW 连接，例如用于分区外部表或分片，则所有主机都必须为相关用户保存完全相同的 SCRAM 凭据。 发起对外 FDW 连接的 PostgreSQL 实例中，当前会话的传入客户端连接也必须使用 SCRAM 认证。（因此称为 “ 透传 ” ：SCRAM 必须在进入和离开时都被使用。）这是 SCRAM 协议的技术要求。","name":"use_scram_passthrough"}],"title":"手册中的选项"}],"zh_from":{"authored_translation":"source-derived-identity","body_sha256":"629c37b4a96ce213f614e080dd8624a62ae04098e662e8f36d7a5b21674c36c8","kind":"same-version-chinese-manual-with-source-derived-identity","manual":{"anchor":"","build_id":107,"extraction":"concept-introduction","fragment_sha256":"37b55536f7b4495667fdedbd0e2ba55d1fbdae2e0d16ff9fa6fbd4246396041e","locale":"zh-Hans","page_key":"postgres-fdw.html","source_hash":"0b35978c0e7579e4ce668b2ed473bb3513b1fb0fa4012f303aa9ca0aa811a4b9","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/postgres-fdw.html","version":"18"},"runtime_rerun":false,"source_facts_revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}},"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":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
