Discussion:
change the value of "unix_socket_directories" , must used "-h /xx/xx" to use the Unix domain socket
lin
2014-08-16 15:41:02 UTC
Permalink
Hi all,
I change the value of "unix_socket_directories" in postgresql.conf , then restart the database, but it cannot connect the database used like this
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx" to use the Unix domain socket¡£
how to fix this issue ?


the test steps as below :
[***@localhost postgres9.3]$ cat data/postgresql.conf | grep unix_socket_directories
unix_socket_directories = '/tmp/wln' # comma-separated list of directories


[***@localhost postgres9.3]$ psql -d postgres -p 5432
psql: could not connect to server: No such file or directory.
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[***@localhost postgres9.3]$ psql -d postgres -p 5432 -h /tmp/wln
psql (9.3beta2)
Type "help" for help.


postgres=# \q
[***@localhost postgres9.3]$


Thanks,
waln
John R Pierce
2014-08-16 15:49:08 UTC
Permalink
Post by lin
I change the value of "unix_socket_directories" in postgresql.conf ,
then restart the database, but it cannot connect the database used
like this
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx"
to use the Unix domain socket。
how to fix this issue ?
the client has no access to postgresql.conf, it has no idea you changed
it. the default value is baked into libpq.so at compile time.
--
john r pierce 37N 122W
somewhere on the middle of the left coast
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Steve Atkins
2014-08-16 15:56:13 UTC
Permalink
I change the value of "unix_socket_directories" in postgresql.conf , then restart the database, but it cannot connect the database used like this
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx" to use the Unix domain socket。
how to fix this issue ?
the client has no access to postgresql.conf, it has no idea you changed it. the default value is baked into libpq.so at compile time.
You might find the environment variable PGHOST useful.

Cheers,
Steve
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Guillaume Lelarge
2014-08-16 15:49:59 UTC
Permalink
Post by lin
Hi all,
I change the value of "unix_socket_directories" in postgresql.conf ,
then restart the database, but it cannot connect the database used like
this
Post by lin
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx" to
use the Unix domain socket。
Post by lin
how to fix this issue ?
That ain't an issue. The client, psql here, can't know where the server put
the socket if it isn't in the default location.
unix_socket_directories
Post by lin
unix_socket_directories = '/tmp/wln' # comma-separated list of directories
psql: could not connect to server: No such file or directory.
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
psql (9.3beta2)
Type "help" for help.
postgres=# \q
Thanks,
waln
Nick Guenther
2014-08-16 16:01:23 UTC
Permalink
Post by lin
Hi all,
I change the value of "unix_socket_directories" in postgresql.conf ,
then restart the database, but it cannot connect the database used like
this
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx"
to use the Unix domain socket。
how to fix this issue ?
I'll start by saying that your test case is very clear, and thank you for it. I am unsure what your goal is, however. I assume you are trying to set up parallel postgres processes, for debugging. I've done this recently, for that reason.

First thing to point out is that you need only one of -h and -p. They are redundant options, because you only connect to postgres either over TCP (-p) or with a unix domain socket (-h).

Second, what you're seeing is necessary. If you change the default, then psql doesn't know where to look. However, you can recover the old behaviour with shell tricks:
$ alias psql='psql -h /xx/xx'
$ psql -d postgres

(Personally, I wrote a short wrapper script called "client.sh" which depth-first searches for a postgres db directory and the runs 'psql -h' with the first one it finds; equally well you could have this script install an alias)

Are you perhaps confused about what a unix domain socket is? Why are you changing it? This is a decent description of it:
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man4/unix.4
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
John R Pierce
2014-08-16 16:06:38 UTC
Permalink
Post by Nick Guenther
First thing to point out is that you need only one of -h and -p. They are redundant options, because you only connect to postgres either over TCP (-p) or with a unix domain socket (-h).
what??!? no, this is totally wrong.

psql -h myserver -p 5435

psql -h /path/to/socket -p 5433

those are both valid. if there is no hostname, OR the hostname starts
with /, then it uses a unix domain socket.
--
john r pierce 37N 122W
somewhere on the middle of the left coast
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Steve Atkins
2014-08-16 16:16:41 UTC
Permalink
Post by Nick Guenther
Post by lin
Hi all,
I change the value of "unix_socket_directories" in postgresql.conf ,
then restart the database, but it cannot connect the database used like
this
"psql -d postgres -p 5432" , it must given the parameter " -h /xx/xx"
to use the Unix domain socket。
how to fix this issue ?
I'll start by saying that your test case is very clear, and thank you for it. I am unsure what your goal is, however. I assume you are trying to set up parallel postgres processes, for debugging. I've done this recently, for that reason.
First thing to point out is that you need only one of -h and -p. They are redundant options, because you only connect to postgres either over TCP (-p) or with a unix domain socket (-h).
Not really. In the case of a TCP connection you need -h for the hostname and -p for the port. For a unix socket connection you use -h to specify the directory the unix socket is in, and -p is used to generate the name of the socket within that directory. If you omit one or both then the compiled-in defaults will be used, but it still uses both values to connect.
Post by Nick Guenther
$ alias psql='psql -h /xx/xx'
$ psql -d postgres
Setting environment variables to point to your preferred instance will also work - and it'll work with any client that uses libpq (which is probably almost everything that's not java).

Cheers,
Steve
Post by Nick Guenther
(Personally, I wrote a short wrapper script called "client.sh" which depth-first searches for a postgres db directory and the runs 'psql -h' with the first one it finds; equally well you could have this script install an alias)
http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man4/unix.4
--
http://www.postgresql.org/mailpref/pgsql-general
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
John R Pierce
2014-08-16 16:25:16 UTC
Permalink
Post by Steve Atkins
Setting environment variables to point to your preferred instance will also work - and it'll work with any client that uses libpq (which is probably almost everything that's not java).
java/jdbc doesn't support unix domain sockets anyways, so that's moot
for the OP's issue.
--
john r pierce 37N 122W
somewhere on the middle of the left coast
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Tom Lane
2014-08-16 16:39:20 UTC
Permalink
Post by John R Pierce
Post by Steve Atkins
Setting environment variables to point to your preferred instance will also work - and it'll work with any client that uses libpq (which is probably almost everything that's not java).
java/jdbc doesn't support unix domain sockets anyways, so that's moot
for the OP's issue.
Another idea (which is also only for libpq-based apps) is to set up
a "service" file.

http://www.postgresql.org/docs/9.3/static/libpq-pgservice.html

regards, tom lane
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...