# Troubleshooting

> Common failures, their symptoms and fixes, including known issues of the candidate.

---

LLMS index: [llms.txt](/llms.txt)

---

When diagnosing an issue, record the gateway version (`pgetcd --version`), source commit, command flags, and exact error text with timestamps. Never include database passwords, private keys, or raw tenant payload values in bug reports.

## Startup failures {#startup}

| Symptom | Cause and fix |
| --- | --- |
| `select exactly one...` | Specify exactly one mode flag (`--tenant-config`, `--p0-fixture`, or `--qualification-config`) and remove positional arguments |
| `PGETCD_DSN required` | Export `PGETCD_DSN` in the gateway process environment |
| `invalid tenant configuration` | Check JSON syntax, unknown or duplicate keys, field types, and the `65,536`-byte file size limit |
| Listener rejected | Use explicit `IP:port` addresses and distinct non-zero ports for `listen` and `diagnostics_listen` |
| `tenant storage configuration rejected` | Ensure `PGETCD_DSN` connects to the same `database` and `role` as the tenant JSON and uses `sslmode=verify-full` on every host |
| Startup ABI, identity, or readiness check failed | Verify `CREATE EXTENSION pg_etcd`, stored `cluster_id` / `member_id`, primary status, and `pg_etcd.databases` |
| Startup certification deadline reached | The 10-second startup check timed out waiting for `COMMIT`; inspect PostgreSQL lock or synchronous-replication waits |
{.wide}

Startup allows 10 seconds to certify the SQL ABI, persistent identity, and Lease readiness. It retries only when a transaction commits normally with `ready = false` (for example while the Lease worker finishes rebuilding). It never retries a SQL error or an unknown `COMMIT`.

## TLS and authentication failures {#tls}

Troubleshoot the two TLS hops separately:

1. **Client to gateway (`listen` and `diagnostics_listen`)**:
   - Confirm that the client certificate chains to `tls.client_ca` and carries the URI SAN `spiffe://pgetcd/tenant/<tenant>`.
   - If `tls.server_name` is set, confirm that the client dials that exact DNS name and sends matching SNI. If `tls.server_name` is empty, confirm that `public_urls` and the server certificate IP SAN match the IP address dialed by the client.
2. **Gateway to PostgreSQL (`PGETCD_DSN`)**:
   - Confirm `sslmode=verify-full`, `sslrootcert`, and hostname matching against the PostgreSQL server certificate.
   - Check every fallback host in `PGETCD_DSN`; any plaintext or unverified TLS option causes the gateway to reject the DSN.
   - Do not confuse the SQL client certificate (`sslcert` / `sslkey` for `pg_hba.conf`) with the etcd tenant client certificate.

## Readiness failures {#readiness}

`/livez` can return `200 OK` while `/readyz` returns `503` (`{"health":false}`) and gRPC requests return `Unavailable: tenant is not ready`.

Run `diag.status` as the PostgreSQL administrator to inspect the typed readiness fields:

```sql
BEGIN ISOLATION LEVEL READ COMMITTED;
SET LOCAL synchronous_commit = on;
SELECT etcd._execute(
  '{"abi":"1","method":"diag.status","request":{}}'::jsonb
);
COMMIT;
```

Check `response.not_ready_reasons` and the surrounding fields:

- **`lease_rebuilding`**: The `pg_etcd` background worker is still reconstructing full Lease TTLs after startup. Wait for rebuild to finish and re-run the transaction.
- **`worker_unavailable`**: Verify that `shared_preload_libraries` includes `pg_etcd`, the database name is listed in `pg_etcd.databases` (at most 8 databases), and `max_worker_processes` has enough free slots.
- **`primary_required`**: The connected PostgreSQL instance is in recovery (`pg_is_in_recovery()` is `true`). Point `PGETCD_DSN` at the primary and restart the gateway.
- **`identity_mismatch`, `schema_mismatch`, or `profile_mismatch`**: The stored `cluster_id` or `member_id` in `etcd.meta`, or the installed extension version, does not match the gateway configuration. After a restore or database swap, verify the intended database before editing `tenant.json`; changing IDs merely to bypass the check can corrupt client revision history.

