crystal-pg icon indicating copy to clipboard operation
crystal-pg copied to clipboard

Uncommon syntax for unix socket connections

Open Caian opened this issue 1 year ago • 3 comments

The only way to connect to my socket is by passing ?host=/postgres/.s.PGSQL.5432 to my database URL. This is quite unusual as all pieces of software I've worked so far used the socket directory instead. Is this the expected behavior?

Caian avatar Dec 29 '24 11:12 Caian

I copied how libpq does it: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-HOST

host Name of host to connect to. If a host name looks like an absolute path name, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. (On Unix, an absolute path name begins with a slash.

will avatar Dec 29 '24 11:12 will

You can also use PGHOST env variable and leave the connection string almost empty.

See last spec of conninfo_spec.

bcardiff avatar Dec 29 '24 11:12 bcardiff

I copied how libpq does it: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-HOST

host Name of host to connect to. If a host name looks like an absolute path name, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. (On Unix, an absolute path name begins with a slash.

Hi Will, in libpq-connect host is passed as a directory containing the socket, not the socket itself.

Caian avatar Dec 29 '24 12:12 Caian