-
Notifications
You must be signed in to change notification settings - Fork 8
feat(connection): multi-host failover (comma-separated hosts, psql parity) #743
Copy link
Copy link
Closed
Description
Problem
psql supports comma-separated host lists for failover:
psql -h host1,host2,host3 -p 5432 -U postgres
rpg does not. This is a psql parity gap that affects HA setups (Patroni, pgBouncer, etc.).
Spec
Follow libpq semantics exactly:
-h host1,host2,host3— try each in order, use first that accepts connection-p 5432,5433— per-host ports (must have 1 port or N ports matching N hosts)- URI form:
postgres://host1:5432,host2:5432/db - Connection string form:
host=host1,host2 port=5432 - Stop at first successful connection
- Error message when all hosts fail: list which hosts were tried and why each failed
Reference
- libpq docs: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS
- tokio-postgres already parses multi-host connstrings via
Config::from_str— leverage this
Implementation hints
src/connection.rs:ConnParamscurrently stores single host/port — extend toVec<(host, port)>connect()function needs retry loop over hosts- Error reporting: collect per-host errors, report all if all fail
- Integration tests: at least 2 Docker containers, test failover (first down, second up)
Acceptance criteria
rpg -h host1,host2 -U u -d dbworks (first host down → falls through to second)- URI and connstring forms work
- Error lists all attempted hosts when all fail
- Integration tests cover: first-host-fails, all-fail, single-host (regression)
- Existing connection tests still pass
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels