This is the multi-page printable view of this section.
Operations
Operational guides for running, diagnosing, and building pgetcd and pg_etcd:
- Monitoring — Diagnostics HTTPS endpoints (
/livez,/readyz,/health,/version,/metrics), Prometheus gauges, graceful shutdown, and single-primary switchover rules. - Troubleshooting — Startup, mTLS, readiness, capacity, and unknown-
COMMITrecovery procedures, plus workarounds forv0.1.0-rc2known issues. - Build from source — Repository layout, pinned toolchain and dependencies, build commands, and verification suites.
1 - Monitoring
This page covers health probes, Prometheus metrics, Watch client supervision, graceful shutdown, and primary switchover boundaries for the single-primary tenant gateway. When pgetcd backs Kubernetes, PostgreSQL and the gateway must be able to start without depending on that Kubernetes API server.
Diagnostics endpoints
The diagnostics listener (diagnostics_listen, port 2381 in examples) requires the same mutual TLS client certificate (spiffe://pgetcd/tenant/<tenant>) as the gRPC listener. All endpoints accept GET only and disable HTTP response caching.
| Endpoint | Response |
|---|---|
/livez | ok (HTTP 200) if the gateway process is alive and serving |
/readyz, /health | {"health":true} (HTTP 200) when ready, or {"health":false} (HTTP 503) when not ready |
/version | Product version (0.1.0), advertised etcd version (3.6.0), SQL ABI (1), and resource profiles |
/metrics | Prometheus text exposition format with fixed metric names and no client-controlled labels |
Query readiness with curl:
/livez checks only that the gateway HTTP handler responds. /readyz and /health also verify request admission, primary database connectivity, persistent identity, and Lease background worker readiness inside a fresh certified transaction that must complete its synchronous COMMIT within 1 second.
Since v0.1.0-rc2 (commit 81691bc), etcdctl endpoint health reports healthy, and the readiness check uses a reserved slot, so client load that fills pool_size does not withdraw readiness. The gateway logs tenant readiness withdrawn: <reason> and tenant readiness granted on each change; alert on the withdrawn line. In v0.1.0-rc1, endpoint health failed and the readiness check shared the client slots.
Prometheus metrics
All exported metrics on /metrics are gauges with no tenant keys, values, or credentials:
| Metric | Meaning |
|---|---|
pgetcd_ready | Runtime readiness flag (1 when ready, 0 when withdrawn) |
pgetcd_publication_inflight | Active requests currently holding a publication slot |
pgetcd_publication_capacity | Configured publication slot capacity (pool_size) |
pgetcd_pool_connections, pgetcd_pool_idle_connections | Total and idle connections in the PostgreSQL pool |
pgetcd_watch_streams | Currently admitted gRPC Watch streams |
pgetcd_watch_senders, pgetcd_watch_receivers | Active Watch sender and receiver goroutines |
pgetcd_watch_tail_inflight | In-flight _tail_v2 polling transactions |
pgetcd_watch_serialized_reserved_bytes | Reserved serialized Watch buffer bytes against watch_max_tenant_bytes |
What to watch and alert on:
pgetcd_ready == 0: Alert immediately. Inspectdiag.statusin PostgreSQL (not_ready_reasons) or check whetherpgetcd_publication_inflightreachedpgetcd_publication_capacity.pgetcd_publication_inflightapproachingpgetcd_publication_capacity: Indicates slow SQL, lock contention onetcd.meta, orCOMMITwaiting on synchronous standby replication. A slot remains occupied until itsCOMMITfinishes.pgetcd_watch_serialized_reserved_bytesapproachingwatch_max_tenant_bytes: Indicates slow Watch consumers or high write volume; streams that exceed their buffer or tenant quota receiveResourceExhausted.
Watch client supervision
- Watch consumers should persist a resume revision only after processing all events in a complete revision.
- A Watch
Createresponse confirms stream registration, not event progress. - If a Watch stream breaks with
Unavailable, reconnect starting atlast_processed_revision + 1. - If the requested revision has been logically compacted (
CompactRevision > 0), read a freshRangesnapshot and open a new Watch atheader.revision + 1(see Use etcdctl).
Graceful shutdown
On SIGINT or SIGTERM, the gateway withdraws readiness, stops admitting new requests, closes Watch streams, and waits up to a shared 10-second deadline for in-flight publication transactions and gRPC transports to drain. When the 10-second deadline expires, it stops the gRPC and HTTP servers forcibly.
In-flight COMMIT calls hold their publication slots until they return. A completed gateway shutdown timeout does not prove that every PostgreSQL backend transaction rolled back; the gateway suppresses responses for any unresolved COMMIT and never replays it.
Primary switchover, backup, and restore
All KV rows, event history, revision manifests, history anchors, Leases, and publication barriers live in PostgreSQL tables under schema etcd.
- Manual primary switchover: To preserve all acknowledged writes across a primary failure, PostgreSQL must run with
synchronous_commit = onand a synchronous standby. After promoting the synchronous standby, pointPGETCD_DSNat the new primary and restartpgetcd. In thev0.1.0-rc2switchover smoke test (commit81691bc, 2026-11-08), restarting the gateways after promotion took1.03 sand kept all52/52acknowledged writes. This checks the procedure only; it does not provide fencing. - Database restore: Startup and periodic metadata checks verify
database_name,database_oid,cluster_id,member_id, andrestore_generation. Keep a restored database isolated until you verify these identities. Automated failover fencing and offline PITR protocol recovery (pgetcd-restore) are post-MVP roadmap items (see HA roadmap and Offline protocol recovery).
2 - Troubleshooting
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
| 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 |
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
Troubleshoot the two TLS hops separately:
- Client to gateway (
listenanddiagnostics_listen):- Confirm that the client certificate chains to
tls.client_caand carries the URI SANspiffe://pgetcd/tenant/<tenant>. - If
tls.server_nameis set, confirm that the client dials that exact DNS name and sends matching SNI. Iftls.server_nameis empty, confirm thatpublic_urlsand the server certificate IP SAN match the IP address dialed by the client.
- Confirm that the client certificate chains to
- 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/sslkeyforpg_hba.conf) with the etcd tenant client certificate.
- Confirm
Readiness failures
/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:
Check response.not_ready_reasons and the surrounding fields:
lease_rebuilding: Thepg_etcdbackground worker is still reconstructing full Lease TTLs after startup. Wait for rebuild to finish and re-run the transaction.worker_unavailable: Verify thatshared_preload_librariesincludespg_etcd, the database name is listed inpg_etcd.databases(at most 8 databases), andmax_worker_processeshas enough free slots.primary_required: The connected PostgreSQL instance is in recovery (pg_is_in_recovery()istrue). PointPGETCD_DSNat the primary and restart the gateway.identity_mismatch,schema_mismatch, orprofile_mismatch: The storedcluster_idormember_idinetcd.meta, or the installed extension version, does not match the gateway configuration. After a restore or database swap, verify the intended database before editingtenant.json; changing IDs merely to bypass the check can corrupt client revision history.
Capacity and Watch errors
ResourceExhaustedon KV or Lease calls: Compare the request against the resource limits (1.5 MiBgRPC receive,2,048-byte write key,8 MiBKV response tree,4,096events and8 MiBper complete revision,1,024Leases per database,4,096keys per Lease). Remember that attaching a key to a Lease also checks whether revoking the entire Lease would exceed the8 MiB/4,096-event revision budget.ResourceExhaustedorUnavailableon Watch streams: A slow consumer can exhaust its per-stream queue or the tenant’swatch_max_tenant_bytesbudget. Reconnect fromlast_processed_revision + 1, or take a newRangesnapshot if history was compacted. Note that a watcher registered with a futurestart_revisionblocks stream-level progress notifications on the same gRPC stream until that revision arrives or the watcher is canceled.
Unknown COMMIT outcomes
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 unknownCOMMITautomatically. - Before retrying a non-idempotent write, the client application must read current state (
Range) or use a conditionalTxn(Compareonversionormod_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
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(). |
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
- On Linux, 16 P3 tests that require root privileges or cgroup mounts are gated behind the
pgetcd_p3build tag; standardgo test ./...skips or isolates them. - Historical SQL and P2 Python test runners (
tests/sql/run-p1-native.pyand the P2 storage runner) hard-code the older P1 2 MiB output limit, macOS.dylibsuffixes, or Homebrew paths; see Status — Known issues.
3 - Build from source
This page describes the pgetcd repository layout, the current root-module dependencies, release build commands, and verification suites. The current tree is untagged; the v0.1.0-rc2 candidate remains documented in Releases. To start a local development tenant after building, see Quick start.
Repository layout
| Path | Responsibility |
|---|---|
cmd/pgetcd | Gateway binary entry point (--tenant-config, --version, and internal test modes) |
internal/gateway, internal/watch | etcd v3 gRPC service handlers, Watch session multiplexing, and bounded event delivery |
internal/pgstore, internal/pgprobe | Certified SQL publication pool, transaction boundaries, and PostgreSQL state probes |
internal/tenant, internal/tenantservice, internal/transport | Tenant JSON validation, readiness lifecycle, and mTLS listeners |
extension/pg_etcd.c, extension/pg_kvcore | C/PGXS PostgreSQL extension, revision/Txn engine, _tail_v2, and Lease background workers |
versions.lock.json, go.mod, go.sum | Pinned upstream reference versions and Go module checksums |
tests/, scripts/ | SQL suites, official client probes, Watch race tests, and historical gate checkers |
Toolchain and pinned versions
The current root tree after the 2026-11-11 dependency refresh requires the following versions:
| Component | Pinned version | Notes |
|---|---|---|
| Go | 1.27.4 | Static gateway compilation (CGO_ENABLED=0) |
| PostgreSQL | 18.6 (REL_18_6) | Server headers (postgresql-server-dev-18) and pg_config for PGXS |
etcd Go API and clientv3 | v3.7.3 | Uses standard google.golang.org/protobuf bindings |
| gRPC / protobuf | v1.85.0 / v1.36.12 | Upstream generated protobuf bindings are consumed directly; protoc is not required for builds |
pgx | v5.12.0 | PostgreSQL wire driver and connection pool |
| Supporting modules | grpc-gateway v2.33.0; x/net v0.62.0; x/sync v0.25.0; x/sys v0.50.0; x/text v0.44.0 | The complete selected module graph is recorded in go.mod and go.sum |
| Reference servers (test only) | etcd v3.6.15, v3.7.2; Kubernetes v1.36.4, v1.37.1 | Locked in versions.lock.json for differential and storage probes |
The reference-server modules under tests/ keep these versions because they are compatibility inputs. They are separate from the root gateway module.
Build commands
Gateway (pgetcd)
Build a development binary for the local host:
Build a reproducible static Linux binary (used for the v0.1.0-rc1 and v0.1.0-rc2 archives on amd64 and arm64):
PostgreSQL extension (pg_etcd)
Compile and install the C/PGXS extension against your target PostgreSQL 18 installation:
This installs lib/pg_etcd.so, share/extension/pg_etcd.control, and share/extension/pg_etcd--0.1.0.sql. To build inside a clean Debian 13 container (postgres:18.6), install build-essential and postgresql-server-dev-18 first and run make -C extension. Note that binaries compiled on Debian 13 require glibc 2.38 or newer; compile directly on the target distribution when targeting EL8/EL9, Debian 12, or Ubuntu 22.04.
Verification commands
On 2026-11-11, the current untagged tree passed go build ./cmd/..., go test ./..., and go vet ./... on macOS arm64 with Go 1.27.4. The pgx refresh also required the legacy batch-error adapter to implement pgx.BatchResults.Tx(). This local check does not replace the Linux release checklist for a future candidate.
| Command | Scope |
|---|---|
go build ./cmd/... | Compile gateway and helper commands; passed on the current macOS arm64 tree on 2026-11-11 |
go vet ./... | Static analysis across all non-isolated packages; passed on the current macOS arm64 tree on 2026-11-11 |
go test ./... | Unit and package tests; passed on the current macOS arm64 tree on 2026-11-11 |
make -C extension PG_CONFIG=... | Compile pg_etcd.so with zero warnings |
python3 tests/sql/run-p1-native.py | Spin up an isolated temporary PostgreSQL cluster and run the SQL ABI test suites |
python3 tests/sql/run-p1-multidb.py | Verify 8-database Lease worker supervision and tenant isolation on a temporary cluster |
The repository also contains make p0-gate, make p1-gate, and make p2-gate targets that audit archived evidence from the 2026-10-08 frozen candidate, as well as P3 native/cgroup tests isolated behind -tags pgetcd_p3. For v0.1.0-rcN, follow the lean release regression checklist described in Status.