will / crystal-pg

a postgres driver for crystal
BSD 3-Clause "New" or "Revised" License
462 stars 77 forks source link

bugfix: treat PGHOST env var as directory when it's a path #269

Closed will closed 1 year ago

will commented 1 year ago

This change makes the driver find the actual socket file and is consistent with how libpq appends .s.PGSQL.5432 to the value of the env var when it's a path:

❯ mkdir -p /tmp/foo && PGHOST=/tmp/foo psql
psql: error: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/foo/.s.PGSQL.5432"?

When the value is a domain the behavior doesn't change

ysbaddaden commented 11 months ago

Documentation says that the socket is .s.PGSQL.nnnn where nnnn is the server port, so it's possible to start a Postgres server on the non default port, and that would affect the UNIX socket file? Maybe the PG shard should try to use PGPORT when specified?

It's an oddball edge case, but :shrug:

will commented 11 months ago

Yeah that looks like what psql using libpq does, so it's not unreasonable. Right now people can specify the path manually, but it could be nice to still get the automatic search to work too