## Capacity and Watch errors {#capacity}

- **`ResourceExhausted` on KV or Lease calls**: Compare the request against the [resource limits](/docs/etcd/compatibility/#limits) (`1.5 MiB` gRPC receive, `2,048`-byte write key, `8 MiB` KV response tree, `4,096` events and `8 MiB` per complete revision, `1,024` Leases per database, `4,096` keys per Lease). Remember that attaching a key to a Lease also checks whether revoking the entire Lease would exceed the `8 MiB` / `4,096`-event revision budget.
- **`ResourceExhausted` or `Unavailable` on Watch streams**: A slow consumer can exhaust its per-stream queue or the tenant's `watch_max_tenant_bytes` budget. Reconnect from `last_processed_revision + 1`, or take a new `Range` snapshot if history was compacted. Note that a watcher registered with a future `start_revision` blocks stream-level progress notifications on the same gRPC stream until that revision arrives or the watcher is canceled.

## Unknown COMMIT outcomes {#unknown-commit}

If the connection between the gateway and PostgreSQL drops, times out, or is canceled while `COMMIT` is in flight, the transaction may or may not have committed in PostgreSQL.

- The gateway never publishes a buffered response without a confirmed synchronous `COMMIT`, and it never replays an unknown `COMMIT` automatically.
- Before retrying a non-idempotent write, the client application must read current state (`Range`) or use a conditional `Txn` (`Compare` on `version` or `mod_revision`) to check whether the earlier write already took effect. Blindly retrying a write can apply the mutation twice and allocate a second revision.

## Workarounds for v0.1.0-rc2 known issues {#known-issues}

| Symptom in `v0.1.0-rc2` | Cause and workaround |
| --- | --- |
| Watch events arrive late during sustained heavy writes | The Watch reader reads one revision per `_tail_v2` transaction and shares publication slots with client requests, so near the throughput limit (about 600 ops/s on the measured host) it falls behind. The stream stays connected and catches up when writes drop. Keep sustained write rates below that level if Watch latency matters. |
| Requests fail with `ResourceExhausted: publication capacity exhausted` | More concurrent requests than `pool_size` reached one gateway and some waited longer than 5 s for a slot. Raise `pool_size`, add a gateway, or lower client concurrency; clients should back off and retry. |
| `pg_etcd.so` fails to load with `GLIBC_2.38 not found` | The prebuilt extension tarballs were compiled on Debian 13 (`glibc` 2.38+). On EL8/EL9, Debian 12 or Ubuntu 22.04, build the extension from source (`make -C extension`). |
| Startup log prints `"P1 incomplete"` | A stale string; verify the binary and ABI with `/version` and `SELECT etcd._abi()`. |
{.wide}

`v0.1.0-rc2` fixed two `rc1` issues: the gateway no longer withdraws readiness when client requests fill `pool_size`, and `etcdctl endpoint health` now reports healthy. If `/readyz` still returns `503`, the gateway log line `tenant readiness withdrawn: <reason>` names the cause.

## Build and test driver issues {#tests}

- On Linux, 16 P3 tests that require root privileges or cgroup mounts are gated behind the `pgetcd_p3` build tag; standard `go test ./...` skips or isolates them.
- Historical SQL and P2 Python test runners (`tests/sql/run-p1-native.py` and the P2 storage runner) hard-code the older P1 2 MiB output limit, macOS `.dylib` suffixes, or Homebrew paths; see [Status — Known issues](/docs/etcd/status/#known-issues).

---

Backlinks:

- [Operations](/docs/etcd/operations/)
- [Quick start](/docs/etcd/quickstart/)
- [Use etcdctl](/docs/etcd/tutorial/etcdctl/)
- [Use the Go client](/docs/etcd/tutorial/go-client/)
