How can a PostgreSQL client determine what its own TCP port number is?
If running e.g. psql as a client, one can use a query like SELECT * FROM pg_stat_activity WHERE application_name = 'psql'; to determine the local port by inspecting the client_port column in the returned result. How can an arbitrary client…