1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-24 14:22:24 +03:00

postgres_fdw: Extend postgres_fdw_get_connections to return remote backend PID.

This commit adds a new "remote_backend_pid" output column to
the postgres_fdw_get_connections function. It returns the process ID of
the remote backend, on the foreign server, handling the connection.

This enhancement is useful for troubleshooting, monitoring, and reporting.
For example, if a connection is unexpectedly closed by the foreign server,
the remote backend's PID can help diagnose the cause.

No extension version bump is needed, as commit c297a47c5f already
handled it for v18~.

Author: Sagar Dilip Shedge <sagar.shedge92@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAPhYifF25q5xUQWXETfKwhc0YVa_6+tfG9Kw4bCvCjpCWxYs2A@mail.gmail.com
This commit is contained in:
Fujii Masao
2025-03-03 08:51:30 +09:00
parent 15a79c7311
commit fe186bda78
5 changed files with 76 additions and 32 deletions

View File

@ -854,7 +854,7 @@ OPTIONS (ADD password_required 'false');
<term><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 closed boolean, OUT remote_backend_pid int4)
returns setof record</function></term>
<listitem>
<para>
@ -882,11 +882,11 @@ OPTIONS (ADD password_required 'false');
Example usage of the function:
<screen>
postgres=# SELECT * FROM postgres_fdw_get_connections(true);
server_name | user_name | valid | used_in_xact | closed
-------------+-----------+-------+--------------+--------
loopback1 | postgres | t | t | f
loopback2 | public | t | t | f
loopback3 | | f | t | f
server_name | user_name | valid | used_in_xact | closed | remote_backend_pid
-------------+-----------+-------+--------------+-----------------------------
loopback1 | postgres | t | t | f | 1353340
loopback2 | public | t | t | f | 1353120
loopback3 | | f | t | f | 1353156
</screen>
The output columns are described in
<xref linkend="postgres-fdw-get-connections-columns"/>.
@ -951,6 +951,17 @@ postgres=# SELECT * FROM postgres_fdw_get_connections(true);
is not available on this platform.
</entry>
</row>
<row>
<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>