Re: Extend postgres_fdw_get_connections to return remote backend pid

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Sagar Shedge <sagar(dot)shedge92(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Extend postgres_fdw_get_connections to return remote backend pid
Date: 2025-02-25 13:31:51
Message-ID: 5643be83-fd50-4a98-a1c0-58409b8515eb@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025/02/25 1:55, Sagar Shedge wrote:
> Hi Team,
>
> Created patch as per recommendation in postgres wiki.

Thanks for updating the patch!

+ Process ID of remote backend handling connection. If <literal>valid</literal>
+ is set to <literal>false</literal> (i.e., marked as invalid), this will be
+ process ID of remote backend which handled this connection. <literal>NULL</literal>
+ is returned if no backend assigned to this connection or connection status is bad.

I have one question; is there actually a case where remote_backend_pid
returns NULL in postgres_fdw_get_connections()? Based on the current patch,
if the connection object (PGconn) is NULL or its state isn’t CONNECTION_OK,
PQbackendPID() returns 0, so remote_backend_pid becomes NULL.

However, if PGconn is NULL, it seems like postgres_fdw_get_connections()
wouldn't include that connection in the result. If the connection status
is not CONNECTION_OK, it looks like the connection would be closed by
pgfdw_reset_xact_state() before the local backend processes the query
calling postgres_fdw_get_connections(). So, can remote_backend_pid really
be NULL?

If remote_backend_pid will never be NULL, wouldn't a simpler description
like the following be clearer and less confusing for users?
Otherwise, users might wonder why remote_backend_pid isn't NULL
even if the remote server-side connection is closed.

Process ID of the remote backend, on the foreign server, handling the connection.

Also, rather than setting NULL when PQbackendPID() returns 0, would it
make sense for postgres_fdw_get_connections() to just return the result
of PQbackendPID() as-is?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2025-02-25 13:42:08 [BUG]: the walsender does not update its IO statistics until it exits
Previous Message Andrew Dunstan 2025-02-25 13:14:39 Re: Redact user password on pg_stat_statements