will / crystal-pg

a postgres driver for crystal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connecting to unix socket with url

tleydxdy opened this issue · comments

I tried various forms such as

postgres://user:pass@/dbname
postgres://user:pass@/dbname?host=/var/run/postgresql
postgres://user:pass@%2Fvar%2Frun%2Fpostgresql/dbname

but they all doesn't seem to work

Hm, it might not be currently possible with a url.

The relevant code is here: https://github.com/will/crystal-pg/blob/master/src/pq/conninfo.cr#L52

This will use a socket if the host parameter starts with a / character. However the crystal stdlib URI.parse might make it impossible to get a host starting with that. I'm unsure what can be done about this.

As an alternative, you should be able to do "host=/var/run/postgresql user=user password=password" or with a bit more effort construct a PQ::ConnInfo directly.

yeah, I'm using someone else's code, I will see what I can do.

aha, postgres://user:pass@/dbname?host=/var/run/postgresql worked, I just made some silly mistake. :(