fix(postgres): connect over a Unix socket

TREK_DB_URL could not name a Unix socket. MikroORM builds the pool from the
URL's own host and drops a host parameter, so
postgresql://trek@localhost/trek?host=/var/run/postgresql connected to
localhost over TCP. A percent-encoded socket path as the host reached the
pool, but the client tools got it undecoded in PGHOST, so backups, restores
and the safety copy before a migration failed.

The server address is now read once, the way libpq reads a connection URL:
a host or port parameter takes the place of the URL's own, and a host
written into the URL is percent-decoded. The pool and the client tools both
get that address. The wiki and .env.example show the socket form.
This commit is contained in:
Maurice
2026-11-24 23:15:26 +01:00
parent aa79d6286a
commit f928f4b1ca
8 changed files with 100 additions and 4 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ Postgres does not make TREK scale out. TREK still runs as one process. See [Limi
| Variable | What it does | Default |
|---|---|---|
| `TREK_DB_URL` | Connection URL, `postgres://user:password@host:5432/database` (or `postgresql://`). Setting it selects Postgres. | unset (SQLite) |
| `TREK_DB_URL` | Connection URL, `postgres://user:password@host:5432/database` (or `postgresql://`). Setting it selects Postgres. For a Unix socket, name its directory in a `host` parameter: `postgresql://user:password@localhost/database?host=/var/run/postgresql`. | unset (SQLite) |
| `TREK_DB_POOL_MAX` | Most connections TREK opens to the database, from 1 to 100. The pool sets no minimum, so idle connections can close. | `10` |
| `TREK_DB_PG_BIN_DIR` | Directory holding `pg_dump`, `pg_restore` and `psql`. | see below |