Skip to content

feat(connection): multi-host failover (comma-separated hosts, psql parity) #743

@NikolayS

Description

@NikolayS

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

Implementation hints

  • src/connection.rs: ConnParams currently stores single host/port — extend to Vec<(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 db works (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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions