postgresql – How to psql on a specific PG server

You must specify the correct port for your installed server instance. psql -h -p can be used to specify the TCP endpoint of the desired server. If you have 2 servers running, they must differ from the configured port.

If your -h The parameter starts with a slash, it will not use TCP, but will assume that you specified the name of a local unix domain socket (which only works on the database machine and not on Windows I think by default, the path also includes the port number).

There are also environment variables that can be used instead or via .pg_service.conf.

See "Connecting to a Database".