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:
Resorting to string parsing is never desirable, nor is it necessary here.
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 ).
Per the docs It is indeed single-valued. I don't know what "reuse" would mean in this context but both sockets and IP have a specific usage of this setting's value that the DBA cannot alter.
One could also inspect data_directory, it has the same "unique per cluster on the same machine" property.
The function inet_server_addr() can help to distinguish which machine if there are multiple. Though what "local" means may be a problem. I suppose what is useful depends on "why" one needs to distinguish them.