Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT. - Mailing list pgsql-bugs

From Francisco Olarte
Subject Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.
Date
Msg-id CA+bJJbzPYe4py-dnzoKEQ9_m_rvduTs_8BSThwWPUUamSK18dQ@mail.gmail.com
Whole thread Raw
In response to 回复: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.  (Wong Simon <thbytwo@live.cn>)
Responses Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.
List pgsql-bugs
On Sun, 3 Apr 2022 at 16:50, Wong Simon <thbytwo@live.cn> wrote:
> If I run multiple instances on one server with local socket, how can I distinguish them?I think the port is need.

You distinguish them by the socket NAME whose "extension" is the port
as a decimal string. The socket name is derived from the port option,
but it is not a port. It's clearly specified:

inet_server_addr () → inet
Returns the IP address on which the server accepted the current
connection, or NULL if the current connection is via a Unix-domain
socket.

inet_server_port () → integer
Returns the IP port number on which the server accepted the current
connection, or NULL if the current connection is via a Unix-domain
socket.

I do not know if there is  an "unix_socket_path" option, as there can
be multiple sockets, may be those functions predate
unix_socket_directories being multivalued ( in TCP, with a single
socket listening on 0.0.0.0, you can have connection on different
local address, so it getsockname(2) is needed more ).

But if you just need to distinguish instance on diferent ports, query
the "port" configuration parameter, IIRC this is unique ( although may
be you can somehow reuse it with careful usage of listen_addresses and
unix_socket_directories ).

Francisco Olarte.



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.