Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Wong Simon <thbytwo(at)live(dot)cn>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.
Date: 2022-04-03 15:35:56
Message-ID: CA+bJJbzPYe4py-dnzoKEQ9_m_rvduTs_8BSThwWPUUamSK18dQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sun, 3 Apr 2022 at 16:50, Wong Simon <thbytwo(at)live(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2022-04-03 15:50:40 Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.
Previous Message David G. Johnston 2022-04-03 01:40:32 Re: BUG #17454: Using psql without ipv4 address,the inet_server_port do not return PORT.