{"kind": "fdw", "major": "18", "item": {"slug": "postgres_fdw", "name": "postgres_fdw", "name_zh": "Remote PostgreSQL", "category": "Remote PostgreSQL", "summary": "Accesses tables in remote PostgreSQL servers through foreign tables.", "aliases": [], "content_hash": "508c923290815097efdade63f651f1fa196d04e4b5396a864eb15461f7466418", "versions": {"10": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "27"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_not_null", "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 ."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=10", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=10", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 10.23 source archive", "label": "10.23", "major": "10", "channel": "historical", "revision": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9", "source_url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/10/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 10 English manual", "sha256": "a747d947f5992c7c8ae026de25f63149e52eb32368f05a615934b3712b078b4f"}, {"url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "line": 424, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:424", "sha256": "d332f8d20b63f75ef6dc84770db42ff25d75ad70b0f7d10fa9cffdaa3fc3fa7e", "archive_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}], "sections": [{"title": "Interface and capability boundaries", "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": "Transaction Management", "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": "Remote Query Optimization", "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 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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.34.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/10/dblink.html\" title=\"F.11.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/10/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/10/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/10/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/10/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/10/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, or <code class=\"command\">DELETE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.43.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/10/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"33.1.2.\u00a0Parameter Key Words\">Section\u00a033.1.2</a>, except that these options are not allowed:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code> and <code class=\"literal\">password</code> (specify these in a user mapping, instead)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/10/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code></span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.5.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.43.10.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.34.1.6.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/10/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> does support <code class=\"literal\">CHECK</code> 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 <code class=\"literal\">CHECK</code> constraint could lead to hard-to-detect errors in query optimization. So if you wish to import <code class=\"literal\">CHECK</code> constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of <code class=\"literal\">CHECK</code> constraints on foreign tables, see <a class=\"xref\" href=\"/docs/10/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are automatically excluded. Partitioned tables are imported, unless they are a partition of some other table. Since all data can be accessed through the partitioned table which is the root of the partitioning hierarchy, this approach should allow access to all the data without creating extra objects.</p>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.2.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server during the first query that uses a foreign table associated with the foreign server. This connection is kept and re-used for subsequent queries in the same session. However, if multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.3.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.4.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.5.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/10/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/10/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/10/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/10/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/10/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/10/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.6.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.7.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/10/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/10/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/10/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"xref\" href=\"/docs/10/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.43.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.34.8.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/10/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_not_null", "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 ."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "68e2e4e662f2970b9c6c5c6076ea877fb184518313f8003a84bf42e5576c5bb7", "runtime_verified": false}, "11": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "29"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_not_null", "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 ."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=11", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=11", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 11.22 source archive", "label": "11.22", "major": "11", "channel": "historical", "revision": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0", "source_url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/11/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 11 English manual", "sha256": "70ee6fc4b9de4de194776eae4387bfa7c0ac3fd36af528ba040d39a7bd242514"}, {"url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "line": 459, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:459", "sha256": "1f25278a46ee5704e52c01216e67b58bf193aac54e580a72fc940ad438a55338", "archive_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}], "sections": [{"title": "Interface and capability boundaries", "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": "Transaction Management", "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": "Remote Query Optimization", "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 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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.33.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/11/dblink.html\" title=\"F.10.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/11/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/11/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/11/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/11/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/11/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, or <code class=\"command\">COPY</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated later.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.42.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/11/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"34.1.2.\u00a0Parameter Key Words\">Section\u00a034.1.2</a>, except that these options are not allowed:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code> and <code class=\"literal\">password</code> (specify these in a user mapping, instead)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/11/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code></span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.5.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.6.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/11/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> does support <code class=\"literal\">CHECK</code> 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 <code class=\"literal\">CHECK</code> constraint could lead to hard-to-detect errors in query optimization. So if you wish to import <code class=\"literal\">CHECK</code> constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of <code class=\"literal\">CHECK</code> constraints on foreign tables, see <a class=\"xref\" href=\"/docs/11/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are automatically excluded. Partitioned tables are imported, unless they are a partition of some other table. Since all data can be accessed through the partitioned table which is the root of the partitioning hierarchy, this approach should allow access to all the data without creating extra objects.</p>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.2.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server during the first query that uses a foreign table associated with the foreign server. This connection is kept and re-used for subsequent queries in the same session. However, if multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.3.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.4.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.5.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/11/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/11/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/11/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/11/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/11/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/11/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.6.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.7.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/11/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/11/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/11/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"xref\" href=\"/docs/11/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.8.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/11/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_not_null", "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 ."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "368dceb807dd9fa860296a909e409eb5b96e479b7d7b4b11ce70233975f9ebb0", "runtime_verified": false}, "12": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "29"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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 ."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=12", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=12", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 12.22 source archive", "label": "12.22", "major": "12", "channel": "historical", "revision": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b", "source_url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/12/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 12 English manual", "sha256": "5b51447bd97bfb425ea233cbb954dd81e9801ce1b07e3a60ad7a199bf1455cd8"}, {"url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "line": 510, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:510", "sha256": "b7ef27b1fc1b9487cdef496a198ca00f2e21036ef9acdbd0b14c72f12298807f", "archive_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}], "sections": [{"title": "Interface and capability boundaries", "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": "Transaction Management", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.33.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/12/dblink.html\" title=\"F.10.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/12/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/12/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/12/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/12/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/12/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, or <code class=\"command\">COPY</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated later.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.42.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/12/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"33.1.2.\u00a0Parameter Key Words\">Section\u00a033.1.2</a>, except that these options are not allowed:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code> and <code class=\"literal\">password</code> (specify these in a user mapping, instead)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/12/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code></span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.5.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.6.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/12/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> does support <code class=\"literal\">CHECK</code> 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 <code class=\"literal\">CHECK</code> constraint could lead to hard-to-detect errors in query optimization. So if you wish to import <code class=\"literal\">CHECK</code> constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of <code class=\"literal\">CHECK</code> constraints on foreign tables, see <a class=\"xref\" href=\"/docs/12/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are automatically excluded. Partitioned tables are imported, unless they are a partition of some other table. Since all data can be accessed through the partitioned table which is the root of the partitioning hierarchy, this approach should allow access to all the data without creating extra objects.</p>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.2.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server during the first query that uses a foreign table associated with the foreign server. This connection is kept and re-used for subsequent queries in the same session. However, if multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.3.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.4.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.5.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/12/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/12/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/12/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/12/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/12/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/12/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.6.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.7.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/12/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/12/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/12/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"xref\" href=\"/docs/12/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.8.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/12/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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 ."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "871fd9c664077a02a0b6c9abd2a1bf0cc3d5614a0c9cdae3f7b6c2f325db8ebb", "runtime_verified": false}, "13": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "29"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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 ."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=13", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=13", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 13.23 source archive", "label": "13.23", "major": "13", "channel": "historical", "revision": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6", "source_url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/13/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 13 English manual", "sha256": "b5903b880f7181d861f6e66be0880adfcc5ca88233c5efd39bf2be3921ebc635"}, {"url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "line": 513, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:513", "sha256": "d673f22c777e76b736ba45afdc5bb80f99181434d4c4c030081d50a785d5ce93", "archive_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}], "sections": [{"title": "Interface and capability boundaries", "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": "Transaction Management", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.33.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/13/dblink.html\" title=\"F.10.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/13/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/13/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/13/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/13/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/13/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, or <code class=\"command\">COPY</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated later.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.42.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/13/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"33.1.2.\u00a0Parameter Key Words\">Section\u00a033.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping, instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc in the unix home directory of the system user the postgres server runs as. They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign server, is a numeric 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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/13/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code></span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.5.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.42.10.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.33.1.6.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/13/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> does support <code class=\"literal\">CHECK</code> 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 <code class=\"literal\">CHECK</code> constraint could lead to hard-to-detect errors in query optimization. So if you wish to import <code class=\"literal\">CHECK</code> constraints, you must do so manually, and you should verify the semantics of each one carefully. For more detail about the treatment of <code class=\"literal\">CHECK</code> constraints on foreign tables, see <a class=\"xref\" href=\"/docs/13/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are automatically excluded. Partitioned tables are imported, unless they are a partition of some other table. Since all data can be accessed through the partitioned table which is the root of the partitioning hierarchy, this approach should allow access to all the data without creating extra objects.</p>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.2.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server during the first query that uses a foreign table associated with the foreign server. This connection is kept and re-used for subsequent queries in the same session. However, if multiple user identities (user mappings) are used to access the foreign server, a connection is established for each user mapping.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.3.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.4.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.5.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/13/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/13/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/13/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/13/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/13/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/13/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.6.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.7.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/13/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/13/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/13/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"xref\" href=\"/docs/13/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.42.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.33.8.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/13/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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_tuple_cost", "definition": "This option, which can be specified for a foreign server, is a numeric 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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "updatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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 ."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExplainDirectModify": "postgresExplainDirectModify", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "871fd9c664077a02a0b6c9abd2a1bf0cc3d5614a0c9cdae3f7b6c2f325db8ebb", "runtime_verified": false}, "14": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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."}, {"name": "async_capable", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=14", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=14", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 14.24 source archive", "label": "14.24", "major": "14", "channel": "stable", "revision": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897", "source_url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/14/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 14 English manual", "sha256": "60090e77bd3d8853b329bfc06e9ffd378163a0acd6e06e029ce5eb04c7922d4b"}, {"url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "line": 554, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:554", "sha256": "8c3f9c8757488fd4128b26a1536f015c69b3d5804ed40560e7c4210624abccc1", "archive_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.35.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/14/dblink.html\" title=\"F.10.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/14/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/14/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/14/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/14/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/14/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.44.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/14/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"34.1.2.\u00a0Parameter Key Words\">Section\u00a034.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping, instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc in the unix home directory of the system user the postgres server runs as. They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code></span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code></span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code></span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/14/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code></span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code></span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.5.\u00a0Asynchronous Execution Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.6.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.8\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.7.\u00a0Truncatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.9\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.8.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/14/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code></span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/14/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/14/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.44.11.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.35.1.9.\u00a0Connection Management Options</h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">keep_connections</code></span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.2.\u00a0Functions</h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</code></span></dt>\n<dd>\n<p>This function returns the foreign server names of all the open connections that <code class=\"filename\">postgres_fdw</code> established from the local session to the foreign servers. It also returns whether each connection is valid or not. <code class=\"literal\">false</code> is returned if the foreign server connection is used in the current local transaction but its foreign server or user mapping is changed or dropped (Note that server name of an invalid connection will be <code class=\"literal\">NULL</code> if the server is dropped), and then such invalid connection will be closed at the end of that transaction. <code class=\"literal\">true</code> is returned otherwise. If there are no open connections, no record is returned. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;\n server_name | valid \n-------------+-------\n loopback1   | t\n loopback2   | f\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect \n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all \n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.3.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.4.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.5.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.6.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/14/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/14/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/14/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/14/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/14/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/14/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.7.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.18\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.8.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/14/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/14/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/14/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/14/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.44.19\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.35.9.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/14/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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."}, {"name": "async_capable", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e327115bd7f57a8f520ccd0d811b9efedf52d040b03efbe8a94c24189fc0de63", "runtime_verified": false}, "15": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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."}, {"name": "async_capable", "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": "parallel_commit", "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 . If multiple foreign servers with this option enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed in parallel across those foreign servers when the local transaction is committed. When this option is enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed."}, {"name": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=15", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=15", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 15.19 source archive", "label": "15.19", "major": "15", "channel": "stable", "revision": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89", "source_url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/15/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 15 English manual", "sha256": "37cf2557c2a6bcdd5d9b182c71b3ccc1a29b44793f833adce54a20d7e8f449bd"}, {"url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "line": 554, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:554", "sha256": "53934582837739133ef39fe04cb50bf5038d90394743cc72d869b00d84dbbfa4", "archive_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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 those remote transactions serially when the local transaction is committed. When multiple remote subtransactions are involved in the current local subtransaction, by default postgres_fdw commits those remote subtransactions serially when the local subtransaction is committed. Performance can be improved with the following option:"]}, {"title": "Transaction Management", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.38.\u00a0postgres_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/15/dblink.html\" title=\"F.12.\u00a0dblink\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/15/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/15/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/15/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/15/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/15/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"id-1.11.7.47.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.1.\u00a0FDW Options of postgres_fdw</h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.2\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.1.\u00a0Connection Options</h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/15/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"34.1.2.\u00a0Parameter Key Words\">Section\u00a034.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping, instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/15/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/15/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Only superusers may connect to foreign servers without password authentication, so always specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.3\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.2.\u00a0Object Name Options</h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.4\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.3.\u00a0Cost Estimation Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/15/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.5\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.4.\u00a0Remote Execution Options</h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.6\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.5.\u00a0Asynchronous Execution Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.7\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.6.\u00a0Transaction Management Options</h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits those remote transactions serially when the local transaction is committed. When multiple remote subtransactions are involved in the current local subtransaction, by default <code class=\"filename\">postgres_fdw</code> commits those remote subtransactions serially when the local subtransaction is committed. Performance can be improved with the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>If multiple foreign servers with this option enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed in parallel across those foreign servers when the local transaction is committed.</p>\n<p>When this option is enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.8\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.7.\u00a0Updatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.9\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.8.\u00a0Truncatability Options</h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.10\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.9.\u00a0Importing Options</h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/15/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/15/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/15/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"id-1.11.7.47.11.11\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.10.\u00a0Connection Management Options</h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.12\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.2.\u00a0Functions</h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</code></span></dt>\n<dd>\n<p>This function returns the foreign server names of all the open connections that <code class=\"filename\">postgres_fdw</code> established from the local session to the foreign servers. It also returns whether each connection is valid or not. <code class=\"literal\">false</code> is returned if the foreign server connection is used in the current local transaction but its foreign server or user mapping is changed or dropped (Note that server name of an invalid connection will be <code class=\"literal\">NULL</code> if the server is dropped), and then such invalid connection will be closed at the end of that transaction. <code class=\"literal\">true</code> is returned otherwise. If there are no open connections, no record is returned. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;\n server_name | valid\n-------------+-------\n loopback1   | t\n loopback2   | f\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.13\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.3.\u00a0Connection Management</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.14\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.4.\u00a0Transaction Management</h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.15\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.5.\u00a0Remote Query Optimization</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.16\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.6.\u00a0Remote Query Execution Environment</h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/15/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/15/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/15/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/15/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/15/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/15/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.17\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.7.\u00a0Cross-Version Compatibility</h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.18\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.8.\u00a0Configuration Parameters</h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span></dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/15/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters and anything other than printable ASCII characters will be replaced with question marks (<code class=\"literal\">?</code>). See <a class=\"xref\" href=\"/docs/15/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/15/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/15/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.19\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.9.\u00a0Examples</h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/15/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/15/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/15/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/15/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"id-1.11.7.47.20\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.10.\u00a0Author</h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/15/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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."}, {"name": "async_capable", "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": "parallel_commit", "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 . If multiple foreign servers with this option enabled are involved in a local transaction, multiple remote transactions on those foreign servers are committed in parallel across those foreign servers when the local transaction is committed. When this option is enabled, a foreign server with many remote transactions may see a negative performance impact when the local transaction is committed."}, {"name": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "411085e71fe8ddc2c8a938b4fa405a9bb8dacdf0d623407308ae18e89cef010c", "runtime_verified": false}, "16": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=16", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=16", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 16.15 source archive", "label": "16.15", "major": "16", "channel": "stable", "revision": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed", "source_url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/16/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 16 English manual", "sha256": "22819913728e40d3730a8aba8a5243fb61b698dc907426a3572c0b641aceb6a0"}, {"url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "line": 554, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:554", "sha256": "844d4743c4ab73e586921518e1ace1f2ef5f5c66c7f49769b1ee865dd964af7c", "archive_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.38.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/16/dblink.html\" title=\"F.12.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/16/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/16/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/16/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/16/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/16/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/16/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"34.1.2.\u00a0Parameter Key Words\">Section\u00a034.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping, instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/16/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/16/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.01</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/16/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following option controls how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/16/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/16/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/16/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</code></span></dt>\n<dd>\n<p>This function returns the foreign server names of all the open connections that <code class=\"filename\">postgres_fdw</code> established from the local session to the foreign servers. It also returns whether each connection is valid or not. <code class=\"literal\">false</code> is returned if the foreign server connection is used in the current local transaction but its foreign server or user mapping is changed or dropped (Note that server name of an invalid connection will be <code class=\"literal\">NULL</code> if the server is dropped), and then such invalid connection will be closed at the end of that transaction. <code class=\"literal\">true</code> is returned otherwise. If there are no open connections, no record is returned. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;\n server_name | valid\n-------------+-------\n loopback1   | t\n loopback2   | f\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.4.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.5.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.6.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/16/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/16/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/16/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/16/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/16/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/16/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.7.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.8.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/16/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/16/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/16/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/16/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/16/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.9.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/16/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/16/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/16/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/16/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.10.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/16/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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.01 ."}, {"name": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "77fccbacd6d7dc405d025bfce572f0544dc46f545865cdd135b2216a188e48de", "runtime_verified": false}, "17": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=17", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=17", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 17.11 source archive", "label": "17.11", "major": "17", "channel": "stable", "revision": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979", "source_url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/17/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 17 English manual", "sha256": "af9a729e6545284286c7d7f43eed9764147340f90d498de625ad057e98b0ed29"}, {"url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "line": 554, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:554", "sha256": "7adb379ebb4217c716a19ff4541e79ac284799c8488f59d70ec3f885cb3ea487", "archive_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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 ."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.36.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/17/dblink.html\" title=\"F.11.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/17/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/17/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/17/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/17/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/17/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/17/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2.\u00a0Parameter Key Words\">Section\u00a032.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/17/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/17/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.2</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/17/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following option controls how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/17/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/17/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/17/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.36.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_get_connections(OUT server_name text, OUT valid boolean) returns setof record</code></span></dt>\n<dd>\n<p>This function returns the foreign server names of all the open connections that <code class=\"filename\">postgres_fdw</code> established from the local session to the foreign servers. It also returns whether each connection is valid or not. <code class=\"literal\">false</code> is returned if the foreign server connection is used in the current local transaction but its foreign server or user mapping is changed or dropped (Note that server name of an invalid connection will be <code class=\"literal\">NULL</code> if the server is dropped), and then such invalid connection will be closed at the end of that transaction. <code class=\"literal\">true</code> is returned otherwise. If there are no open connections, no record is returned. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT * FROM postgres_fdw_get_connections() ORDER BY 1;\n server_name | valid\n-------------+-------\n loopback1   | t\n loopback2   | f\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.4.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.5.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.6.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/17/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/17/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/17/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/17/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/17/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/17/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.7.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1. A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.8.\u00a0Wait Events </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can report the following wait events under the wait event type <code class=\"literal\">Extension</code>:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwCleanupResult</code></span></dt>\n<dd>\n<p>Waiting for transaction abort on remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwConnect</code></span></dt>\n<dd>\n<p>Waiting to establish a connection to a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwGetResult</code></span></dt>\n<dd>\n<p>Waiting to receive the results of a query from a remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.9.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/17/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/17/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/17/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/17/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/17/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.10.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/17/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/17/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/17/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/17/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.36.11.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/17/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "25282118ab4029d89b6fa7885ee7b60180d7a2cba8b128942ae84bc3aaadc228", "runtime_verified": false}, "18": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=18", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=18", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 18.6 source archive", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/18/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 18 English manual", "sha256": "a7833ebac1e9581de25695443eaec67d16d32ef33107783cdfb940fefa5f66a3"}, {"url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "line": 557, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:557", "sha256": "5f61f89fc1f9d67a204c47fd993db575b2d619449e5238b536b9fb1877037db6", "archive_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.38.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/18/dblink.html\" title=\"F.11.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/18/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2.\u00a0Parameter Key Words\">Section\u00a032.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see <a class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16.\u00a0The Password File\">Section\u00a032.16</a>.) They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.2</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following option controls how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n<dt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"><span class=\"term\"><code class=\"literal\">use_scram_passthrough</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>To use SCRAM pass-through authentication:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The remote server must request the <code class=\"literal\">scram-sha-256</code> authentication method; otherwise, the connection will fail.</p>\n</li>\n<li class=\"listitem\">\n<p>The remote server can be of any PostgreSQL version that supports SCRAM. Support for <code class=\"literal\">use_scram_passthrough</code> is only required on the client side (FDW side).</p>\n</li>\n<li class=\"listitem\">\n<p>The user mapping password is not used.</p>\n</li>\n<li class=\"listitem\">\n<p>The server running <code class=\"filename\">postgres_fdw</code> and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on <code class=\"filename\">postgres_fdw</code> to authenticate on the foreign server (same salt and iterations, not merely the same password).</p>\n<p>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.</p>\n</li>\n<li class=\"listitem\">\n<p>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 <span class=\"quote\">\u201c<span class=\"quote\">pass-through</span>\u201d</span>: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.</p>\n</li>\n</ul>\n</div>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_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</code></span></dt>\n<dd>\n<p>This 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.</p>\n<p>If <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">true</code>, the function checks the status of each connection and shows the result in the <code class=\"literal\">closed</code> column. This feature is currently available only on systems that support the non-standard <code class=\"symbol\">POLLRDHUP</code> extension to the <code class=\"symbol\">poll</code> 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 <code class=\"literal\">used_in_xact</code> and <code class=\"literal\">closed</code> are <code class=\"literal\">true</code>.</p>\n<p>Example usage of the function:</p>\n<pre class=\"screen\">postgres=# 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</pre>\n<p>The output columns are described in <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table\u00a0F.28.\u00a0postgres_fdw_get_connections Output Columns\">Table\u00a0F.28</a>.</p>\n<div class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\">\n<p class=\"title\"><strong>Table\u00a0F.28.\u00a0<code class=\"function\">postgres_fdw_get_connections</code> Output Columns</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n<thead>\n<tr>\n<th>Column</th>\n<th>Type</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"structfield\">server_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>The foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">user_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>Name of the local user mapped to the foreign server of this connection, or <code class=\"literal\">public</code> 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 <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">valid</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>False 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.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">used_in_xact</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is used in the current transaction.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">closed</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is closed, false otherwise. <code class=\"literal\">NULL</code> is returned if <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">false</code> or if the connection status check is not available on this platform.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">remote_backend_pid</code></td>\n<td><code class=\"type\">int4</code></td>\n<td>Process ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with <code class=\"literal\">closed</code> set to <code class=\"literal\">true</code>), this still shows the process ID of the terminated backend.</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.4.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.5.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.6.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.7.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1.</p>\n<p>A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n<p>Another limitation is that when executing <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause on a foreign table, the remote server must be running <span class=\"productname\">PostgreSQL</span> 9.5 or later, as earlier versions do not support this feature.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.8.\u00a0Wait Events </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can report the following wait events under the wait event type <code class=\"literal\">Extension</code>:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwCleanupResult</code></span></dt>\n<dd>\n<p>Waiting for transaction abort on remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwConnect</code></span></dt>\n<dd>\n<p>Waiting to establish a connection to a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwGetResult</code></span></dt>\n<dd>\n<p>Waiting to receive the results of a query from a remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.9.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.10.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.11.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/18/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "b8cfe64df86ef92c7aa383c99b1ce6ddc0c195b32004bf9a4ec0ea46bb7e9ba8", "runtime_verified": false}, "19": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "37"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "import_stats", "definition": "This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' n_distinct option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, it is the user's responsibility to ensure that the existing statistics for the remote table are up-to-date. The default is false . If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled. Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol. The foreign server must not be used for subscription connections (see Section F.40.4 )."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=19", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=19", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 19beta4 source archive", "label": "19beta4", "major": "19", "channel": "preview", "revision": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86", "source_url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/19/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 19 English manual", "sha256": "b54c9019efc9422022fac729e2c7a784cef59246af38ea90a385994b42818519"}, {"url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "line": 650, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:650", "sha256": "fc9ada0efad0c84b8cbd8e2a1d788853b7e060cf22489e4724a78da67348333e", "archive_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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.", "The remote transaction is opened in the same read/write mode as the local transaction: if the local transaction is READ ONLY , the remote transaction is opened in READ ONLY mode, otherwise it is opened in READ WRITE mode. (This rule is also applied to remote and local subtransactions.) Note that this does not prevent login triggers executed on the remote server from writing.", "The remote transaction is also opened in the same deferrable mode as the local transaction: if the local transaction is DEFERRABLE , the remote transaction is opened in DEFERRABLE mode, otherwise it is opened in NOT DEFERRABLE mode.", "Note that it is currently not supported by postgres_fdw to prepare the remote transaction for two-phase commit."]}, {"title": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\troutine->ImportForeignStatistics = postgresImportForeignStatistics;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ImportForeignStatistics": "postgresImportForeignStatistics", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.40.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/19/dblink.html\" title=\"F.11.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/19/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/19/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/19/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/19/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/19/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO SELECT/UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/19/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2.\u00a0Parameter Key Words\">Section\u00a032.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/19/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/19/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see <a class=\"xref\" href=\"/docs/19/libpq-pgpass.html\" title=\"32.16.\u00a0The Password File\">Section\u00a032.16</a>.) They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.2</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/19/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following options control how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_stats</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' <code class=\"literal\">n_distinct</code> option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> to ensure that the existing statistics for the remote table are up-to-date. The default is <code class=\"literal\">false</code>.</p>\n<p>If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled.</p>\n<p>Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/19/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/19/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/19/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n<dt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"><span class=\"term\"><code class=\"literal\">use_scram_passthrough</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>To use SCRAM pass-through authentication:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The remote server must request the <code class=\"literal\">scram-sha-256</code> authentication method; otherwise, the connection will fail.</p>\n</li>\n<li class=\"listitem\">\n<p>The remote server can be of any PostgreSQL version that supports SCRAM. Support for <code class=\"literal\">use_scram_passthrough</code> is only required on the client side (FDW side).</p>\n</li>\n<li class=\"listitem\">\n<p>The user mapping password is not used.</p>\n</li>\n<li class=\"listitem\">\n<p>The server running <code class=\"filename\">postgres_fdw</code> and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on <code class=\"filename\">postgres_fdw</code> to authenticate on the foreign server (same salt and iterations, not merely the same password).</p>\n<p>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.</p>\n</li>\n<li class=\"listitem\">\n<p>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 <span class=\"quote\">\u201c<span class=\"quote\">pass-through</span>\u201d</span>: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.</p>\n</li>\n<li class=\"listitem\">\n<p>The foreign server must not be used for subscription connections (see <a class=\"xref\" href=\"/docs/19/postgres-fdw.html#POSTGRES-FDW-SERVER-SUBSCRIPTION\" title=\"F.40.4.\u00a0Subscription Management\">Section\u00a0F.40.4</a>).</p>\n</li>\n</ul>\n</div>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_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</code></span></dt>\n<dd>\n<p>This 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.</p>\n<p>If <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">true</code>, the function checks the status of each connection and shows the result in the <code class=\"literal\">closed</code> column. This feature is currently available only on systems that support the non-standard <code class=\"symbol\">POLLRDHUP</code> extension to the <code class=\"symbol\">poll</code> 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 <code class=\"literal\">used_in_xact</code> and <code class=\"literal\">closed</code> are <code class=\"literal\">true</code>.</p>\n<p>Example usage of the function:</p>\n<pre class=\"screen\">postgres=# 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</pre>\n<p>The output columns are described in <a class=\"xref\" href=\"/docs/19/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table\u00a0F.29.\u00a0postgres_fdw_get_connections Output Columns\">Table\u00a0F.29</a>.</p>\n<div class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\">\n<p class=\"title\"><strong>Table\u00a0F.29.\u00a0<code class=\"function\">postgres_fdw_get_connections</code> Output Columns</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n<thead>\n<tr>\n<th>Column</th>\n<th>Type</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"structfield\">server_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>The foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">user_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>Name of the local user mapped to the foreign server of this connection, or <code class=\"literal\">public</code> 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 <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">valid</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>False 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.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">used_in_xact</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is used in the current transaction.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">closed</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is closed, false otherwise. <code class=\"literal\">NULL</code> is returned if <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">false</code> or if the connection status check is not available on this platform.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">remote_backend_pid</code></td>\n<td><code class=\"type\">int4</code></td>\n<td>Process ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with <code class=\"literal\">closed</code> set to <code class=\"literal\">true</code>), this still shows the process ID of the terminated backend.</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-SERVER-SUBSCRIPTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.4.\u00a0Subscription Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports subscription connections using the same options described in <a class=\"xref\" href=\"/docs/19/postgres-fdw.html#POSTGRES-FDW-OPTIONS-CONNECTION\" title=\"F.40.1.1.\u00a0Connection Options\">Section\u00a0F.40.1.1</a>.</p>\n<p>For example, assuming the remote server <code class=\"literal\">foreign-host</code> has a publication <code class=\"literal\">testpub</code>:</p>\n<pre class=\"programlisting\">CREATE SERVER subscription_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foreign-host', dbname 'foreign_db');\nCREATE USER MAPPING FOR local_user SERVER subscription_server OPTIONS (user 'foreign_user', password 'password');\nCREATE SUBSCRIPTION my_subscription SERVER subscription_server PUBLICATION testpub;\n</pre>\n<p>To create a subscription, the user must be a member of the <a class=\"xref\" href=\"/docs/19/predefined-roles.html#PREDEFINED-ROLE-PG-CREATE-SUBSCRIPTION\">pg_create_subscription</a> role and have <code class=\"literal\">USAGE</code> privileges on the server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.5.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>The remote transaction is opened in the same read/write mode as the local transaction: if the local transaction is <code class=\"literal\">READ ONLY</code>, the remote transaction is opened in <code class=\"literal\">READ ONLY</code> mode, otherwise it is opened in <code class=\"literal\">READ WRITE</code> mode. (This rule is also applied to remote and local subtransactions.) Note that this does not prevent login triggers executed on the remote server from writing.</p>\n<p>The remote transaction is also opened in the same deferrable mode as the local transaction: if the local transaction is <code class=\"literal\">DEFERRABLE</code>, the remote transaction is opened in <code class=\"literal\">DEFERRABLE</code> mode, otherwise it is opened in <code class=\"literal\">NOT DEFERRABLE</code> mode.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.6.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.7.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/19/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/19/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/19/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/19/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/19/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/19/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.8.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1.</p>\n<p>A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n<p>Another limitation is that when executing <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause on a foreign table, the remote server must be running <span class=\"productname\">PostgreSQL</span> 9.5 or later, as earlier versions do not support this feature.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.9.\u00a0Wait Events </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can report the following wait events under the wait event type <code class=\"literal\">Extension</code>:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwCleanupResult</code></span></dt>\n<dd>\n<p>Waiting for transaction abort on a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwConnect</code></span></dt>\n<dd>\n<p>Waiting to establish a connection to a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwGetResult</code></span></dt>\n<dd>\n<p>Waiting to receive the results of a query from a remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.10.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/19/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/19/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/19/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/19/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/19/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.11.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/19/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/19/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/19/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/19/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.12.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/19/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "import_stats", "definition": "This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' n_distinct option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, it is the user's responsibility to ensure that the existing statistics for the remote table are up-to-date. The default is false . If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled. Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol. The foreign server must not be used for subscription connections (see Section F.40.4 )."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ImportForeignStatistics": "postgresImportForeignStatistics", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "979d5d561aadcb43a7175cdac42b9b3460c97a4ad5d7464e730ecb6404e60bbf", "runtime_verified": false}, "20": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "postgres_fdw_handler"}, {"label": "Recorded callbacks", "value": "37"}, {"label": "Data source", "value": "Remote PostgreSQL servers"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "import_stats", "definition": "This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' n_distinct option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, it is the user's responsibility to ensure that the existing statistics for the remote table are up-to-date. The default is false . If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled. Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol. The foreign server must not be used for subscription connections (see Section F.40.4 )."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=20", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=20", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 20devel source archive", "label": "20devel", "major": "20", "channel": "devel", "revision": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41", "source_url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "source_snapshot_utc": "26-Sep-2026 20:22"}, "sources": [{"url": "/docs/devel/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 20 English manual", "sha256": "f13b7a8122b3c8dcc9c37645f07c2b3835b6980cca4e153c574f67bb098269cb"}, {"url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "line": 680, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:680", "sha256": "a164315da627f8cbc12eb147ccefcd99ca488f4f5806d7b740349ed547646dcd", "archive_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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.", "The remote transaction is opened in the same read/write mode as the local transaction: if the local transaction is READ ONLY , the remote transaction is opened in READ ONLY mode, otherwise it is opened in READ WRITE mode. (This rule is also applied to remote and local subtransactions.) Note that this does not prevent login triggers executed on the remote server from writing.", "The remote transaction is also opened in the same deferrable mode as the local transaction: if the local transaction is DEFERRABLE , the remote transaction is opened in DEFERRABLE mode, otherwise it is opened in NOT DEFERRABLE mode.", "Note that it is currently not supported by postgres_fdw to prepare the remote transaction for two-phase commit."]}, {"title": "Remote Query Optimization", "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.", "An INNER JOIN between a foreign table and a set-returning function appearing as a FROM -list item can likewise be pushed down: the function call is absorbed into the remote query so that only rows matching the function's output are fetched. This is attempted only when the function is IMMUTABLE (so evaluating it on the remote server is guaranteed to produce the same result as evaluating it locally), its arguments and any restriction clauses on it are shippable, and none of the following disqualifying conditions applies: the join type is not INNER ; the function is used with WITH ORDINALITY ; the function returns a record type without an accompanying column definition list; or the function laterally references another relation at the same query level. A function argument that is a parameter from an enclosing query level is allowed and is transmitted to the remote server as a query parameter.", "The query that is actually sent to the remote server for execution can be examined using EXPLAIN VERBOSE ."]}, {"title": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\troutine->ImportForeignStatistics = postgresImportForeignStatistics;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ImportForeignStatistics": "postgresImportForeignStatistics", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.40.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/devel/dblink.html\" title=\"F.11.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/devel/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/devel/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/devel/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/devel/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/devel/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO SELECT/UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/devel/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2.\u00a0Parameter Key Words\">Section\u00a032.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/devel/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/devel/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see <a class=\"xref\" href=\"/docs/devel/libpq-pgpass.html\" title=\"32.15.\u00a0The Password File\">Section\u00a032.15</a>.) They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.2</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/devel/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following options control how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_stats</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' <code class=\"literal\">n_distinct</code> option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> to ensure that the existing statistics for the remote table are up-to-date. The default is <code class=\"literal\">false</code>.</p>\n<p>If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled.</p>\n<p>Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/devel/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/devel/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/devel/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.40.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n<dt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"><span class=\"term\"><code class=\"literal\">use_scram_passthrough</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>To use SCRAM pass-through authentication:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The remote server must request the <code class=\"literal\">scram-sha-256</code> authentication method; otherwise, the connection will fail.</p>\n</li>\n<li class=\"listitem\">\n<p>The remote server can be of any PostgreSQL version that supports SCRAM. Support for <code class=\"literal\">use_scram_passthrough</code> is only required on the client side (FDW side).</p>\n</li>\n<li class=\"listitem\">\n<p>The user mapping password is not used.</p>\n</li>\n<li class=\"listitem\">\n<p>The server running <code class=\"filename\">postgres_fdw</code> and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on <code class=\"filename\">postgres_fdw</code> to authenticate on the foreign server (same salt and iterations, not merely the same password).</p>\n<p>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.</p>\n</li>\n<li class=\"listitem\">\n<p>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 <span class=\"quote\">\u201c<span class=\"quote\">pass-through</span>\u201d</span>: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.</p>\n</li>\n<li class=\"listitem\">\n<p>The foreign server must not be used for subscription connections (see <a class=\"xref\" href=\"/docs/devel/postgres-fdw.html#POSTGRES-FDW-SERVER-SUBSCRIPTION\" title=\"F.40.4.\u00a0Subscription Management\">Section\u00a0F.40.4</a>).</p>\n</li>\n</ul>\n</div>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_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</code></span></dt>\n<dd>\n<p>This 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.</p>\n<p>If <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">true</code>, the function checks the status of each connection and shows the result in the <code class=\"literal\">closed</code> column. This feature is currently available only on systems that support the non-standard <code class=\"symbol\">POLLRDHUP</code> extension to the <code class=\"symbol\">poll</code> 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 <code class=\"literal\">used_in_xact</code> and <code class=\"literal\">closed</code> are <code class=\"literal\">true</code>.</p>\n<p>Example usage of the function:</p>\n<pre class=\"screen\">postgres=# 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</pre>\n<p>The output columns are described in <a class=\"xref\" href=\"/docs/devel/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table\u00a0F.29.\u00a0postgres_fdw_get_connections Output Columns\">Table\u00a0F.29</a>.</p>\n<div class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\">\n<p class=\"title\"><strong>Table\u00a0F.29.\u00a0<code class=\"function\">postgres_fdw_get_connections</code> Output Columns</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n<thead>\n<tr>\n<th>Column</th>\n<th>Type</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"structfield\">server_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>The foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">user_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>Name of the local user mapped to the foreign server of this connection, or <code class=\"literal\">public</code> 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 <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">valid</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>False 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.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">used_in_xact</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is used in the current transaction.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">closed</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is closed, false otherwise. <code class=\"literal\">NULL</code> is returned if <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">false</code> or if the connection status check is not available on this platform.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">remote_backend_pid</code></td>\n<td><code class=\"type\">int4</code></td>\n<td>Process ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with <code class=\"literal\">closed</code> set to <code class=\"literal\">true</code>), this still shows the process ID of the terminated backend.</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-SERVER-SUBSCRIPTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.4.\u00a0Subscription Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports subscription connections using the same options described in <a class=\"xref\" href=\"/docs/devel/postgres-fdw.html#POSTGRES-FDW-OPTIONS-CONNECTION\" title=\"F.40.1.1.\u00a0Connection Options\">Section\u00a0F.40.1.1</a>.</p>\n<p>For example, assuming the remote server <code class=\"literal\">foreign-host</code> has a publication <code class=\"literal\">testpub</code>:</p>\n<pre class=\"programlisting\">CREATE SERVER subscription_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foreign-host', dbname 'foreign_db');\nCREATE USER MAPPING FOR local_user SERVER subscription_server OPTIONS (user 'foreign_user', password 'password');\nCREATE SUBSCRIPTION my_subscription SERVER subscription_server PUBLICATION testpub;\n</pre>\n<p>To create a subscription, the user must be a member of the <a class=\"xref\" href=\"/docs/devel/predefined-roles.html#PREDEFINED-ROLE-PG-CREATE-SUBSCRIPTION\">pg_create_subscription</a> role and have <code class=\"literal\">USAGE</code> privileges on the server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.5.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>The remote transaction is opened in the same read/write mode as the local transaction: if the local transaction is <code class=\"literal\">READ ONLY</code>, the remote transaction is opened in <code class=\"literal\">READ ONLY</code> mode, otherwise it is opened in <code class=\"literal\">READ WRITE</code> mode. (This rule is also applied to remote and local subtransactions.) Note that this does not prevent login triggers executed on the remote server from writing.</p>\n<p>The remote transaction is also opened in the same deferrable mode as the local transaction: if the local transaction is <code class=\"literal\">DEFERRABLE</code>, the remote transaction is opened in <code class=\"literal\">DEFERRABLE</code> mode, otherwise it is opened in <code class=\"literal\">NOT DEFERRABLE</code> mode.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.6.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>An <code class=\"literal\">INNER JOIN</code> between a foreign table and a set-returning function appearing as a <code class=\"literal\">FROM</code>-list item can likewise be pushed down: the function call is absorbed into the remote query so that only rows matching the function's output are fetched. This is attempted only when the function is <code class=\"literal\">IMMUTABLE</code> (so evaluating it on the remote server is guaranteed to produce the same result as evaluating it locally), its arguments and any restriction clauses on it are shippable, and none of the following disqualifying conditions applies: the join type is not <code class=\"literal\">INNER</code>; the function is used with <code class=\"literal\">WITH ORDINALITY</code>; the function returns a <code class=\"type\">record</code> type without an accompanying column definition list; or the function laterally references another relation at the same query level. A function argument that is a parameter from an enclosing query level is allowed and is transmitted to the remote server as a query parameter.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.7.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/devel/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/devel/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/devel/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/devel/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/devel/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/devel/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.8.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1.</p>\n<p>A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n<p>Another limitation is that when executing <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause on a foreign table, the remote server must be running <span class=\"productname\">PostgreSQL</span> 9.5 or later, as earlier versions do not support this feature.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.9.\u00a0Wait Events </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can report the following wait events under the wait event type <code class=\"literal\">Extension</code>:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwCleanupResult</code></span></dt>\n<dd>\n<p>Waiting for transaction abort on a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwConnect</code></span></dt>\n<dd>\n<p>Waiting to establish a connection to a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwGetResult</code></span></dt>\n<dd>\n<p>Waiting to receive the results of a query from a remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.10.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/devel/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/devel/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/devel/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/devel/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/devel/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.11.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/devel/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/devel/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/devel/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/devel/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.40.12.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/devel/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "import_stats", "definition": "This option, which can be specified for a foreign table or a foreign server, determines if ANALYZE on a foreign table will instead attempt to fetch the existing statistics for the remote table, and import those statistics directly to the local server (without applying the foreign table columns' n_distinct option). If the attempt failed, statistics are collected by row sampling on the foreign table. This option is only useful if the remote table is one that can have regular statistics (tables, not inherited, and materialized views). When using this option, it is the user's responsibility to ensure that the existing statistics for the remote table are up-to-date. The default is false . If the foreign table is a partition of a partitioned table, analyzing the partitioned table will still result in row sampling on the foreign table regardless of this setting, though direct analysis of the foreign table would have attempted to fetch and import the remote statistics first if this option was enabled. Note that this option doesn't currently support the case where the remote table is (or was once) inherited. This is an implementation restriction that might be fixed in a future release."}, {"name": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol. The foreign server must not be used for subscription connections (see Section F.40.4 )."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ImportForeignStatistics": "postgresImportForeignStatistics", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "979d5d561aadcb43a7175cdac42b9b3460c97a4ad5d7464e730ecb6404e60bbf", "runtime_verified": false, "collection_tables": [{"key": "fdw-catalogue", "rows": [{"scope": "Wrapper framework", "checked": "2026-08-30", "version": "0.6.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/wrappers/", "text": "wrappers"}, "description": "Foreign data wrappers developed by Supabase"}, {"scope": "Wrapper framework", "checked": "2026-08-30", "version": "3.2", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/multicorn/", "text": "multicorn"}, "description": "Fetch foreign data in Python in your PostgreSQL server."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.5.2", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/odbc_fdw/", "text": "odbc_fdw"}, "description": "Foreign data wrapper for accessing remote databases using ODBC"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.2", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/jdbc_fdw/", "text": "jdbc_fdw"}, "description": "foreign-data wrapper for remote servers available over JDBC"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.3.0", "postgres": "15, 16, 17, 18", "extension": {"url": "/e/pgspider_ext/", "text": "pgspider_ext"}, "description": "foreign-data wrapper for remote PGSpider servers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "2.9.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/mysql_fdw/", "text": "mysql_fdw"}, "description": "Foreign data wrapper for querying a MySQL server"}, {"scope": "Primary documentation reviewed separately below", "checked": "2026-08-30", "version": "2.9.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "description": "foreign data wrapper for Oracle access"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "2.0.5", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/tds_fdw/", "text": "tds_fdw"}, "description": "Foreign data wrapper for querying a TDS database (Sybase or Microsoft SQL Server)"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "18.2.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/db2_fdw/", "text": "db2_fdw"}, "description": "foreign data wrapper for DB2 access"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "2.5.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/sqlite_fdw/", "text": "sqlite_fdw"}, "description": "SQLite Foreign Data Wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.4.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/pgbouncer_fdw/", "text": "pgbouncer_fdw"}, "description": "Extension for querying PgBouncer stats from normal SQL views & running pgbouncer commands from normal SQL functions"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/etcd_fdw/", "text": "etcd_fdw"}, "description": "Foreign data wrapper for etcd"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.6.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/informix_fdw/", "text": "informix_fdw"}, "description": "Foreign data wrapper for Informix access"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "2.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/nominatim_fdw/", "text": "nominatim_fdw"}, "description": "Nominatim Foreign Data Wrapper for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "5.5.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/mongo_fdw/", "text": "mongo_fdw"}, "description": "foreign data wrapper for MongoDB access"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/redis_fdw/", "text": "redis_fdw"}, "description": "Foreign data wrapper for querying a Redis server"}, {"scope": "Related messaging interface", "checked": "2026-08-30", "version": "0.0.1", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/redis/", "text": "redis"}, "description": "Send redis pub/sub messages to Redis from PostgreSQL Directly"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.3", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/kafka_fdw/", "text": "kafka_fdw"}, "description": "kafka Foreign Data Wrapper for CSV formatted messages"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "2.0.5", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/hdfs_fdw/", "text": "hdfs_fdw"}, "description": "foreign-data wrapper for remote hdfs servers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.4.2", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/firebird_fdw/", "text": "firebird_fdw"}, "description": "Foreign data wrapper for Firebird"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-27", "version": "3.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/rdf_fdw/", "text": "rdf_fdw"}, "description": "Foreign data wrapper for RDF triplestores over SPARQL endpoints"}, {"scope": "Related import/export interface", "checked": "2026-08-30", "version": "0.0.1", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/aws_s3/", "text": "aws_s3"}, "description": "aws_s3 postgres extension to import/export data from/to s3"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.5", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/log_fdw/", "text": "log_fdw"}, "description": "foreign-data wrapper for Postgres log file access"}, {"scope": "Related remote-query interface", "checked": "Not recorded", "version": "1.2", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/dblink/", "text": "dblink"}, "description": "connect to other PostgreSQL databases from within a database"}, {"scope": "Core interface; see versioned entry", "checked": "Not recorded", "version": "1.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/file_fdw/", "text": "file_fdw"}, "description": "foreign-data wrapper for flat file access"}, {"scope": "Core interface; see versioned entry", "checked": "Not recorded", "version": "1.1", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/postgres_fdw/", "text": "postgres_fdw"}, "description": "foreign-data wrapper for remote PostgreSQL servers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1", "postgres": "11, 12, 13", "extension": {"url": "/e/clickhousedb_fdw/", "text": "clickhousedb_fdw"}, "description": "ClickHouse foreign data wrapper with SELECT/INSERT support plus aggregate and join pushdown."}, {"scope": "Wrapper framework", "checked": "2026-08-30", "version": "1.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/holycorn/", "text": "holycorn"}, "description": "Ruby foreign data wrapper provider"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/json_fdw/", "text": "json_fdw"}, "description": "Foreign data wrapper for local and remote JSON document access."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.2", "postgres": "10, 11, 12, 13, 14, 15, 16", "extension": {"url": "/e/parquet_fdw/", "text": "parquet_fdw"}, "description": "Read-only foreign data wrapper for Apache Parquet files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.9", "postgres": "Unknown", "extension": {"url": "/e/www_fdw/", "text": "www_fdw"}, "description": "Foreign data wrapper for accessing web services from PostgreSQL."}, {"scope": "Related remote-query interface", "checked": "2026-08-30", "version": "1.0.11", "postgres": "Unknown", "extension": {"url": "/e/dblink_plus/", "text": "dblink_plus"}, "description": "Run SQL against external PostgreSQL, Oracle, MySQL, and SQLite databases from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "2.0", "postgres": "11, 12, 13, 14, 15", "extension": {"url": "/e/cassandra2_fdw/", "text": "cassandra2_fdw"}, "description": "Foreign data wrapper for querying Cassandra 2.x and newer from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "13", "extension": {"url": "/e/ch_fdw/", "text": "ch_fdw"}, "description": "Foreign data wrapper for federated access from PostgreSQL to ClickHouse."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/couchdb_fdw/", "text": "couchdb_fdw"}, "description": "Foreign data wrapper for querying CouchDB from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/dump_fdw/", "text": "dump_fdw"}, "description": "Foreign data wrapper for querying rows directly from PostgreSQL custom-format dump files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/file_fixed_length_fdw/", "text": "file_fixed_length_fdw"}, "description": "Foreign data wrapper for files with fixed-length fields."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0.1", "postgres": "Unknown", "extension": {"url": "/e/file_textarray_fdw/", "text": "file_textarray_fdw"}, "description": "Foreign data wrapper returning each text-file row as a text array."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.1.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/git_fdw/", "text": "git_fdw"}, "description": "PostgreSQL Git Foreign Data Wrapper"}, {"scope": "Wrapper development framework", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/go_fdw/", "text": "go_fdw"}, "description": "Experimental Go/cgo project template for building PostgreSQL foreign data wrappers."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/bigtable/", "text": "bigtable"}, "description": "Rust PostgreSQL FDW for Google Bigtable"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.2", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/griddb_fdw/", "text": "griddb_fdw"}, "description": "GridDB Foreign Data Wrapper for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/hello_fdw/", "text": "hello_fdw"}, "description": "foreign-data wrapper for hello world"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.3", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/influxdb_fdw/", "text": "influxdb_fdw"}, "description": "Foreign data wrapper for querying InfluxDB from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/jdbc2_fdw/", "text": "jdbc2_fdw"}, "description": "Experimental foreign data wrapper for JDBC-accessible databases with remote filter pushdown."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/kt_fdw/", "text": "kt_fdw"}, "description": "Foreign data wrapper for reading and writing Kyoto Tycoon key-value stores."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.1", "postgres": "Unknown", "extension": {"url": "/e/ldap_fdw/", "text": "ldap_fdw"}, "description": "Foreign data wrapper for querying LDAP servers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "4.1.2", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/osm_fdw/", "text": "osm_fdw"}, "description": "Foreign data wrapper for reading OpenStreetMap PBF files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "13", "extension": {"url": "/e/kv_fdw/", "text": "kv_fdw"}, "description": "Foreign data wrapper for key-value storage backed by RocksDB/VidarDB."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.4.1", "postgres": "Unknown", "extension": {"url": "/e/quasar_fdw/", "text": "quasar_fdw"}, "description": "quasar_fdw: push PostgreSQL queries down to Quasar-supported data backends"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.0", "postgres": "Unknown", "extension": {"url": "/e/s3_fdw/", "text": "s3_fdw"}, "description": "Foreign data wrapper for reading Amazon S3 files through PostgreSQL COPY format."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.1.0", "postgres": "Unknown", "extension": {"url": "/e/twitter_fdw/", "text": "twitter_fdw"}, "description": "Legacy foreign data wrapper for the retired unauthenticated Twitter Search API."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0", "postgres": "Unknown", "extension": {"url": "/e/monetdb_fdw/", "text": "monetdb_fdw"}, "description": "MonetDB foreign data wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "4.3.2-dev", "postgres": "10, 11, 12", "extension": {"url": "/e/neo4j-fdw/", "text": "neo4j-fdw"}, "description": "Multicorn-based foreign data wrapper and Cypher functions for Neo4j."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/neo4j_fdw/", "text": "neo4j_fdw"}, "description": "C foreign data wrapper for Neo4j Cypher query results."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/orc_fdw/", "text": "orc_fdw"}, "description": "Foreign data wrapper for reading ORC formatted files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "11, 12, 13", "extension": {"url": "/e/lsm/", "text": "lsm"}, "description": "RocksDB foreign data wrapper for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/oblivpg_fdw/", "text": "oblivpg_fdw"}, "description": "Oblivious foreign data wrapper for table access backed by trusted hardware and ORAM"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.10.2", "postgres": "Unknown", "extension": {"url": "/e/kadb_fdw/", "text": "kadb_fdw"}, "description": "Transactional Kafka foreign data wrapper for Arenadata DB and Greenplum"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "3.1", "postgres": "11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/cassandra_fdw/", "text": "cassandra_fdw"}, "description": "foreign-data wrapper for querying Cassandra 3+"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "12", "extension": {"url": "/e/db2odbc_fdw/", "text": "db2odbc_fdw"}, "description": "Foreign data wrapper for accessing IBM Db2 through an ODBC data source"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "4.0", "postgres": "13", "extension": {"url": "/e/hive_fdw/", "text": "hive_fdw"}, "description": "Foreign data wrapper for querying Apache Hive from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/lua_fdw/", "text": "lua_fdw"}, "description": "Lua Foreign Data Wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "10, 11, 12, 13, 14", "extension": {"url": "/e/ocgeo_fdw/", "text": "ocgeo_fdw"}, "description": "Foreign data wrapper for the OpenCageData API"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/douban_fdw/", "text": "douban_fdw"}, "description": "Foreign data wrapper for querying Douban public movie-ranking APIs"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.4.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/passwd-fdw/", "text": "passwd-fdw"}, "description": "Foreign data wrapper for Unix/Linux passwd and group databases."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/aerospike_fdw/", "text": "aerospike_fdw"}, "description": "Foreign Data Wrapper for Aerospike."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0.1", "postgres": "Unknown", "extension": {"url": "/e/file_fdw_program/", "text": "file_fdw_program"}, "description": "Backport of file_fdw PROGRAM support, exposing a file_fdw-like foreign data wrapper that reads from external commands."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "12, 13", "extension": {"url": "/e/greenplum_fdw/", "text": "greenplum_fdw"}, "description": "Foreign data wrapper for querying Greenplum from PostgreSQL using SERIALIZABLE remote transactions."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.2", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/treasuredata_fdw/", "text": "treasuredata_fdw"}, "description": "C foreign data wrapper backed by a Rust td-client bridge for querying and inserting Treasure Data datasets."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/tsf_fdw/", "text": "tsf_fdw"}, "description": "Golden Helix C foreign data wrapper for reading one or more TSF genomic data files as PostgreSQL foreign tables."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/tuple_fdw/", "text": "tuple_fdw"}, "description": "Proof-of-concept C foreign data wrapper for append-only, LZ4-compressed binary tuple files used as cold storage."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/wdb_fdw/", "text": "wdb_fdw"}, "description": "WhiteDB Foreign Data Wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/gtables_fdw/", "text": "gtables_fdw"}, "description": "Global tables across FDW API"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/hash_fdw/", "text": "hash_fdw"}, "description": "Shared-memory hash-table foreign data wrapper for storing and querying rows by a configured key."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/hba_fdw/", "text": "hba_fdw"}, "description": "Work-in-progress foreign data wrapper scaffold intended to expose pg_hba.conf through SQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/hbase_fdw/", "text": "hbase_fdw"}, "description": "Foreign data wrapper for querying HBase from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "12", "extension": {"url": "/e/pgc_fdw/", "text": "pgc_fdw"}, "description": "Access remote PostgreSQL tables through a postgres_fdw-derived wrapper with a FoundationDB-backed query cache"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/pglog/", "text": "pglog"}, "description": "PostgreSQL log via SQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "16, 17, 18", "extension": {"url": "/e/postgres_fdw_plus/", "text": "postgres_fdw_plus"}, "description": "Fork postgres_fdw to coordinate remote PostgreSQL transactions with optional two-phase commit and recovery helpers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/rasterdb/", "text": "rasterdb"}, "description": "rasterdb: filesystem-backed PostGIS raster foreign data wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/sybase_fdw/", "text": "sybase_fdw"}, "description": "C foreign data wrapper for accessing Sybase databases from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/template_fdw/", "text": "template_fdw"}, "description": "Foreign data wrapper for template tables that intentionally rejects SELECT and DML operations."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/dataclips/", "text": "dataclips"}, "description": "Archived, unfinished C prototype for querying Heroku Dataclips through a function and planned FDW."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "16", "extension": {"url": "/e/redis_link/", "text": "redis_link"}, "description": "Read-write PostgreSQL foreign data wrapper for Redis strings, hashes, and sets, with basic Redis Cluster support"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.3.3", "postgres": "14, 15, 16, 17", "extension": {"url": "/e/clerk_fdw/", "text": "clerk_fdw"}, "description": "Foreign data wrapper for querying the Clerk user-management API from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.2.1", "postgres": "14, 15, 16, 17", "extension": {"url": "/e/prometheus_fdw/", "text": "prometheus_fdw"}, "description": "A Rust/pgrx foreign data wrapper that queries Prometheus metrics through PostgreSQL foreign tables."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.0", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/lance/", "text": "lance"}, "description": "PostgreSQL FDW extension for reading and querying Lance format tables"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.5.5-rc.1", "postgres": "13, 14, 15, 16, 17, 18", "extension": {"url": "/e/pg_kalam/", "text": "pg_kalam"}, "description": "KalamDB PostgreSQL extension and FDW callback layer for SQL access to KalamDB."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.13.3", "postgres": "14, 15, 16, 17", "extension": {"url": "/e/orb_fdw/", "text": "orb_fdw"}, "description": "A foreign data wrapper for Orb"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.0", "postgres": "11, 12, 13, 14, 15", "extension": {"url": "/e/db721_fdw/", "text": "db721_fdw"}, "description": "Rust/pgrx foreign data wrapper for db721 files, developed for CMU 15-721 project data."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.2", "postgres": "14, 15, 16", "extension": {"url": "/e/prometheusfdw/", "text": "prometheusfdw"}, "description": "Queries Prometheus instant-vector data through a PostgreSQL foreign data wrapper."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.0", "postgres": "11, 12, 13, 14, 15", "extension": {"url": "/e/ebs_fdw/", "text": "ebs_fdw"}, "description": "Rust/pgrx foreign data wrapper for listing AWS EBS volumes through PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.4", "postgres": "11, 12, 13, 14, 15, 16, 17", "extension": {"url": "/e/clickhouse_fdw/", "text": "clickhouse_fdw"}, "description": "ClickHouse foreign data wrapper for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-11", "version": "1.0", "postgres": "10, 11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/cos_fdw/", "text": "cos_fdw"}, "description": "TencentDB PostgreSQL foreign data wrapper for reading CSV data from Tencent Cloud Object Storage (COS)."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.1", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/dynamodb_fdw/", "text": "dynamodb_fdw"}, "description": "Foreign data wrapper for querying and modifying Amazon DynamoDB tables from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-11", "version": "Not recorded", "postgres": "17, 18", "extension": {"url": "/e/external_search_fdw/", "text": "external_search_fdw"}, "description": "AlloyDB extension that provides a read-only foreign data wrapper for querying Elasticsearch data from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-12", "version": "1.0.0", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/obs_fdw/", "text": "obs_fdw"}, "description": "Huawei Cloud OBS foreign data wrapper extension listed for RDS PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-12", "version": "Not recorded", "postgres": "11, 14, 16", "extension": {"url": "/e/oss_fdw/", "text": "oss_fdw"}, "description": "Alibaba Cloud OSS foreign data wrapper for reading and writing OSS objects from PostgreSQL-compatible managed services."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.3", "postgres": "13, 14, 15, 16, 17", "extension": {"url": "/e/parquet_s3_fdw/", "text": "parquet_s3_fdw"}, "description": "Foreign data wrapper for accessing Parquet files on local filesystems and Amazon S3 from PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/scylla_fdw/", "text": "scylla_fdw"}, "description": "Foreign data wrapper for querying and modifying ScyllaDB tables from PostgreSQL over CQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-13", "version": "1.2", "postgres": "13, 14, 15, 16, 17, 18", "extension": {"url": "/e/starrocks_fdw/", "text": "starrocks_fdw"}, "description": "TencentDB for PostgreSQL foreign data wrapper for querying StarRocks tables through a MySQL-compatible interface."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.125.0", "postgres": "14, 15", "extension": {"url": "/e/steampipe_postgres_aws/", "text": "steampipe_postgres_aws"}, "description": "Steampipe AWS native PostgreSQL FDW for querying live AWS APIs as foreign tables."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "17, 18", "extension": {"url": "/e/valkey_fdw/", "text": "valkey_fdw"}, "description": "Foreign data wrapper for querying a Valkey server"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.2", "postgres": "14, 15, 16", "extension": {"url": "/e/vmagentfdw/", "text": "vmagentfdw"}, "description": "Foreign data wrapper for reading vmagent scrape-target status through its HTTP API."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.6.0", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/redis_fdw_rs/", "text": "redis_fdw_rs"}, "description": "This extension allows PostgreSQL to directly query and manipulate Redis data as if it were regular PostgreSQL tables."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/pg_conn2/", "text": "pg_conn2"}, "description": "Manage separate PostgreSQL database connections from SQL code"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.2", "postgres": "13, 14, 15, 16, 17, 18", "extension": {"url": "/e/pg_sheet_fdw/", "text": "pg_sheet_fdw"}, "description": "Read local Excel XLSX worksheets as PostgreSQL foreign tables"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.13", "postgres": "11, 12, 13, 14, 15, 16, 17, 18", "extension": {"url": "/e/oai_fdw/", "text": "oai_fdw"}, "description": "OAI-PMH foreign data wrapper for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.2.2", "postgres": "Unknown", "extension": {"url": "/e/multicdr_fdw/", "text": "multicdr_fdw"}, "description": "Foreign data wrapper for reading call-detail-record file streams as external SQL tables."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1.0", "postgres": "Unknown", "extension": {"url": "/e/ansilo_pgx/", "text": "ansilo_pgx"}, "description": "A Postgres interface into any database"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-27", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/busybee_fdw/", "text": "busybee_fdw"}, "description": "MQTT Foreign Data Wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/dir_fdw/", "text": "dir_fdw"}, "description": "foreign-data wrapper for readdir"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-07-27", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/dummy_data/", "text": "dummy_data"}, "description": "Readable, Null Foreign Data Wrapper for Postgresql 9.3+"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.4.0", "postgres": "Unknown", "extension": {"url": "/e/filesystem/", "text": "filesystem"}, "description": "filesystem foreign data wrapper"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/gofdw/", "text": "gofdw"}, "description": "Postgres FDW in go experiments"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/gp_exttable_fdw/", "text": "gp_exttable_fdw"}, "description": "External Table Foreign Data Wrapper for Greenplum-family databases."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/grpc_fdw/", "text": "grpc_fdw"}, "description": "Foreign data wrapper that delegates table operations to services over gRPC."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/level_pivot/", "text": "level_pivot"}, "description": "LevelDB FDW with support for pivoting and key templating"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.0", "postgres": "Unknown", "extension": {"url": "/e/pg_kafka/", "text": "pg_kafka"}, "description": "Kafka foreign data wrapper for PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.4", "postgres": "Unknown", "extension": {"url": "/e/pg_monetdb/", "text": "pg_monetdb"}, "description": "MonetDB foreign-data wrapper with stronger analytical pushdown"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/pgtokdb/", "text": "pgtokdb"}, "description": "PostgreSQL to kdb+ Extension"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/pxf/", "text": "pxf"}, "description": "Historical Greenplum extension for accessing unmanaged data through PXF."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/pxf_fdw/", "text": "pxf_fdw"}, "description": "PXF Framework for Greengage"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/r53db/", "text": "r53db"}, "description": "r53db, the PostgreSQL Foreign Data Wrapper for the AWS Route53 Database service"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/steampipe_postgres_fdw/", "text": "steampipe_postgres_fdw"}, "description": "Zero-ETL foreign data wrapper that maps PostgreSQL foreign tables to cloud-service and API calls."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/tibero_fdw/", "text": "tibero_fdw"}, "description": "PostgreSQL foreign data wrapper source code for Tibero"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "1.5.0", "postgres": "Unknown", "extension": {"url": "/e/tsurugi_fdw/", "text": "tsurugi_fdw"}, "description": "Tsurugi Foreign Data Wrapper for PostgreSQL."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-30", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/zipfile-fdw/", "text": "zipfile-fdw"}, "description": "Prototype foreign data wrapper scaffold for ZIP-file access."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-31", "version": "1.0", "postgres": "9.1, 9.2, 9.3", "extension": {"url": "/e/dc_fdw/", "text": "dc_fdw"}, "description": "Historical foreign data wrapper for document collections stored on local disk."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-08-31", "version": "0.4.1", "postgres": "14, 15, 16, 17, 18", "extension": {"url": "/e/openapi_fdw/", "text": "openapi_fdw"}, "description": "Read/write foreign data wrapper for OpenAPI and JSON HTTP services."}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-21", "version": "1.0.0-alpha1", "postgres": "18", "extension": {"url": "/e/pgwrh_fdw/", "text": "pgwrh_fdw"}, "description": "PostgreSQL foreign data wrapper with transaction setting propagation and replica routing"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-26", "version": "0.6", "postgres": "Unknown", "extension": {"url": "/e/gaia_fdw/", "text": "gaia_fdw"}, "description": "Foreign data wrapper for querying and modifying Gaia Platform databases"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "9.3", "extension": {"url": "/e/sdb_fdw/", "text": "sdb_fdw"}, "description": "Foreign data wrapper for SequoiaDB collections"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/dist_fdw/", "text": "dist_fdw"}, "description": "openGauss foreign data wrapper for bulk loading external files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/mot_fdw/", "text": "mot_fdw"}, "description": "openGauss memory-optimized table engine FDW adapter"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "0.1.0", "postgres": "17, 18", "extension": {"url": "/e/yesno_pg/", "text": "yesno_pg"}, "description": "yesnodb foreign data, index and table access methods for PostgreSQL"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0.0", "postgres": "Unknown", "extension": {"url": "/e/ekorre/", "text": "ekorre"}, "description": "Foreign data wrapper for local Git repositories"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "13", "extension": {"url": "/e/redis_cluster_fdw/", "text": "redis_cluster_fdw"}, "description": "Foreign data wrapper for clustered Redis data"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "0.1", "postgres": "Unknown", "extension": {"url": "/e/mufdw/", "text": "mufdw"}, "description": "Minimal local-table foreign data wrapper for teaching"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/pixels_fdw/", "text": "pixels_fdw"}, "description": "Foreign data wrapper for Pixels columnar files"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "0.1.0", "postgres": "13, 14, 15, 16, 17, 18", "extension": {"url": "/e/firebirdsql_fdw/", "text": "firebirdsql_fdw"}, "description": "Rust foreign data wrapper for Firebird databases"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "15, 16", "extension": {"url": "/e/tdengine_fdw/", "text": "tdengine_fdw"}, "description": "Foreign data wrapper for TDengine time-series databases"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.1", "postgres": "Unknown", "extension": {"url": "/e/kite_fdw/", "text": "kite_fdw"}, "description": "Foreign data wrapper for remote Kite servers"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "0.1", "postgres": "13", "extension": {"url": "/e/pg_xdbc_fdw/", "text": "pg_xdbc_fdw"}, "description": "Foreign data wrapper for XDBC data transfer"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.0", "postgres": "Unknown", "extension": {"url": "/e/pgspider_core_fdw/", "text": "pgspider_core_fdw"}, "description": "PGSpider multi-source foreign-table query coordinator"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "1.4", "postgres": "Unknown", "extension": {"url": "/e/pgspider_fdw/", "text": "pgspider_fdw"}, "description": "Foreign data wrapper for remote PGSpider nodes"}, {"scope": "Catalogue candidate; interface unverified", "checked": "2026-09-29", "version": "0.0.1", "postgres": "Unknown", "extension": {"url": "/e/blackhole_fdw/", "text": "blackhole_fdw"}, "description": "Black-hole foreign tables that discard writes and return no rows"}], "title": "FDW-category catalogue", "caption": "Current catalogue observation 2026-09-29 from pgext.universe. Extension versions, source metadata dates and declared PostgreSQL compatibility are independent of the selected core version. Catalogue classification does not establish capabilities or maintenance support.", "columns": [{"key": "extension", "label": "Existing extension"}, {"key": "version", "label": "Catalogued version"}, {"key": "postgres", "label": "Declared PG majors"}, {"key": "checked", "label": "Metadata checked"}, {"key": "scope", "label": "Evidence scope"}, {"key": "description", "label": "Catalogued purpose"}]}, {"key": "fdw-reviewed-capabilities", "rows": [{"state": "Conditional", "detail": "Translatable conditions can run in Oracle; EXPLAIN exposes the remote query.", "version": "2.9.0", "evidence": {"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "text": "2026-09-29 \u00b7 3ea9a4522c44 \u00b7 README.oracle_fdw"}, "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "capability": "Predicate pushdown"}, {"state": "Conditional", "detail": "Two tables on one server, in SELECT, with shippable predicates; cross joins and three-table joins are excluded. A pushed join prevents ORDER BY pushdown.", "version": "2.9.0", "evidence": {"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "text": "2026-09-29 \u00b7 3ea9a4522c44 \u00b7 README.oracle_fdw"}, "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "capability": "Join pushdown"}, {"state": "Conditional", "detail": "INSERT, UPDATE and DELETE are supported unless readonly is set. UPDATE and DELETE require every Oracle primary-key column to have key enabled.", "version": "2.9.0", "evidence": {"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "text": "2026-09-29 \u00b7 3ea9a4522c44 \u00b7 README.oracle_fdw"}, "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "capability": "Writes"}, {"state": "Conditional", "detail": "Transaction commands and savepoints reach Oracle. Oracle commits before PostgreSQL, so distributed commit is not atomic.", "version": "2.9.0", "evidence": {"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "text": "2026-09-29 \u00b7 3ea9a4522c44 \u00b7 README.oracle_fdw"}, "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "capability": "Transactions"}, {"state": "Unknown", "detail": "This review has not established aggregate pushdown.", "version": "2.9.0", "evidence": {"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "text": "2026-09-29 \u00b7 3ea9a4522c44 \u00b7 README.oracle_fdw"}, "extension": {"url": "/e/oracle_fdw/", "text": "oracle_fdw"}, "capability": "Aggregate pushdown"}], "title": "Primary-source capability observations", "caption": "Each statement applies to its named extension version and immutable source revision. Unlisted capabilities remain unknown. These are documentation observations, not runtime tests or current maintenance guarantees.", "columns": [{"key": "extension", "label": "Extension"}, {"key": "version", "label": "Reviewed version"}, {"key": "capability", "label": "Capability"}, {"key": "state", "label": "Evidence state"}, {"key": "detail", "label": "Conditions"}, {"key": "evidence", "label": "Evidence date and source"}]}], "extension_reviews": [{"kind": "fdw", "name": "oracle_fdw", "claims": [{"text": "Translatable conditions can run in Oracle; EXPLAIN exposes the remote query.", "label": "Predicate pushdown", "state": "Conditional"}, {"text": "Two tables on one server, in SELECT, with shippable predicates; cross joins and three-table joins are excluded. A pushed join prevents ORDER BY pushdown.", "label": "Join pushdown", "state": "Conditional"}, {"text": "INSERT, UPDATE and DELETE are supported unless readonly is set. UPDATE and DELETE require every Oracle primary-key column to have key enabled.", "label": "Writes", "state": "Conditional"}, {"text": "Transaction commands and savepoints reach Oracle. Oracle commits before PostgreSQL, so distributed commit is not atomic.", "label": "Transactions", "state": "Conditional"}, {"text": "This review has not established aggregate pushdown.", "label": "Aggregate pushdown", "state": "Unknown"}], "sources": [{"url": "https://github.com/laurenz/oracle_fdw/blob/3ea9a4522c445c15c741d4f2bc89bccde740d283/README.oracle_fdw", "path": "README.oracle_fdw", "sha256": "0df770409c3896c887b0c4821457782cc887b7178bd52edef452026bd82d4ede", "local_name": "oracle_fdw-readme.txt"}], "version": "2.9.0", "revision": "3ea9a4522c445c15c741d4f2bc89bccde740d283", "checked_at": "2026-09-29"}], "catalog_observation": {"sha256": "a8f35f83709025575037ce50331f20fc27727e478464e35b48bb501e687cc121", "source": "data.pgext.universe", "identities": [{"id": 8500, "name": "wrappers"}, {"id": 8510, "name": "multicorn"}, {"id": 8520, "name": "odbc_fdw"}, {"id": 8530, "name": "jdbc_fdw"}, {"id": 8540, "name": "pgspider_ext"}, {"id": 8600, "name": "mysql_fdw"}, {"id": 8610, "name": "oracle_fdw"}, {"id": 8620, "name": "tds_fdw"}, {"id": 8630, "name": "db2_fdw"}, {"id": 8640, "name": "sqlite_fdw"}, {"id": 8650, "name": "pgbouncer_fdw"}, {"id": 8660, "name": "etcd_fdw"}, {"id": 8670, "name": "informix_fdw"}, {"id": 8680, "name": "nominatim_fdw"}, {"id": 8700, "name": "mongo_fdw"}, {"id": 8710, "name": "redis_fdw"}, {"id": 8720, "name": "redis"}, {"id": 8730, "name": "kafka_fdw"}, {"id": 8740, "name": "hdfs_fdw"}, {"id": 8750, "name": "firebird_fdw"}, {"id": 8760, "name": "rdf_fdw"}, {"id": 8800, "name": "aws_s3"}, {"id": 8810, "name": "log_fdw"}, {"id": 8970, "name": "dblink"}, {"id": 8980, "name": "file_fdw"}, {"id": 8990, "name": "postgres_fdw"}, {"id": 100017, "name": "clickhousedb_fdw"}, {"id": 100018, "name": "holycorn"}, {"id": 100019, "name": "json_fdw"}, {"id": 100020, "name": "parquet_fdw"}, {"id": 100021, "name": "www_fdw"}, {"id": 100072, "name": "dblink_plus"}, {"id": 100082, "name": "cassandra2_fdw"}, {"id": 100083, "name": "ch_fdw"}, {"id": 100084, "name": "couchdb_fdw"}, {"id": 100085, "name": "dump_fdw"}, {"id": 100086, "name": "file_fixed_length_fdw"}, {"id": 100092, "name": "file_textarray_fdw"}, {"id": 100093, "name": "git_fdw"}, {"id": 100094, "name": "go_fdw"}, {"id": 100095, "name": "bigtable"}, {"id": 100096, "name": "griddb_fdw"}, {"id": 100097, "name": "hello_fdw"}, {"id": 100098, "name": "influxdb_fdw"}, {"id": 100099, "name": "jdbc2_fdw"}, {"id": 100100, "name": "kt_fdw"}, {"id": 100101, "name": "ldap_fdw"}, {"id": 100102, "name": "osm_fdw"}, {"id": 100103, "name": "kv_fdw"}, {"id": 100104, "name": "quasar_fdw"}, {"id": 100105, "name": "s3_fdw"}, {"id": 100106, "name": "twitter_fdw"}, {"id": 100114, "name": "monetdb_fdw"}, {"id": 100115, "name": "neo4j-fdw"}, {"id": 100116, "name": "neo4j_fdw"}, {"id": 100117, "name": "orc_fdw"}, {"id": 100154, "name": "lsm"}, {"id": 100167, "name": "oblivpg_fdw"}, {"id": 100334, "name": "kadb_fdw"}, {"id": 100358, "name": "cassandra_fdw"}, {"id": 100359, "name": "db2odbc_fdw"}, {"id": 100368, "name": "hive_fdw"}, {"id": 100369, "name": "lua_fdw"}, {"id": 100370, "name": "ocgeo_fdw"}, {"id": 100371, "name": "douban_fdw"}, {"id": 100372, "name": "passwd-fdw"}, {"id": 100375, "name": "aerospike_fdw"}, {"id": 100376, "name": "file_fdw_program"}, {"id": 100377, "name": "greenplum_fdw"}, {"id": 100379, "name": "treasuredata_fdw"}, {"id": 100380, "name": "tsf_fdw"}, {"id": 100381, "name": "tuple_fdw"}, {"id": 100382, "name": "wdb_fdw"}, {"id": 100385, "name": "gtables_fdw"}, {"id": 100386, "name": "hash_fdw"}, {"id": 100387, "name": "hba_fdw"}, {"id": 100388, "name": "hbase_fdw"}, {"id": 100457, "name": "pgc_fdw"}, {"id": 100458, "name": "pglog"}, {"id": 100459, "name": "postgres_fdw_plus"}, {"id": 100540, "name": "rasterdb"}, {"id": 100566, "name": "sybase_fdw"}, {"id": 100568, "name": "template_fdw"}, {"id": 100598, "name": "dataclips"}, {"id": 100680, "name": "redis_link"}, {"id": 100709, "name": "clerk_fdw"}, {"id": 100718, "name": "prometheus_fdw"}, {"id": 100726, "name": "lance"}, {"id": 100728, "name": "pg_kalam"}, {"id": 100802, "name": "orb_fdw"}, {"id": 100858, "name": "db721_fdw"}, {"id": 100897, "name": "prometheusfdw"}, {"id": 100920, "name": "ebs_fdw"}, {"id": 100970, "name": "clickhouse_fdw"}, {"id": 100971, "name": "cos_fdw"}, {"id": 100978, "name": "dynamodb_fdw"}, {"id": 100986, "name": "external_search_fdw"}, {"id": 101033, "name": "obs_fdw"}, {"id": 101037, "name": "oss_fdw"}, {"id": 101038, "name": "parquet_s3_fdw"}, {"id": 101159, "name": "scylla_fdw"}, {"id": 101164, "name": "starrocks_fdw"}, {"id": 101166, "name": "steampipe_postgres_aws"}, {"id": 101196, "name": "valkey_fdw"}, {"id": 101198, "name": "vmagentfdw"}, {"id": 101221, "name": "redis_fdw_rs"}, {"id": 101226, "name": "pg_conn2"}, {"id": 101227, "name": "pg_sheet_fdw"}, {"id": 101228, "name": "oai_fdw"}, {"id": 101229, "name": "multicdr_fdw"}, {"id": 101277, "name": "ansilo_pgx"}, {"id": 101302, "name": "busybee_fdw"}, {"id": 101337, "name": "dir_fdw"}, {"id": 101341, "name": "dummy_data"}, {"id": 101364, "name": "filesystem"}, {"id": 101381, "name": "gofdw"}, {"id": 101384, "name": "gp_exttable_fdw"}, {"id": 101391, "name": "grpc_fdw"}, {"id": 101438, "name": "level_pivot"}, {"id": 101567, "name": "pg_kafka"}, {"id": 101583, "name": "pg_monetdb"}, {"id": 101693, "name": "pgtokdb"}, {"id": 101735, "name": "pxf"}, {"id": 101736, "name": "pxf_fdw"}, {"id": 101740, "name": "r53db"}, {"id": 101788, "name": "steampipe_postgres_fdw"}, {"id": 101811, "name": "tibero_fdw"}, {"id": 101820, "name": "tsurugi_fdw"}, {"id": 101844, "name": "zipfile-fdw"}, {"id": 101875, "name": "dc_fdw"}, {"id": 101895, "name": "openapi_fdw"}, {"id": 101990, "name": "pgwrh_fdw"}, {"id": 102028, "name": "gaia_fdw"}, {"id": 102038, "name": "sdb_fdw"}, {"id": 102039, "name": "dist_fdw"}, {"id": 102040, "name": "mot_fdw"}, {"id": 102041, "name": "yesno_pg"}, {"id": 102042, "name": "ekorre"}, {"id": 102043, "name": "redis_cluster_fdw"}, {"id": 102044, "name": "mufdw"}, {"id": 102045, "name": "pixels_fdw"}, {"id": 102046, "name": "firebirdsql_fdw"}, {"id": 102047, "name": "tdengine_fdw"}, {"id": 102048, "name": "kite_fdw"}, {"id": 102049, "name": "pg_xdbc_fdw"}, {"id": 102051, "name": "pgspider_core_fdw"}, {"id": 102052, "name": "pgspider_fdw"}, {"id": 102053, "name": "blackhole_fdw"}], "observed_at": "2026-09-29T15:02:21.407129+00:00", "catalogue_rows": 2452, "candidate_count": 148}}}}, "snapshot": {"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"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "postgresIterateForeignScan"}, {"state": "Handler registered; conditions apply", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "postgresExecForeignInsert"}, {"state": "Handler registered; conditions apply", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "postgresExecForeignUpdate"}, {"state": "Handler registered; conditions apply", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "postgresExecForeignDelete"}, {"state": "Handler registered; conditions apply", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "postgresExecForeignTruncate"}, {"state": "Handler registered; conditions apply", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "postgresGetForeignJoinPaths"}, {"state": "Handler registered; conditions apply", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "postgresGetForeignUpperPaths"}, {"state": "Handler registered; conditions apply", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "postgresExecForeignBatchInsert"}, {"state": "Handler registered; conditions apply", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "postgresForeignAsyncRequest"}, {"state": "Handler registered; conditions apply", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "postgresImportForeignSchema"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=18", "label": "Foreign-data wrapper catalog"}, {"url": "/e/postgres_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=18", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 18.6 source archive", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/18/postgres-fdw.html", "path": "postgres-fdw.html", "label": "PostgreSQL 18 English manual", "sha256": "a7833ebac1e9581de25695443eaec67d16d32ef33107783cdfb940fefa5f66a3"}, {"url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "line": 557, "path": "contrib/postgres_fdw/postgres_fdw.c", "label": "contrib/postgres_fdw/postgres_fdw.c:557", "sha256": "5f61f89fc1f9d67a204c47fd993db575b2d619449e5238b536b9fb1877037db6", "archive_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}], "sections": [{"title": "Interface and capability boundaries", "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": "Asynchronous Execution Options", "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": "Transaction Management 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", "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": "Remote Query Optimization", "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": "Cross-Version Compatibility", "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 \u201c function does not exist \u201d 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."]}, {"code": "{\n\tFdwRoutine *routine = makeNode(FdwRoutine);\n\n\t/* Functions for scanning foreign tables */\n\troutine->GetForeignRelSize = postgresGetForeignRelSize;\n\troutine->GetForeignPaths = postgresGetForeignPaths;\n\troutine->GetForeignPlan = postgresGetForeignPlan;\n\troutine->BeginForeignScan = postgresBeginForeignScan;\n\troutine->IterateForeignScan = postgresIterateForeignScan;\n\troutine->ReScanForeignScan = postgresReScanForeignScan;\n\troutine->EndForeignScan = postgresEndForeignScan;\n\n\t/* Functions for updating foreign tables */\n\troutine->AddForeignUpdateTargets = postgresAddForeignUpdateTargets;\n\troutine->PlanForeignModify = postgresPlanForeignModify;\n\troutine->BeginForeignModify = postgresBeginForeignModify;\n\troutine->ExecForeignInsert = postgresExecForeignInsert;\n\troutine->ExecForeignBatchInsert = postgresExecForeignBatchInsert;\n\troutine->GetForeignModifyBatchSize = postgresGetForeignModifyBatchSize;\n\troutine->ExecForeignUpdate = postgresExecForeignUpdate;\n\troutine->ExecForeignDelete = postgresExecForeignDelete;\n\troutine->EndForeignModify = postgresEndForeignModify;\n\troutine->BeginForeignInsert = postgresBeginForeignInsert;\n\troutine->EndForeignInsert = postgresEndForeignInsert;\n\troutine->IsForeignRelUpdatable = postgresIsForeignRelUpdatable;\n\troutine->PlanDirectModify = postgresPlanDirectModify;\n\troutine->BeginDirectModify = postgresBeginDirectModify;\n\troutine->IterateDirectModify = postgresIterateDirectModify;\n\troutine->EndDirectModify = postgresEndDirectModify;\n\n\t/* Function for EvalPlanQual rechecks */\n\troutine->RecheckForeignScan = postgresRecheckForeignScan;\n\t/* Support functions for EXPLAIN */\n\troutine->ExplainForeignScan = postgresExplainForeignScan;\n\troutine->ExplainForeignModify = postgresExplainForeignModify;\n\troutine->ExplainDirectModify = postgresExplainDirectModify;\n\n\t/* Support function for TRUNCATE */\n\troutine->ExecForeignTruncate = postgresExecForeignTruncate;\n\n\t/* Support functions for ANALYZE */\n\troutine->AnalyzeForeignTable = postgresAnalyzeForeignTable;\n\n\t/* Support functions for IMPORT FOREIGN SCHEMA */\n\troutine->ImportForeignSchema = postgresImportForeignSchema;\n\n\t/* Support functions for join push-down */\n\troutine->GetForeignJoinPaths = postgresGetForeignJoinPaths;\n\n\t/* Support functions for upper relation push-down */\n\troutine->GetForeignUpperPaths = postgresGetForeignUpperPaths;\n\n\t/* Support functions for asynchronous execution */\n\troutine->IsForeignPathAsyncCapable = postgresIsForeignPathAsyncCapable;\n\troutine->ForeignAsyncRequest = postgresForeignAsyncRequest;\n\troutine->ForeignAsyncConfigureWait = postgresForeignAsyncConfigureWait;\n\troutine->ForeignAsyncNotify = postgresForeignAsyncNotify;\n\n\tPG_RETURN_POINTER(routine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "description": ["Accesses tables in remote PostgreSQL servers through foreign tables."], "manual_html": "<div class=\"sect1\" id=\"POSTGRES-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.38.\u00a0postgres_fdw \u2014 access data stored in external <span class=\"productname\">PostgreSQL</span> servers </h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">postgres_fdw</code> module provides the foreign-data wrapper <code class=\"literal\">postgres_fdw</code>, which can be used to access data stored in external <span class=\"productname\">PostgreSQL</span> servers.</p>\n<p>The functionality provided by this module overlaps substantially with the functionality of the older <a class=\"xref\" href=\"/docs/18/dblink.html\" title=\"F.11.\u00a0dblink \u2014 connect to other PostgreSQL databases\">dblink</a> module. But <code class=\"filename\">postgres_fdw</code> provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.</p>\n<p>To prepare for remote access using <code class=\"filename\">postgres_fdw</code>:</p>\n<div class=\"orderedlist\">\n<ol class=\"orderedlist compact\">\n<li class=\"listitem\">\n<p>Install the <code class=\"filename\">postgres_fdw</code> extension using <a class=\"xref\" href=\"/docs/18/sql-createextension.html\" title=\"CREATE EXTENSION\"><span class=\"refentrytitle\">CREATE EXTENSION</span></a>.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign server object, using <a class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>, to represent each remote database you want to connect to. Specify connection information, except <code class=\"literal\">user</code> and <code class=\"literal\">password</code>, as options of the server object.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a user mapping, using <a class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, for each database user you want to allow to access each foreign server. Specify the remote user name and password to use as <code class=\"literal\">user</code> and <code class=\"literal\">password</code> options of the user mapping.</p>\n</li>\n<li class=\"listitem\">\n<p>Create a foreign table, using <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a> or <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>, 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.</p>\n</li>\n</ol>\n</div>\n<p>Now you need only <code class=\"command\">SELECT</code> from a foreign table to access the data stored in its underlying remote table. You can also modify the remote table using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code>, <code class=\"command\">COPY</code>, or <code class=\"command\">TRUNCATE</code>. (Of course, the remote user you have specified in your user mapping must have privileges to do these things.)</p>\n<p>Note that the <code class=\"literal\">ONLY</code> option specified in <code class=\"command\">SELECT</code>, <code class=\"command\">UPDATE</code>, <code class=\"command\">DELETE</code> or <code class=\"command\">TRUNCATE</code> has no effect when accessing or modifying the remote table.</p>\n<p>Note that <code class=\"filename\">postgres_fdw</code> currently lacks support for <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO UPDATE</code> clause. However, the <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause is supported, provided a unique index inference specification is omitted. Note also that <code class=\"filename\">postgres_fdw</code> supports row movement invoked by <code class=\"command\">UPDATE</code> 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 <code class=\"command\">UPDATE</code> target partition that will be updated elsewhere in the same command.</p>\n<p>It is generally recommended that the columns of a foreign table be declared with exactly the same data types, and collations if applicable, as the referenced columns of the remote table. Although <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Note that a foreign table can be declared with fewer columns, or with a different column order, than its underlying remote table has. Matching of columns to the remote table is by name, not position.</p>\n<div class=\"sect2\" id=\"POSTGRES-FDW-OPTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.1.\u00a0FDW Options of postgres_fdw </h3>\n</div>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.1.\u00a0Connection Options </h4>\n</div>\n</div>\n</div>\n<p>A foreign server using the <code class=\"filename\">postgres_fdw</code> foreign data wrapper can have the same options that <span class=\"application\">libpq</span> accepts in connection strings, as described in <a class=\"xref\" href=\"/docs/18/libpq-connect.html#LIBPQ-PARAMKEYWORDS\" title=\"32.1.2.\u00a0Parameter Key Words\">Section\u00a032.1.2</a>, except that these options are not allowed or have special handling:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><code class=\"literal\">user</code>, <code class=\"literal\">password</code> and <code class=\"literal\">sslpassword</code> (specify these in a user mapping instead, or use a service file)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">client_encoding</code> (this is automatically set from the local server encoding)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">application_name</code> - this may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a>. If both are present, <code class=\"varname\">postgres_fdw.application_name</code> overrides the connection setting. Unlike <span class=\"application\">libpq</span>, <code class=\"filename\">postgres_fdw</code> allows <code class=\"varname\">application_name</code> to include <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span>. See <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#GUC-PGFDW-APPLICATION-NAME\">postgres_fdw.application_name</a> for details.</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">fallback_application_name</code> (always set to <code class=\"literal\">postgres_fdw</code>)</p>\n</li>\n<li class=\"listitem\">\n<p><code class=\"literal\">sslkey</code> and <code class=\"literal\">sslcert</code> - these may appear in <span class=\"emphasis\"><em>either or both</em></span> a connection and a user mapping. If both are present, the user mapping setting overrides the connection setting.</p>\n</li>\n</ul>\n</div>\n<p>Only superusers may create or modify user mappings with the <code class=\"literal\">sslcert</code> or <code class=\"literal\">sslkey</code> settings.</p>\n<p>Non-superusers may connect to foreign servers using password authentication or with GSSAPI delegated credentials, so specify the <code class=\"literal\">password</code> option for user mappings belonging to non-superusers where password authentication is required.</p>\n<p>A superuser may override this check on a per-user-mapping basis by setting the user mapping option <code class=\"literal\">password_required 'false'</code>, e.g.,</p>\n<pre class=\"programlisting\">ALTER USER MAPPING FOR some_non_superuser SERVER loopback_nopw\nOPTIONS (ADD password_required 'false');\n</pre>\n<p>To prevent unprivileged users from exploiting the authentication rights of the unix user the postgres server is running as to escalate to superuser rights, only the superuser may set this option on a user mapping.</p>\n<p>Care is required to ensure that this does not allow the mapped user the ability to connect as superuser to the mapped database per CVE-2007-3278 and CVE-2007-6601. Don't set <code class=\"literal\">password_required=false</code> on the <code class=\"literal\">public</code> role. Keep in mind that the mapped user can potentially use any client certificates, <code class=\"filename\">.pgpass</code>, <code class=\"filename\">.pg_service.conf</code> etc. in the unix home directory of the system user the postgres server runs as. (For details on how home directories are found, see <a class=\"xref\" href=\"/docs/18/libpq-pgpass.html\" title=\"32.16.\u00a0The Password File\">Section\u00a032.16</a>.) They can also use any trust relationship granted by authentication modes like <code class=\"literal\">peer</code> or <code class=\"literal\">ident</code> authentication.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-OBJECT-NAME\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.2.\u00a0Object Name Options </h4>\n</div>\n</div>\n</div>\n<p>These options can be used to control the names used in SQL statements sent to the remote <span class=\"productname\">PostgreSQL</span> server. These options are needed when a foreign table is created with names different from the underlying remote table's names.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">schema_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">table_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">column_name</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-COST-ESTIMATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.3.\u00a0Cost Estimation Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 \u2014 but for simple queries, it may not be worth the cost of an additional remote query to get a cost estimate. So <code class=\"filename\">postgres_fdw</code> provides the following options to control how cost estimation is done:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">use_remote_estimate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, controls whether <code class=\"filename\">postgres_fdw</code> issues remote <code class=\"command\">EXPLAIN</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_startup_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fdw_tuple_cost</code> (<code class=\"type\">floating point</code>)</span></dt>\n<dd>\n<p>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 <code class=\"literal\">0.2</code>.</p>\n</dd>\n</dl>\n</div>\n<p>When <code class=\"literal\">use_remote_estimate</code> is true, <code class=\"filename\">postgres_fdw</code> obtains row count and cost estimates from the remote server and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> to the cost estimates. When <code class=\"literal\">use_remote_estimate</code> is false, <code class=\"filename\">postgres_fdw</code> performs local row count and cost estimation and then adds <code class=\"literal\">fdw_startup_cost</code> and <code class=\"literal\">fdw_tuple_cost</code> 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 <a class=\"xref\" href=\"/docs/18/sql-analyze.html\" title=\"ANALYZE\"><span class=\"refentrytitle\">ANALYZE</span></a> 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 \u2014 but if the remote table is frequently updated, the local statistics will soon be obsolete.</p>\n<p>The following option controls how such an <code class=\"command\">ANALYZE</code> operation behaves:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">analyze_sampling</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option, which can be specified for a foreign table or a foreign server, determines if <code class=\"command\">ANALYZE</code> 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 <code class=\"literal\">off</code>, <code class=\"literal\">random</code>, <code class=\"literal\">system</code>, <code class=\"literal\">bernoulli</code> and <code class=\"literal\">auto</code>. <code class=\"literal\">off</code> disables remote sampling, so all data are transferred and sampled locally. <code class=\"literal\">random</code> performs remote sampling using the <code class=\"literal\">random()</code> function to choose returned rows, while <code class=\"literal\">system</code> and <code class=\"literal\">bernoulli</code> rely on the built-in <code class=\"literal\">TABLESAMPLE</code> methods of those names. <code class=\"literal\">random</code> works on all remote server versions, while <code class=\"literal\">TABLESAMPLE</code> is supported only since 9.5. <code class=\"literal\">auto</code> (the default) picks the recommended sampling method automatically; currently it means either <code class=\"literal\">bernoulli</code> or <code class=\"literal\">random</code> depending on the remote server version.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-REMOTE-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.4.\u00a0Remote Execution Options </h4>\n</div>\n</div>\n</div>\n<p>By default, only <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">WHERE</code> clauses for remote execution. This behavior can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">extensions</code> (<code class=\"type\">string</code>)</span></dt>\n<dd>\n<p>This option is a comma-separated list of names of <span class=\"productname\">PostgreSQL</span> 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.</p>\n<p>When using the <code class=\"literal\">extensions</code> option, <span class=\"emphasis\"><em>it is the user's responsibility</em></span> that the listed extensions exist and behave identically on both the local and remote servers. Otherwise, remote queries may fail or behave unexpectedly.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">fetch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">100</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">batch_size</code> (<code class=\"type\">integer</code>)</span></dt>\n<dd>\n<p>This option specifies the number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">1</code>.</p>\n<p>Note the actual number of rows <code class=\"filename\">postgres_fdw</code> inserts at once depends on the number of columns and the provided <code class=\"literal\">batch_size</code> value. The batch is executed as a single query, and the libpq protocol (which <code class=\"filename\">postgres_fdw</code> uses to connect to a remote server) limits the number of parameters in a single query to 65535. When the number of columns * <code class=\"literal\">batch_size</code> exceeds the limit, the <code class=\"literal\">batch_size</code> will be adjusted to avoid an error.</p>\n<p>This option also applies when copying into foreign tables. In that case the actual number of rows <code class=\"filename\">postgres_fdw</code> 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 <code class=\"command\">COPY</code> command.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-ASYNCHRONOUS-EXECUTION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.5.\u00a0Asynchronous Execution Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> supports asynchronous execution, which runs multiple parts of an <code class=\"structname\">Append</code> node concurrently rather than serially to improve performance. This execution can be controlled using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">async_capable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n<p>In order to ensure that the data being returned from a foreign server is consistent, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>Asynchronous execution is applied even when an <code class=\"structname\">Append</code> 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 <code class=\"filename\">postgres_fdw</code>, 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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.6.\u00a0Transaction Management Options </h4>\n</div>\n</div>\n</div>\n<p>As described in the Transaction Management section, in <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> 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 <code class=\"filename\">postgres_fdw</code> commits or aborts those remote subtransactions serially when the local subtransaction is committed or aborted. Performance can be improved with the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">parallel_commit</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">parallel_abort</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">false</code>.</p>\n</dd>\n</dl>\n</div>\n<p>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.</p>\n<p>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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-UPDATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.7.\u00a0Updatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be updatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">updatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be modified using <code class=\"command\">INSERT</code>, <code class=\"command\">UPDATE</code> and <code class=\"command\">DELETE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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 <code class=\"literal\">information_schema</code> views will report a <code class=\"filename\">postgres_fdw</code> foreign table to be updatable (or not) according to the setting of this option, without any check of the remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-TRUNCATABILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.8.\u00a0Truncatability Options </h4>\n</div>\n</div>\n</div>\n<p>By default all foreign tables using <code class=\"filename\">postgres_fdw</code> are assumed to be truncatable. This may be overridden using the following option:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">truncatable</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> allows foreign tables to be truncated using the <code class=\"command\">TRUNCATE</code> 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 <code class=\"literal\">true</code>.</p>\n<p>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.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-IMPORTING\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.9.\u00a0Importing Options </h4>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> is able to import foreign table definitions using <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n<p>Importing behavior can be customized with the following options (given in the <code class=\"command\">IMPORT FOREIGN SCHEMA</code> command):</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">import_collate</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">COLLATE</code> options are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. 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.</p>\n<p>Even when this parameter is set to <code class=\"literal\">true</code>, importing columns whose collation is the remote server's default can be risky. They will be imported with <code class=\"literal\">COLLATE \"default\"</code>, which will select the local server's default collation, which could be different.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_default</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">DEFAULT</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">false</code>. 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; <code class=\"function\">nextval()</code> is a common source of problems. The <code class=\"command\">IMPORT</code> will fail altogether if an imported default expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_generated</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">GENERATED</code> expressions are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>. The <code class=\"command\">IMPORT</code> will fail altogether if an imported generated expression uses a function or operator that does not exist locally.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">import_not_null</code> (<code class=\"type\">boolean</code>)</span></dt>\n<dd>\n<p>This option controls whether column <code class=\"literal\">NOT NULL</code> constraints are included in the definitions of foreign tables imported from a foreign server. The default is <code class=\"literal\">true</code>.</p>\n</dd>\n</dl>\n</div>\n<p>Note that constraints other than <code class=\"literal\">NOT NULL</code> will never be imported from the remote tables. Although <span class=\"productname\">PostgreSQL</span> 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 <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>.</p>\n<p>Tables or foreign tables which are partitions of some other table are imported only when they are explicitly specified in <code class=\"literal\">LIMIT TO</code> clause. Otherwise they are automatically excluded from <a class=\"xref\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><span class=\"refentrytitle\">IMPORT FOREIGN SCHEMA</span></a>. 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.</p>\n</div>\n<div class=\"sect3\" id=\"POSTGRES-FDW-OPTIONS-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\">F.38.1.10.\u00a0Connection Management Options </h4>\n</div>\n</div>\n</div>\n<p>By default, all connections that <code class=\"filename\">postgres_fdw</code> establishes to foreign servers are kept open in the local session for re-use.</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"POSTGRES-FDW-OPTION-KEEP-CONNECTIONS\"><span class=\"term\"><code class=\"literal\">keep_connections</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">on</code>. If set to <code class=\"literal\">off</code>, all connections to this foreign server will be discarded at the end of each transaction.</p>\n</dd>\n<dt id=\"POSTGRES-FDW-OPTION-USE-SCRAM-PASSTHROUGH\"><span class=\"term\"><code class=\"literal\">use_scram_passthrough</code> (<code class=\"type\">boolean</code>)</span> </dt>\n<dd>\n<p>This option controls whether <code class=\"filename\">postgres_fdw</code> 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, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>To use SCRAM pass-through authentication:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist\">\n<li class=\"listitem\">\n<p>The remote server must request the <code class=\"literal\">scram-sha-256</code> authentication method; otherwise, the connection will fail.</p>\n</li>\n<li class=\"listitem\">\n<p>The remote server can be of any PostgreSQL version that supports SCRAM. Support for <code class=\"literal\">use_scram_passthrough</code> is only required on the client side (FDW side).</p>\n</li>\n<li class=\"listitem\">\n<p>The user mapping password is not used.</p>\n</li>\n<li class=\"listitem\">\n<p>The server running <code class=\"filename\">postgres_fdw</code> and the remote server must have identical SCRAM secrets (encrypted passwords) for the user being used on <code class=\"filename\">postgres_fdw</code> to authenticate on the foreign server (same salt and iterations, not merely the same password).</p>\n<p>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.</p>\n</li>\n<li class=\"listitem\">\n<p>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 <span class=\"quote\">\u201c<span class=\"quote\">pass-through</span>\u201d</span>: SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.</p>\n</li>\n</ul>\n</div>\n</dd>\n</dl>\n</div>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-FUNCTIONS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.2.\u00a0Functions </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"function\">postgres_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</code></span></dt>\n<dd>\n<p>This 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.</p>\n<p>If <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">true</code>, the function checks the status of each connection and shows the result in the <code class=\"literal\">closed</code> column. This feature is currently available only on systems that support the non-standard <code class=\"symbol\">POLLRDHUP</code> extension to the <code class=\"symbol\">poll</code> 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 <code class=\"literal\">used_in_xact</code> and <code class=\"literal\">closed</code> are <code class=\"literal\">true</code>.</p>\n<p>Example usage of the function:</p>\n<pre class=\"screen\">postgres=# 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</pre>\n<p>The output columns are described in <a class=\"xref\" href=\"/docs/18/postgres-fdw.html#POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\" title=\"Table\u00a0F.28.\u00a0postgres_fdw_get_connections Output Columns\">Table\u00a0F.28</a>.</p>\n<div class=\"table\" id=\"POSTGRES-FDW-GET-CONNECTIONS-COLUMNS\">\n<p class=\"title\"><strong>Table\u00a0F.28.\u00a0<code class=\"function\">postgres_fdw_get_connections</code> Output Columns</strong></p>\n<div class=\"table-contents\">\n<table class=\"table\">\n\n\n\n\n\n<thead>\n<tr>\n<th>Column</th>\n<th>Type</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"structfield\">server_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>The foreign server name of this connection. If the server is dropped but the connection remains open (i.e., marked as invalid), this will be <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">user_name</code></td>\n<td><code class=\"type\">text</code></td>\n<td>Name of the local user mapped to the foreign server of this connection, or <code class=\"literal\">public</code> 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 <code class=\"literal\">NULL</code>.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">valid</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>False 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.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">used_in_xact</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is used in the current transaction.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">closed</code></td>\n<td><code class=\"type\">boolean</code></td>\n<td>True if this connection is closed, false otherwise. <code class=\"literal\">NULL</code> is returned if <code class=\"literal\">check_conn</code> is set to <code class=\"literal\">false</code> or if the connection status check is not available on this platform.</td>\n</tr>\n<tr>\n<td><code class=\"structfield\">remote_backend_pid</code></td>\n<td><code class=\"type\">int4</code></td>\n<td>Process ID of the remote backend, on the foreign server, handling the connection. If the remote backend is terminated and the connection is closed (with <code class=\"literal\">closed</code> set to <code class=\"literal\">true</code>), this still shows the process ID of the terminated backend.</td>\n</tr>\n</tbody>\n</table>\n</div>\n</div><br class=\"table-break\">\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect(server_name text) returns boolean</code></span></dt>\n<dd>\n<p>This function discards the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. If no foreign server with the given name is found, an error is reported. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect('loopback1');\n postgres_fdw_disconnect\n-------------------------\n t\n</pre>\n</dd>\n<dt><span class=\"term\"><code class=\"function\">postgres_fdw_disconnect_all() returns boolean</code></span></dt>\n<dd>\n<p>This function discards all the open connections that are established by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">true</code> if it disconnects at least one connection, otherwise <code class=\"literal\">false</code>. Example usage of the function:</p>\n<pre class=\"screen\">postgres=# SELECT postgres_fdw_disconnect_all();\n postgres_fdw_disconnect_all\n-----------------------------\n t\n</pre>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONNECTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.3.\u00a0Connection Management </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">keep_connections</code> 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.</p>\n<p>When 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.</p>\n<p>Once 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, <code class=\"literal\">keep_connections</code> option for a foreign server may be disabled, or <code class=\"function\">postgres_fdw_disconnect</code> and <code class=\"function\">postgres_fdw_disconnect_all</code> functions may be used. For example, these are useful to close connections that are no longer necessary, thereby releasing connections on the foreign server.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-TRANSACTION-MANAGEMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.4.\u00a0Transaction Management </h3>\n</div>\n</div>\n</div>\n<p>During a query that references any remote tables on a foreign server, <code class=\"filename\">postgres_fdw</code> 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.</p>\n<p>The remote transaction uses <code class=\"literal\">SERIALIZABLE</code> isolation level when the local transaction has <code class=\"literal\">SERIALIZABLE</code> isolation level; otherwise it uses <code class=\"literal\">REPEATABLE READ</code> 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 <code class=\"literal\">SERIALIZABLE</code> or <code class=\"literal\">REPEATABLE READ</code> isolation level, but it might be surprising for a <code class=\"literal\">READ COMMITTED</code> local transaction. A future <span class=\"productname\">PostgreSQL</span> release might modify these rules.</p>\n<p>Note that it is currently not supported by <code class=\"filename\">postgres_fdw</code> to prepare the remote transaction for two-phase commit.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-OPTIMIZATION\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.5.\u00a0Remote Query Optimization </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> attempts to optimize remote queries to reduce the amount of data transferred from foreign servers. This is done by sending query <code class=\"literal\">WHERE</code> 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, <code class=\"literal\">WHERE</code> 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 <code class=\"literal\">extensions</code> option. Operators and functions in such clauses must be <code class=\"literal\">IMMUTABLE</code> as well. For an <code class=\"command\">UPDATE</code> or <code class=\"command\">DELETE</code> query, <code class=\"filename\">postgres_fdw</code> attempts to optimize the query execution by sending the whole query to the remote server if there are no query <code class=\"literal\">WHERE</code> clauses that cannot be sent to the remote server, no local joins for the query, no row-level local <code class=\"literal\">BEFORE</code> or <code class=\"literal\">AFTER</code> triggers or stored generated columns on the target table, and no <code class=\"literal\">CHECK OPTION</code> constraints from parent views. In <code class=\"command\">UPDATE</code>, expressions to assign to target columns must use only built-in data types, <code class=\"literal\">IMMUTABLE</code> operators, or <code class=\"literal\">IMMUTABLE</code> functions, to reduce the risk of misexecution of the query.</p>\n<p>When <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">JOIN</code> clauses, it takes the same precautions as mentioned above for the <code class=\"literal\">WHERE</code> clauses.</p>\n<p>The query that is actually sent to the remote server for execution can be examined using <code class=\"command\">EXPLAIN VERBOSE</code>.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-REMOTE-QUERY-EXECUTION-ENVIRONMENT\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.6.\u00a0Remote Query Execution Environment </h3>\n</div>\n</div>\n</div>\n<p>In the remote sessions opened by <code class=\"filename\">postgres_fdw</code>, the <a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-SEARCH-PATH\">search_path</a> parameter is set to just <code class=\"literal\">pg_catalog</code>, so that only built-in objects are visible without schema qualification. This is not an issue for queries generated by <code class=\"filename\">postgres_fdw</code> 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 <code class=\"literal\">SET search_path</code> options (see <a class=\"xref\" href=\"/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\"><span class=\"refentrytitle\">CREATE FUNCTION</span></a>) to such functions to establish their expected search path environment.</p>\n<p><code class=\"filename\">postgres_fdw</code> likewise establishes remote session settings for various parameters:</p>\n<div class=\"itemizedlist\">\n<ul class=\"itemizedlist compact\">\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-TIMEZONE\">TimeZone</a> is set to <code class=\"literal\">UTC</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-DATESTYLE\">DateStyle</a> is set to <code class=\"literal\">ISO</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-INTERVALSTYLE\">IntervalStyle</a> is set to <code class=\"literal\">postgres</code></p>\n</li>\n<li class=\"listitem\">\n<p><a class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS\">extra_float_digits</a> is set to <code class=\"literal\">3</code> for remote servers 9.0 and newer and is set to <code class=\"literal\">2</code> for older versions</p>\n</li>\n</ul>\n</div>\n<p>These are less likely to be problematic than <code class=\"varname\">search_path</code>, but can be handled with function <code class=\"literal\">SET</code> options if the need arises.</p>\n<p>It is <span class=\"emphasis\"><em>not</em></span> recommended that you override this behavior by changing the session-level settings of these parameters; that is likely to cause <code class=\"filename\">postgres_fdw</code> to malfunction.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CROSS-VERSION-COMPATIBILITY\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.7.\u00a0Cross-Version Compatibility </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can be used with remote servers dating back to <span class=\"productname\">PostgreSQL</span> 8.3. Read-only capability is available back to 8.1.</p>\n<p>A limitation however is that <code class=\"filename\">postgres_fdw</code> generally assumes that immutable built-in functions and operators are safe to send to the remote server for execution, if they appear in a <code class=\"literal\">WHERE</code> 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 <span class=\"quote\">\u201c<span class=\"quote\">function does not exist</span>\u201d</span> 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-<code class=\"literal\">SELECT</code> with <code class=\"literal\">OFFSET 0</code> as an optimization fence, and placing the problematic function or operator outside the sub-<code class=\"literal\">SELECT</code>.</p>\n<p>Another limitation is that when executing <code class=\"command\">INSERT</code> statements with an <code class=\"literal\">ON CONFLICT DO NOTHING</code> clause on a foreign table, the remote server must be running <span class=\"productname\">PostgreSQL</span> 9.5 or later, as earlier versions do not support this feature.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-WAIT-EVENTS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.8.\u00a0Wait Events </h3>\n</div>\n</div>\n</div>\n<p><code class=\"filename\">postgres_fdw</code> can report the following wait events under the wait event type <code class=\"literal\">Extension</code>:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwCleanupResult</code></span></dt>\n<dd>\n<p>Waiting for transaction abort on remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwConnect</code></span></dt>\n<dd>\n<p>Waiting to establish a connection to a remote server.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">PostgresFdwGetResult</code></span></dt>\n<dd>\n<p>Waiting to receive the results of a query from a remote server.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-CONFIGURATION-PARAMETERS\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.9.\u00a0Configuration Parameters </h3>\n</div>\n</div>\n</div>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt id=\"GUC-PGFDW-APPLICATION-NAME\"><span class=\"term\"><code class=\"varname\">postgres_fdw.application_name</code> (<code class=\"type\">string</code>) </span> </dt>\n<dd>\n<p>Specifies a value for <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> configuration parameter used when <code class=\"filename\">postgres_fdw</code> establishes a connection to a foreign server. This overrides <code class=\"varname\">application_name</code> option of the server object. Note that change of this parameter doesn't affect any existing connections until they are re-established.</p>\n<p><code class=\"varname\">postgres_fdw.application_name</code> can be any string of any length and contain even non-ASCII characters. However when it's passed to and used as <code class=\"varname\">application_name</code> in a foreign server, note that it will be truncated to less than <code class=\"symbol\">NAMEDATALEN</code> characters. Anything other than printable ASCII characters are replaced with <a class=\"link\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE\" title=\"4.1.2.2.\u00a0String Constants with C-Style Escapes\">C-style hexadecimal escapes</a>. See <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-APPLICATION-NAME\">application_name</a> for details.</p>\n<p><code class=\"literal\">%</code> characters begin <span class=\"quote\">\u201c<span class=\"quote\">escape sequences</span>\u201d</span> 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 <code class=\"literal\">%</code> and before the option, for alignment and padding.</p>\n<div class=\"informaltable\">\n<table class=\"informaltable\">\n\n\n\n\n<thead>\n<tr>\n<th>Escape</th>\n<th>Effect</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"literal\">%a</code></td>\n<td>Application name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%c</code></td>\n<td>Session ID on local server (see <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\">log_line_prefix</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%C</code></td>\n<td>Cluster name on local server (see <a class=\"xref\" href=\"/docs/18/runtime-config-logging.html#GUC-CLUSTER-NAME\">cluster_name</a> for details)</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%u</code></td>\n<td>User name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%d</code></td>\n<td>Database name on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%p</code></td>\n<td>Process ID of backend on local server</td>\n</tr>\n<tr>\n<td><code class=\"literal\">%%</code></td>\n<td>Literal %</td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>For example, suppose user <code class=\"literal\">local_user</code> establishes a connection from database <code class=\"literal\">local_db</code> to <code class=\"literal\">foreign_db</code> as user <code class=\"literal\">foreign_user</code>, the setting <code class=\"literal\">'db=%d, user=%u'</code> is replaced with <code class=\"literal\">'db=local_db, user=local_user'</code>.</p>\n</dd>\n</dl>\n</div>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-EXAMPLES\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.10.\u00a0Examples </h3>\n</div>\n</div>\n</div>\n<p>Here is an example of creating a foreign table with <code class=\"literal\">postgres_fdw</code>. First install the extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION postgres_fdw;\n</pre>\n<p>Then create a foreign server using <a class=\"xref\" href=\"/docs/18/sql-createserver.html\" title=\"CREATE SERVER\"><span class=\"refentrytitle\">CREATE SERVER</span></a>. In this example we wish to connect to a <span class=\"productname\">PostgreSQL</span> server on host <code class=\"literal\">192.83.123.89</code> listening on port <code class=\"literal\">5432</code>. The database to which the connection is made is named <code class=\"literal\">foreign_db</code> on the remote server:</p>\n<pre class=\"programlisting\">CREATE SERVER foreign_server\n        FOREIGN DATA WRAPPER postgres_fdw\n        OPTIONS (host '192.83.123.89', port '5432', dbname 'foreign_db');\n</pre>\n<p>A user mapping, defined with <a class=\"xref\" href=\"/docs/18/sql-createusermapping.html\" title=\"CREATE USER MAPPING\"><span class=\"refentrytitle\">CREATE USER MAPPING</span></a>, is needed as well to identify the role that will be used on the remote server:</p>\n<pre class=\"programlisting\">CREATE USER MAPPING FOR local_user\n        SERVER foreign_server\n        OPTIONS (user 'foreign_user', password 'password');\n</pre>\n<p>Now it is possible to create a foreign table with <a class=\"xref\" href=\"/docs/18/sql-createforeigntable.html\" title=\"CREATE FOREIGN TABLE\"><span class=\"refentrytitle\">CREATE FOREIGN TABLE</span></a>. In this example we wish to access the table named <code class=\"structname\">some_schema.some_table</code> on the remote server. The local name for it will be <code class=\"structname\">foreign_table</code>:</p>\n<pre class=\"programlisting\">CREATE 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</pre>\n<p>It's essential that the data types and other properties of the columns declared in <code class=\"command\">CREATE FOREIGN TABLE</code> match the actual remote table. Column names must match as well, unless you attach <code class=\"literal\">column_name</code> options to the individual columns to show how they are named in the remote table. In many cases, use of <a class=\"link\" href=\"/docs/18/sql-importforeignschema.html\" title=\"IMPORT FOREIGN SCHEMA\"><code class=\"command\">IMPORT FOREIGN SCHEMA</code></a> is preferable to constructing foreign table definitions manually.</p>\n</div>\n<div class=\"sect2\" id=\"POSTGRES-FDW-AUTHOR\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h3 class=\"title\">F.38.11.\u00a0Author </h3>\n</div>\n</div>\n</div>\n<p>Shigeru Hanada <code class=\"email\">&lt;<a class=\"email\" href=\"mailto:shigeru.hanada@gmail.com\">shigeru.hanada@gmail.com</a>&gt;</code></p>\n</div>\n</div>", "manual_path": "/docs/18/postgres-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "schema_name", "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": "table_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": "column_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": "use_remote_estimate", "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": "fdw_startup_cost", "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_tuple_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": "analyze_sampling", "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": "extensions", "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": "fetch_size", "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": "batch_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": "async_capable", "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": "parallel_commit", "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_abort", "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": "updatable", "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": "truncatable", "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": "import_collate", "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_default", "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_generated", "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_not_null", "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": "keep_connections", "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": "use_scram_passthrough", "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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol."}], "callbacks": {"EndForeignScan": "postgresEndForeignScan", "GetForeignPlan": "postgresGetForeignPlan", "EndDirectModify": "postgresEndDirectModify", "GetForeignPaths": "postgresGetForeignPaths", "BeginForeignScan": "postgresBeginForeignScan", "EndForeignInsert": "postgresEndForeignInsert", "EndForeignModify": "postgresEndForeignModify", "PlanDirectModify": "postgresPlanDirectModify", "BeginDirectModify": "postgresBeginDirectModify", "ExecForeignDelete": "postgresExecForeignDelete", "ExecForeignInsert": "postgresExecForeignInsert", "ExecForeignUpdate": "postgresExecForeignUpdate", "GetForeignRelSize": "postgresGetForeignRelSize", "PlanForeignModify": "postgresPlanForeignModify", "ReScanForeignScan": "postgresReScanForeignScan", "BeginForeignInsert": "postgresBeginForeignInsert", "BeginForeignModify": "postgresBeginForeignModify", "ExplainForeignScan": "postgresExplainForeignScan", "ForeignAsyncNotify": "postgresForeignAsyncNotify", "IterateForeignScan": "postgresIterateForeignScan", "RecheckForeignScan": "postgresRecheckForeignScan", "AnalyzeForeignTable": "postgresAnalyzeForeignTable", "ExecForeignTruncate": "postgresExecForeignTruncate", "ExplainDirectModify": "postgresExplainDirectModify", "ForeignAsyncRequest": "postgresForeignAsyncRequest", "GetForeignJoinPaths": "postgresGetForeignJoinPaths", "ImportForeignSchema": "postgresImportForeignSchema", "IterateDirectModify": "postgresIterateDirectModify", "ExplainForeignModify": "postgresExplainForeignModify", "GetForeignUpperPaths": "postgresGetForeignUpperPaths", "IsForeignRelUpdatable": "postgresIsForeignRelUpdatable", "ExecForeignBatchInsert": "postgresExecForeignBatchInsert", "AddForeignUpdateTargets": "postgresAddForeignUpdateTargets", "ForeignAsyncConfigureWait": "postgresForeignAsyncConfigureWait", "GetForeignModifyBatchSize": "postgresGetForeignModifyBatchSize", "IsForeignPathAsyncCapable": "postgresIsForeignPathAsyncCapable"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "b8cfe64df86ef92c7aa383c99b1ce6ddc0c195b32004bf9a4ec0ea46bb7e9ba8", "runtime_verified": false}, "comparison": {"left": "17", "right": "18", "status": "changed", "diff": "--- PostgreSQL 17\n+++ PostgreSQL 18\n@@ -117,6 +117,10 @@\n     {\n       \"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.\",\n       \"name\": \"keep_connections\"\n+    },\n+    {\n+      \"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 \u201c pass-through \u201d : SCRAM must be used going in and out.) This is a technical requirement of the SCRAM protocol.\",\n+      \"name\": \"use_scram_passthrough\"\n     }\n   ],\n   \"protocol_versions\": {},"}}