Configuration
Pass comma-separated hosts inDATABASE_URL:
- psycopg (LangGraph pool) receives the URL as-is — libpq natively supports comma-separated hosts
- asyncpg (SQLAlchemy pool) receives a rewritten URL with hosts and ports as query parameters, which is the format asyncpg requires for multi-host connections
target_session_attrs
PostgreSQL’starget_session_attrs parameter controls which host is selected from the list. Append it as a query parameter:
| Value | Behavior |
|---|---|
any | Connect to the first available host |
read-write | Only connect to a host accepting writes (primary) |
read-only | Only connect to a read-only host (standby) |
prefer-standby | Prefer standby, fall back to primary |
primary | Only connect to the primary |
standby | Only connect to a standby |
target_session_attrs or use any — Aegra needs a writable connection for metadata and checkpoints, and standalone primaries satisfy all session attribute filters.
Pool recovery
Aegra’s SQLAlchemy pool is configured withpool_pre_ping=True. This means each connection is validated with a lightweight ping before use. When a host goes down:
- Existing pooled connections to the dead host fail the ping check
- The pool discards the dead connection
- A new connection is created using the multi-host URL
- The driver tries each host in order until one responds
Limitations
- IPv6 addresses must use bracket notation:
[::1]:5432,[::2]:5433 - Ports must be numeric. Non-numeric ports (e.g.
host:abc) are rejected at startup with a clear error - Individual
POSTGRES_*fields do not support multi-host — useDATABASE_URL - Multi-host does not provide load balancing — the driver connects to the first responsive host