Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL Unix Domain Sockets with DATABASE_URL #1202

Closed
EvanCarroll opened this issue Apr 30, 2021 · 3 comments
Closed

PostgreSQL Unix Domain Sockets with DATABASE_URL #1202

EvanCarroll opened this issue Apr 30, 2021 · 3 comments

Comments

@EvanCarroll
Copy link

I can connect to a database just fine using this,

let opts = PgConnectOptions::new().host("/run/postgresql").port(5432);

However, I can't figure out how to get that into DATABASE_URL, without which the macros don't work.

The docs say,

If a host name begins with a slash, 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. The default behavior when host is not specified, or is empty, is to connect to a Unix-domain socket

That doesn't seem to be true, if empty like

DATABASE_URL=postgres://:5432

I get,

error: empty host

If I try to set it to a directory,

DATABASE_URL=postgres:///run/postgresql:5432/

I get

error: error returned from database: database "run/postgresql:5432/" does not exist

@EvanCarroll EvanCarroll changed the title To use the macros DATBASE_URL must be set, how do we set when using Unix Domain sockets. PostgreSQL Unix Domain Sockets with DATABASE_URL Apr 30, 2021
@EvanCarroll
Copy link
Author

I found the solution,

DATABASE_URL=postgres:///?port=5432&host=/run/postgresql

@jplatte
Copy link
Contributor

jplatte commented May 2, 2021

There is no such thing as a port for a unix socket afaik, it should work the same without that.

@abonander
Copy link
Collaborator

For the record, Postgres does use the port for namespacing the socket file. This is likely used to allow multiple server instances to use a separate socket each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants