Skip to content

Respect the port in DATABASE_URL for PostgreSQL Unix sockets - #6877

Open
officialasishkumar wants to merge 1 commit into
plausible:masterfrom
officialasishkumar:respect-port-in-postgres-unix-socket-url
Open

officialasishkumar wants to merge 1 commit into
plausible:masterfrom
officialasishkumar:respect-port-in-postgres-unix-socket-url

Conversation

@officialasishkumar

Copy link
Copy Markdown

Changes

Part of #5593 (the port part of the report)

When DATABASE_URL points to a Unix socket directory (a %2F-encoded host, or an empty host with a host query parameter), the port was dropped. PostgreSQL appends the port to the socket file name (.s.PGSQL.<port>), so Postgrex always connected to .s.PGSQL.5432 and a server listening on another port could not be reached over a socket.

The port is now read from the URL authority or from the port query parameter and passed to the repo config:

DATABASE_URL=postgresql://user:pass@%2Frun%2Fpostgresql:5433/plausible_db
DATABASE_URL=postgresql:///plausible_db?host=/run/postgresql&port=5433

A port that is not an integer raises an ArgumentError on boot instead of being silently ignored. URLs without a port behave as before.

Tests

  • Automated tests have been added

Changelog

  • Entry has been added to changelog

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

When `DATABASE_URL` pointed to a Unix socket directory (a `%2F`-encoded
host or an empty host with a `host` query parameter), the port was
dropped. PostgreSQL appends the port to the name of the socket file
(`.s.PGSQL.<port>`), so Postgrex always connected to `.s.PGSQL.5432` and
instances running on another port could not be reached over a socket.

The port is now read from the URL authority
(`postgresql://user:pass@%2Frun%2Fpostgresql:5433/db`) or from the `port`
query parameter (`postgresql:///db?host=/run/postgresql&port=5433`) and
passed to the repo config. A port that is not an integer raises an
`ArgumentError` on boot instead of being silently ignored.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants