-
-
Couldn't load subscription status.
- Fork 1.3k
Open
Description
Past Issues Searched
- I have searched open and closed issues to make sure that the bug has not yet been reported
Issue is a Bug Report
- This is a bug report and not a feature request, nor asking for self-hosted support
Using official Plausible Cloud hosting or self-hosting?
Self-hosting
Describe the bug
I’ve had a hard time troubleshooting this. The current logic for parsing DATABASE_URL, the postgres(ql):// connection URL, is incomplete.
Currently,
- PostgreSQL query-string connection parameters in
DATABASE_URL,?…=…&…=…, are not respected when using a Unix domain socket. - You cannot have Plausible use a Unix domain socket file other than
.s.PGSQL.5432.
The current URL parsing logic
Lines 483 to 508 in e7e553c
| db_socket_dir? = String.starts_with?(db_host, "%2F") or db_host == "" | |
| if db_socket_dir? do | |
| [database] = String.split(db_uri.path, "/", trim: true) | |
| socket_dir = | |
| if db_host == "" do | |
| db_host = (db_uri.query || "") |> URI.decode_query() |> Map.get("host") | |
| db_host || raise ArgumentError, "DATABASE_URL=#{db_url} doesn't include host info" | |
| else | |
| URI.decode_www_form(db_host) | |
| end | |
| config :plausible, Plausible.Repo, | |
| socket_dir: socket_dir, | |
| database: database | |
| if userinfo = db_uri.userinfo do | |
| [username, password] = String.split(userinfo, ":") | |
| config :plausible, Plausible.Repo, | |
| username: username, | |
| password: password | |
| end | |
| else | |
| config :plausible, Plausible.Repo, url: db_url |
- If the
hostpart of the URL begins with%2F(uppercase) or is empty:- It takes the
socket_dirfrom thehostpart or thehostquery-string parameter. - CAVEAT:
- Other query-string parameters, including
application_name,search_path, et cetera, are ignored. Currently, I’m specifyingpostgresql://user:password@%2FPostgreSQL%2Fsocket%2F/database?application_name=Plausiblefor myDATABASE_URL, but theapplication_nameparameter doesn’t make it into the PostgreSQL server log. - The
port, either in theportpart (:…) or in the query-string, is ignored. It should not, becauseportdetermines the suffix of the socket filename. For example,port = 1inpostgresql.confcreates the Unix domain socket.s.PGSQL.1, not.s.PGSQL.5432, the default. I had to comment outport = 1in mypostgresql.conffor this reason.
- Other query-string parameters, including
- It takes the
- Otherwise:
- The full URL gets passed (
config :plausible, Plausible.Repo, url: db_url) to the underlying driver, Postgrex. The query-string parameters would be respected. - CAVEAT:
- Postgrex does not like
%2f/%2Fin thehostpart, emitting the errornon-existing domain - :nxdomain. It means you cannot specify a Unix domain socket for thehost. - The clever trickery of having the
hostquery-string parameter override thehostpart of the URL, e.g.postgresql://user:password@fakehost/database?host=%2FPostgreSQL%2Fsocket%2F, could not establish the connection, either.
- Postgrex does not like
- The full URL gets passed (
Expected behavior
- PostgreSQL query-string connection parameters in
DATABASE_URLshould be respected in any case. - It should allow specifying
portfor the Unix domain socket filename suffix.
Screenshots
No response
Environment
The Docker image `ghcr.io/plausible/community-edition:v3.0.1`Metadata
Metadata
Assignees
Labels
No labels