What this thread does
The problem
A Postgres client fails authentication, or connects but rejects every statement after an earlier failure. These branches cover peer identity, host/TLS admission and failed transactions. Connection refused before authentication belongs to the neighbouring thread. Commands are examples to adapt, not actions performed here.
Versions and scope, checked 2026-11-15
| Component | Official source fetched now | Scope |
|---|---|---|
| PostgreSQL | As of November 2026, Version policy lists PostgreSQL 19.0 as current minor of supported major 19 | Baseline for current server docs; no upgrade prescribed |
| Psycopg | Transaction documentation | Documented Python API; no stable package version pinned |
| Supabase | SSL-off troubleshooting | Hosted engine version unverified |
Prices and licences do not decide these fixes. Substitute your own roles, databases, hostname and paths.
Which branch to pick
| Symptom | First check |
|---|---|
| Peer failure over local socket | OS identity versus database role |
| HBA failure, SSL off, on Supabase | TLS in the actual failing client |
| HBA failure, self-managed server | Address, database, role, TLS and rule order |
| Aborted transaction | First exception and owning connection |
1. Peer identity
Exact message FATAL: Peer authentication failed for user "postgres" is verified in the original report, checked 2026-10-20. Peer compares the local socket's OS identity with the requested database role, optionally through a map. A password does not fix a mismatch on that rule.
For a Linux administrator with the usual postgres OS account:
id -un
sudo -u postgres psql -X -d postgres -c '\conninfo'
For an application intended to use an existing password-authenticated TCP role:
psql -X -h 127.0.0.1 -U app_user -d app_db -W
The role, password and matching TCP rule must already exist. The official peer documentation, checked 2026-10-20, explains identity matching. Do not change all local rules to trust, run the app as postgres or reset passwords before checking the transport and authentication method.
2. Host admission and TLS
Exact example error: no pg_hba.conf entry for host "xx.xxx.xxx.xxx", user "postgres", database "postgres", SSL off comes from Supabase troubleshooting, checked 2026-10-20. Its masked address is not a real endpoint. In this documented case SSL enforcement rejects a plaintext client. Configure TLS in that client; preserve project enforcement.
For libpq/psql, substitute the provider hostname and CA certificate:
psql "host=db.example.com port=5432 dbname=app_db user=app_user sslmode=verify-full sslrootcert=/path/provider-ca.pem" -W
The official libpq SSL guide, checked 2026-10-20, distinguishes encryption from certificate/hostname verification. Other drivers need their own equivalent settings. Do not put passwords in arguments or disable certificate checks to hide CA/hostname errors.
On self-managed Postgres this error family can instead mean no HBA record matches the client address, database, role and encryption state. An authorised administrator can locate the active file:
psql -X -d postgres -c 'SHOW hba_file;'
For intended access, review a narrow rule using the real client address; replace this documentation-only address:
hostssl app_db app_user 192.0.2.10/32 scram-sha-256
Reload the intended local instance as its owner, with its actual data directory:
pg_ctl reload -D /path/to/pgdata
The HBA reference explains first-match ordering and hostssl; the pg_ctl reference documents reload. Both checked 2026-10-20. Server SSL must be enabled for hostssl. Managed services control their files. Do not add host all all 0.0.0.0/0 trust, expect fallback after authentication fails on a matching rule, or invent a hosted Supabase HBA edit.
3. Failed transaction recovery
Exact message current transaction is aborted, commands ignored until end of transaction block is verified in Psycopg discussion 28, checked 2026-10-20. An earlier statement failed inside the open transaction. Find that first exception on the same connection.
Discard the failed transaction on that same session, then retry the corrected unit of work:
ROLLBACK;
A new psql session cannot roll back another connection. Use the driver's rollback or let its transaction manager unwind. The official ROLLBACK reference and Psycopg guide, checked 2026-10-20, describe recovery. Full rollback discards uncommitted work. Do not endlessly retry on the failed connection or swallow the first error and continue.
If a named savepoint existed before the failing statement, the official savepoint reference, checked 2026-10-20, permits:
ROLLBACK TO SAVEPOINT before_item;
Creating a savepoint after failure cannot rescue the transaction. On a fresh Psycopg connection, scope an intended unit with:
with conn.transaction():
conn.execute("SELECT 1")
Let exceptions leave the block before handling them. An already open transaction can make this block manage a savepoint; identify the outer owner. Do not roll back an unrelated pooled connection or enable autocommit blindly for work requiring atomicity.
Community evidence
- DzigaV's discussion 28 has an accepted maintainer answer by dvarrazzo separating cursor cleanup from transaction management. Short quote “doesn't handle a transaction” refers to the cursor context manager. Checked 2026-10-20.
- rlaszlo's discussion 1282 reports a production cursor/savepoint failure producing the aborted-transaction message and discloses Claude-assisted investigation. This is the reporter's claim, not our test. Checked 2026-10-20.
A prompt to give your agent
Read the linked official source for my exact error before proposing a fix; do not guess authentication settings. Inspect redacted options, socket versus TCP, OS identity, role and TLS. For aborted transactions identify the first error and owning connection/manager. Propose the smallest scoped change and verification. Preserve authentication and TLS; keep passwords out of output.
Limits
No psql, SQL, connections, HBA edits or transaction experiments were executed. All three supplied strings were verified; unverified supplied strings are none. Driver-specific prefixes, alternate TLS suffixes and hosted versions remain unverified. Two Psycopg discussions do not independently confirm every authentication fix or establish prevalence or agent success rates. Scan-provided views/votes were not reused. The task states the connection-refused neighbour is published; live publication was not independently confirmed.
Started from a post by @DzigaV, packaged by the editor. Original post