1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

postgres_fdw: Extend postgres_fdw_get_connections to return user name.

This commit adds a "user_name" output column to
the postgres_fdw_get_connections function, returning the name
of the local user mapped to the foreign server for each connection.
If a public mapping is used, it returns "public."

This helps identify postgres_fdw connections more easily,
such as determining which connections are invalid, closed,
or used within the current transaction.

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

Author: Hayato Kuroda
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/b492a935-6c7e-8c08-e485-3c1d64d7d10f@oss.nttdata.com
This commit is contained in:
Fujii Masao
2024-09-18 12:51:48 +09:00
parent b14e9ce7d5
commit 4f08ab5545
5 changed files with 81 additions and 26 deletions

View File

@@ -779,7 +779,8 @@ OPTIONS (ADD password_required 'false');
<varlistentry>
<term><function>postgres_fdw_get_connections(
IN check_conn boolean DEFAULT false, OUT server_name text,
OUT valid boolean, OUT used_in_xact boolean, OUT closed boolean)
OUT user_name text, OUT valid boolean, OUT used_in_xact boolean,
OUT closed boolean)
returns setof record</function></term>
<listitem>
<para>
@@ -806,10 +807,12 @@ OPTIONS (ADD password_required 'false');
<para>
Example usage of the function:
<screen>
server_name | valid | used_in_xact | closed
-------------+-------+--------------+--------
loopback1 | t | t |
loopback2 | f | t |
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
</screen>
The output columns are described in
<xref linkend="postgres-fdw-get-connections-columns"/>.
@@ -836,6 +839,16 @@ OPTIONS (ADD password_required 'false');
invalid), this will be <literal>NULL</literal>.
</entry>
</row>
<row>
<entry><structfield>user_name</structfield></entry>
<entry><type>text</type></entry>
<entry>
Name of the local user mapped to the foreign server of this
connection, or <literal>public</literal> 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 <literal>NULL</literal>.
</entry>
</row>
<row>
<entry><structfield>valid</structfield></entry>
<entry><type>boolean</type></entry>