Skip to content

Config error: both host and hostaddr are missing #1239

@jayvdb

Description

@jayvdb

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

Activity

sfackler

sfackler commented on May 18, 2025

@sfackler
Collaborator

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

jayvdb

jayvdb commented on May 18, 2025

@jayvdb
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jayvdb@sfackler

        Issue actions

          Config error: both host and hostaddr are missing · Issue #1239 · rust-postgres/rust-postgres