Direct PostgreSQL Routing (`x-pg-uri`)
Route gateway and SQL requests directly to PostgreSQL without requiring X-Athena-Client when URI credentials are present.
This page is the source of truth for Athena direct PostgreSQL routing using
x-pg-uri (preferred) and compatibility JDBC-style headers.
What this mode does
Direct routing lets callers target PostgreSQL without first resolving a registered Athena client name.
- Preferred header:
x-pg-uri - Compatibility headers:
x-athena-jdbc-url,x-jdbc-url,X-JDBC-URL - JDBC forms are normalized (
jdbc:postgresql://...-> PostgreSQL URI form)
Header precedence and normalization
When multiple direct headers are present, Athena treats them through one canonical parser with this priority:
x-pg-urix-athena-jdbc-urlx-jdbc-url/X-JDBC-URL
Athena then validates that the resolved URI targets PostgreSQL.
Credential requirement for keyless direct routing
Keyless direct routing is only allowed when URI credentials contain both:
- username
- password
Example accepted credentialed URI:
postgres://app_user:app_password@db.example.com:5432/app_dbExample that does not qualify for keyless bypass:
postgres://db.example.com:5432/app_dbWithout both credentials, normal API key auth applies.
Route coverage matrix
| Route surface | Direct URI headers accepted | Keyless allowed when URI has user+password | Notes |
|---|---|---|---|
/gateway/fetch, /gateway/data, /gateway/update, /gateway/insert, /gateway/delete, /gateway/query | Yes | Yes | X-Athena-Client optional in this path |
/query/sql, /gateway/sql with driver: postgresql or driver: postgres | Yes | Yes | Keyless bypass is scoped to PostgreSQL driver path only |
/query/sql, /gateway/sql with driver: athena/scylla/supabase | Headers may be present but bypass is not applied | No | Standard auth still required |
Non-gateway surfaces (/pipelines, /schema/*, /storage/*, /management/*, /admin/*, etc.) | Not part of direct PG bypass contract | No | Use standard client + key model |
Auth and routing decision flow
For eligible PostgreSQL gateway routes and PostgreSQL SQL-driver requests:
- Resolve direct URI header (preferred
x-pg-uri, then compatibility headers). - Normalize URI input and validate PostgreSQL target format.
- If no API key is supplied and URI has both username and password, allow direct bypass.
- Otherwise apply normal API key enforcement rules.
This keeps non-PostgreSQL and non-gateway paths protected by default.
Operational behaviors with direct URI requests
- Wildcard host client inference is skipped when a direct PostgreSQL URI header is present.
- Deferred gateway queue execution is skipped for direct URI requests; execution is inline.
- Athena uses a deterministic opaque token for request identity (logs/cache/webhooks) so raw URI credentials are not exposed.
Request examples
Gateway fetch with keyless direct URI
curl -X POST "http://localhost:4052/gateway/fetch" \
-H "content-type: application/json" \
-H "x-pg-uri: postgres://app_user:app_password@db.example.com:5432/app_db" \
-d '{
"table_name": "events",
"conditions": [{ "eq_column": "type", "eq_value": "checkout.completed" }],
"limit": 50
}'Gateway query using compatibility JDBC header
curl -X POST "http://localhost:4052/gateway/query" \
-H "content-type: application/json" \
-H "x-athena-jdbc-url: jdbc:postgresql://db.example.com:5432/app_db?user=app_user&password=app_password" \
-d '{
"query": "select now() as ts"
}'SQL driver path (driver: postgresql) with keyless direct URI
curl -X POST "http://localhost:4052/query/sql" \
-H "content-type: application/json" \
-H "x-pg-uri: postgres://app_user:app_password@db.example.com:5432/app_db" \
-d '{
"driver": "postgresql",
"query": "select count(*) from events",
"db_name": "app_db"
}'SQL driver path (driver: supabase) still requires standard auth
curl -X POST "http://localhost:4052/query/sql" \
-H "content-type: application/json" \
-H "x-athena-client: analytics" \
-H "x-athena-key: <gateway-or-admin-key>" \
-d '{
"driver": "supabase",
"query": "select 1",
"db_name": "analytics"
}'Troubleshooting
| Symptom | Typical cause | Fix |
|---|---|---|
| Request still asks for key | URI missing username or password | Provide credentialed URI or send standard API key |
driver path still requires key | Driver is not PostgreSQL | Use PostgreSQL driver for direct bypass or keep key auth |
| Direct URI rejected for host policy | Host policy restriction | Review gateway.jdbc_allow_private_hosts / gateway.jdbc_allowed_hosts |
| Host-based wildcard route not applied | Direct header present | Expected behavior; direct URI takes precedence |