Home Explore Blog CI



postgresql

14th chunk of `doc/src/sgml/postgres-fdw.sgml`
ffebb838b1bd90ced8d763751ab8e5c8cae4e696f211952a0000000100000fac
 <entry><structfield>remote_backend_pid</structfield></entry>
        <entry><type>int4</type></entry>
        <entry>
         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 <literal>closed</literal> set to
         <literal>true</literal>), this still shows the process ID of
         the terminated backend.
        </entry>
       </row>
      </tbody>
     </tgroup>
    </table>

    </listitem>
   </varlistentry>

   <varlistentry>
    <term><function>postgres_fdw_disconnect(server_name text) returns boolean</function></term>
    <listitem>
     <para>
      This function discards the open connections that are established by
      <filename>postgres_fdw</filename> from the local session to
      the foreign server with the given name.  Note that there can be
      multiple connections to the given server using different user mappings.
      If the connections are used in the current local transaction,
      they are not disconnected and warning messages are reported.
      This function returns <literal>true</literal> if it disconnects
      at least one connection, otherwise <literal>false</literal>.
      If no foreign server with the given name is found, an error is reported.
      Example usage of the function:
<screen>
postgres=# SELECT postgres_fdw_disconnect('loopback1');
 postgres_fdw_disconnect
-------------------------
 t
</screen>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><function>postgres_fdw_disconnect_all() returns boolean</function></term>
    <listitem>
     <para>
      This function discards all the open connections that are established by
      <filename>postgres_fdw</filename> from the local session to
      foreign servers.  If the connections are used in the current local
      transaction, they are not disconnected and warning messages are reported.
      This function returns <literal>true</literal> if it disconnects
      at least one connection, otherwise <literal>false</literal>.
      Example usage of the function:
<screen>
postgres=# SELECT postgres_fdw_disconnect_all();
 postgres_fdw_disconnect_all
-----------------------------
 t
</screen>
     </para>
    </listitem>
   </varlistentry>
   </variablelist>

</sect2>

 <sect2 id="postgres-fdw-connection-management">
  <title>Connection Management</title>

  <para>
   <filename>postgres_fdw</filename> establishes a connection to a
   foreign server during the first query that uses a foreign table
   associated with the foreign server.  By default this connection
   is kept and re-used for subsequent queries in the same session.
   This behavior can be controlled using
   <literal>keep_connections</literal> option for a foreign server. If
   multiple user identities (user mappings) are used to access the foreign
   server, a connection is established for each user mapping.
  </para>

  <para>
   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.
  </para>

  <para>
   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,
   <literal>keep_connections</literal> option for a foreign server
   may be disabled, or
   <function>postgres_fdw_disconnect</function> and
   <function>postgres_fdw_disconnect_all</function> functions
   may be used.  For example, these are useful to close
   connections that are no longer necessary, thereby releasing
   connections on the foreign server.
  </para>
 </sect2>

 <sect2 id="postgres-fdw-transaction-management">
  <title>Transaction

Title: Postgres FDW Connection and Transaction Management
Summary
The postgres_fdw foreign data wrapper provides functions and options to manage connections to foreign servers, including disconnecting open connections with postgres_fdw_disconnect and postgres_fdw_disconnect_all, and controlling connection behavior with the keep_connections option, as well as handling transactions and connection closures.