Skip to content

Config error: both host and hostaddr are missing #1239

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

Open
jayvdb opened this issue May 18, 2025 · 2 comments
Open

Config error: both host and hostaddr are missing #1239

jayvdb opened this issue May 18, 2025 · 2 comments

Comments

@jayvdb
Copy link

jayvdb commented May 18, 2025

According to https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

The default behavior when host is not specified, or is empty, is to connect to a Unix-domain socket in /tmp (or whatever socket directory was specified when PostgreSQL was built). On Windows, the default is to connect to localhost.

However tokio-posgres connect prevents host & hostaddr being omitted:

https://github.com/sfackler/rust-postgres/blob/02463b1/tokio-postgres/src/connect.rs#L20-L22

@sfackler
Copy link
Owner

Correct, the client does not implement that since it doesn't know what socket directory was specified when PostgreSQL was built.

@jayvdb
Copy link
Author

jayvdb commented May 18, 2025

On non-Windows, the pg client default is /tmp/.s.PGSQL.5432, however as you indicate it can be changed at the time the client is built.

On Windows, the default if it missing is host=localhost.

Can appreciate you may not want to support this.
I see on https://docs.rs/tokio-postgres/latest/tokio_postgres/config/struct.Config.html it says regarding host

Required if connecting with the connect method.

Perhaps that should be revised to say something like

Either host or hostaddr is required if connecting with the connect method.

And perhaps move that up to the top, so it is more prominent.

Interestingly under "Url" it says

All components are optional

How then does this client connect if all components of the Url are missing?

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

2 participants