Skip to content

Init-generated connection string fails at daemon startup with "empty host" when --pg-host is a Unix socket path #52

@quinnypig

Description

@quinnypig

Summary

extenddb init writes a PostgreSQL connection string into extenddb.toml and into the catalog settings.data_database_connection_string field that fails to parse at daemon startup. Following the documented peer-authentication path in docs/getting-started.md produces an install the daemon refuses to start.

Repro

Ubuntu 24.04, fresh Postgres 16:

sudo apt-get install -y postgresql postgresql-contrib
echo 'local all extenddb scram-sha-256' \
  | sudo tee -a /etc/postgresql/16/main/pg_hba.conf
sudo systemctl reload postgresql

cargo build --release
./target/release/extenddb init \
    --pg-host /var/run/postgresql \
    --extenddb-pass 'extenddb-test-pw'
# init succeeds, prints admin credentials, writes extenddb.toml

./target/release/extenddb serve --config extenddb.toml
# Server failed to start: daemon process exited during startup.

sudo journalctl -t extenddb -n 5
# extenddb fatal: Failed to connect to postgres: Connection error:
# error with configuration: empty host

What init wrote

extenddb.toml:

[storage.postgres]
connection_string = "postgresql://extenddb:***@/var/run/postgresql:5432/extenddb_catalog"

extenddb_catalog.settings:

data_database_connection_string |
postgresql://extenddb:***@/var/run/postgresql:5432/extenddb

The @/var/run/postgresql:5432/ segment is the problem. Unencoded forward slashes in the host portion make the URL ambiguous, and the sqlx/libpq parser the daemon uses rejects it with empty host. The init code apparently builds its connection from discrete --pg-host/--pg-port flags rather than from the URL it later writes, so init succeeds and the daemon fails.

Workaround

After hitting this, the user has to:

  1. Edit extenddb.toml to change the connection string.
  2. psql extenddb_catalog -c "UPDATE settings SET value=... WHERE key='data_database_connection_string';" to fix the data-database connection string the daemon reads separately.

After both edits, the daemon starts.

Suggested fix

The connection-string assembly should either percent-encode the host portion (postgresql://extenddb:***@%2Fvar%2Frun%2Fpostgresql:5432/extenddb_catalog) or use the host= parameter form (postgresql://extenddb:***@localhost:5432/extenddb_catalog?host=/var/run/postgresql). A test that round-trips a generated URL through sqlx::postgres::PgConnectOptions::from_url would catch this.

Environment

  • ExtendDB: v0.1.0 (HEAD as of release tag)
  • OS: Ubuntu 24.04.4 LTS, aarch64
  • PostgreSQL: 16.13 (Ubuntu 16.13-0ubuntu0.24.04.1)
  • Rust: 1.94.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions