Skip to content

Postgres: verify and document Unix-socket DSN (host=/var/run/postgresql) #944

Closed

Description

@fclairamb

From a user comment on the feddit.org project post (https://feddit.org/post/38184275, comment https://feddit.org/comment/16144435, 2026-11-18):

Ich habe nur einen kurzen Blick drauf geworfen, ist eine Postgresverbindung via Unixsockets möglich (host = /var/run/postgresql)?

The Postgres DSN is passed through unchanged to bun's pgdriver (pgdriver.WithDSN(cfg.DSN) in server/internal/db/postgres/postgres.go), which builds on lib/pq — and lib/pq supports Unix-domain sockets when host is an absolute path. So host=/var/run/postgresql should work, but it is not tested or documented anywhere.

Task: verify with a real Unix-socket Postgres (e.g. a local cluster with the TCP listener off), add a test or a documented example DSN, and mention it in the self-hosting docs. Relevant for single-box installs where Postgres listens only on the socket.

Source: https://feddit.org/comment/16144435

Activity

  1. Morethanevil commented on Nov 19, 2026

    @Morethanevil

    Tried to connect with different ways, mostly copied from other services, which use unix sockets already and Stackoverflow.

    Why could this be important to users: It is very easy to mount the socket file in a container and use the host postgres installation for containers too without setting permissions in pg_hba.conf or listening on all ports in postgresql.conf.

    In Docker the users could mount the file with:

        volumes:
          - /some/data:/app/data
          - /var/run/postgresql:/var/run/postgresql
    

    USER: testuser
    PASSWORD: testpw
    DATABASE: testdb

    CachyOS LXC, Solidping Binary -> Postgresql on host

    Working:

    postgres://testuser:testpw@/testdb?sslmode=disable
    postgres://testuser:testpw@localhost:5432/testdb?sslmode=disable
    

    Not working:

    postgres://testuser:testpw@%2Fvar%2Flib%2Fpostgresql/testdb?sslmode=disable
    postgres://testuser:testpw@/testdb?sslmode=disable&host=/var/run/postgresql
    postgres://testuser:testpw@/testdb?host=/var/run/postgresql&sslmode=disable
    postgres://testuser:testpw@localhost:5432/testdb?sslmode=disable&host=/var/run/postgresql
    postgres://testuser:testpw@localhost:5432/testdb?host=/var/run/postgresql&sslmode=disable
    

    I hope, that this helps you a little bit. I am in to do some more testing!

  2. added
    fix-pending
    on Nov 19, 2026
  3. fclairamb commented on Nov 19, 2026

    @fclairamb
    OwnerAuthor

    Fixed in 2af6edd7 on branch wt/feat/todos-2026-11-18-2: the root cause was that bun's pgdriver dials the host value itself, so host=/var/run/postgresql (the libpq convention, a socket directory) never reached the .s.PGSQL.5432 file inside it. SolidPing now rewrites a socket-directory host to the socket file for pgdriver (and keeps the directory form for the lib/pq LISTEN connection). Supported forms: postgresql://user:pass@/db?host=/var/run/postgresql&sslmode=disable (add &port=5433 for a non-default port), or host=/var/run/postgresql/.s.PGSQL.5432. A percent-encoded host (@%2Fvar%2F...) is rejected by Go's URL parser, so use the host parameter. A test runs Postgres with TCP off and connects through both drivers. Thanks @Morethanevil for the detailed attempts, which pinned it down. Not merged yet: closing because the fix exists, the branch's PR carries it live.

  4. fclairamb commented on Nov 19, 2026

    @fclairamb
    OwnerAuthor

    autopilot: in #939

  5. Morethanevil commented on Nov 20, 2026

    @Morethanevil

    Tried out again with docker and mounted socket file and on bare metal:

    Works:

    # TCP
    
    postgres://testuser:testpw@/testdb?sslmode=disable
    postgres://testuser:testpw@localhost:5432/testdb?sslmode=disable
    
    # Sockets
    
    postgres://testuser:testpw@/testdb?sslmode=disable&host=/var/run/postgresql
    postgres://testuser:testpw@/testdb?host=/var/run/postgresql&sslmode=disable
    

    Doesn't work:

    # Sockets
    
    postgres://testuser:testpw@%2Fvar%2Flib%2Fpostgresql/testdb?sslmode=disable
    
    # Host appended at the end should overwrite the previous one (at least this is my experience), but Solidping ignores this and connects to TCP anyway :)
    
    postgres://testuser:testpw@localhost:5432/testdb?sslmode=disable&host=/var/run/postgresql
    postgres://testuser:testpw@localhost:5432/testdb?host=/var/run/postgresql&sslmode=disable
    

    Sockets are working now, maybe put an example string into the docs. Thanks!

  6. fclairamb commented on Nov 20, 2026

    @fclairamb
    OwnerAuthor

    Thanks for retesting on both setups, glad the socket forms work.

    On the two that don't:

    And agreed on the docs: #960 tracks adding the working socket DSN as an example.

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

    autopilotfix-pending

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions