Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Operations

Monitor, troubleshoot and build pgetcd.

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-COMMIT recovery procedures, plus workarounds for v0.1.0-rc2 known issues.
  • Build from source — Repository layout, pinned toolchain and dependencies, build commands, and verification suites.

1 - Monitoring

Diagnostics endpoints, metrics and what to alert on.

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.

EndpointResponse
/livezok (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
/versionProduct version (0.1.0), advertised etcd version (3.6.0), SQL ABI (1), and resource profiles
/metricsPrometheus text exposition format with fixed metric names and no client-controlled labels

Query readiness with curl:

curl --cacert /path/to/server-ca.crt \
  --cert /path/to/tenant-client.crt \
  --key /path/to/tenant-client.key \
  https://127.0.0.1:2381/readyz

/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.

Warning

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:

MetricMeaning
pgetcd_readyRuntime readiness flag (1 when ready, 0 when withdrawn)
pgetcd_publication_inflightActive requests currently holding a publication slot
pgetcd_publication_capacityConfigured publication slot capacity (pool_size)
pgetcd_pool_connections, pgetcd_pool_idle_connectionsTotal and idle connections in the PostgreSQL pool
pgetcd_watch_streamsCurrently admitted gRPC Watch streams
pgetcd_watch_senders, pgetcd_watch_receiversActive Watch sender and receiver goroutines
pgetcd_watch_tail_inflightIn-flight _tail_v2 polling transactions
pgetcd_watch_serialized_reserved_bytesReserved serialized Watch buffer bytes against watch_max_tenant_bytes

What to watch and alert on:

  • pgetcd_ready == 0: Alert immediately. Inspect diag.status in PostgreSQL (not_ready_reasons) or check whether pgetcd_publication_inflight reached pgetcd_publication_capacity.
  • pgetcd_publication_inflight approaching pgetcd_publication_capacity: Indicates slow SQL, lock contention on etcd.meta, or COMMIT waiting on synchronous standby replication. A slot remains occupied until its COMMIT finishes.
  • pgetcd_watch_serialized_reserved_bytes approaching watch_max_tenant_bytes: Indicates slow Watch consumers or high write volume; streams that exceed their buffer or tenant quota receive ResourceExhausted.

Watch client supervision

  • Watch consumers should persist a resume revision only after processing all events in a complete revision.
  • A Watch Create response confirms stream registration, not event progress.
  • If a Watch stream breaks with Unavailable, reconnect starting at last_processed_revision + 1.
  • If the requested revision has been logically compacted (CompactRevision > 0), read a fresh Range snapshot and open a new Watch at header.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 = on and a synchronous standby. After promoting the synchronous standby, point PGETCD_DSN at the new primary and restart pgetcd. In the v0.1.0-rc2 switchover smoke test (commit 81691bc, 2026-11-08), restarting the gateways after promotion took 1.03 s and kept all 52/52 acknowledged 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, and restore_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

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

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

SymptomCause and fix
select exactly one...Specify exactly one mode flag (--tenant-config, --p0-fixture, or --qualification-config) and remove positional arguments
PGETCD_DSN requiredExport PGETCD_DSN in the gateway process environment
invalid tenant configurationCheck JSON syntax, unknown or duplicate keys, field types, and the 65,536-byte file size limit
Listener rejectedUse explicit IP:port addresses and distinct non-zero ports for listen and diagnostics_listen
tenant storage configuration rejectedEnsure 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 failedVerify CREATE EXTENSION pg_etcd, stored cluster_id / member_id, primary status, and pg_etcd.databases
Startup certification deadline reachedThe 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:

  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

/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:

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

  • ResourceExhausted on KV or Lease calls: Compare the request against the resource 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

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

Symptom in v0.1.0-rc2Cause and workaround
Watch events arrive late during sustained heavy writesThe 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 exhaustedMore 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 foundThe 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_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.

3 - Build from source

Toolchain, pinned versions and build commands.

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

PathResponsibility
cmd/pgetcdGateway binary entry point (--tenant-config, --version, and internal test modes)
internal/gateway, internal/watchetcd v3 gRPC service handlers, Watch session multiplexing, and bounded event delivery
internal/pgstore, internal/pgprobeCertified SQL publication pool, transaction boundaries, and PostgreSQL state probes
internal/tenant, internal/tenantservice, internal/transportTenant JSON validation, readiness lifecycle, and mTLS listeners
extension/pg_etcd.c, extension/pg_kvcoreC/PGXS PostgreSQL extension, revision/Txn engine, _tail_v2, and Lease background workers
versions.lock.json, go.mod, go.sumPinned 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:

ComponentPinned versionNotes
Go1.27.4Static gateway compilation (CGO_ENABLED=0)
PostgreSQL18.6 (REL_18_6)Server headers (postgresql-server-dev-18) and pg_config for PGXS
etcd Go API and clientv3v3.7.3Uses standard google.golang.org/protobuf bindings
gRPC / protobufv1.85.0 / v1.36.12Upstream generated protobuf bindings are consumed directly; protoc is not required for builds
pgxv5.12.0PostgreSQL wire driver and connection pool
Supporting modulesgrpc-gateway v2.33.0; x/net v0.62.0; x/sync v0.25.0; x/sys v0.50.0; x/text v0.44.0The 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.1Locked 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:

go build -o .cache/docs-dev/pgetcd ./cmd/pgetcd

Build a reproducible static Linux binary (used for the v0.1.0-rc1 and v0.1.0-rc2 archives on amd64 and arm64):

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o pgetcd ./cmd/pgetcd
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o pgetcd ./cmd/pgetcd

PostgreSQL extension (pg_etcd)

Compile and install the C/PGXS extension against your target PostgreSQL 18 installation:

make -C extension PG_CONFIG=/path/to/postgresql/bin/pg_config
make -C extension PG_CONFIG=/path/to/postgresql/bin/pg_config install

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.

CommandScope
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.pySpin up an isolated temporary PostgreSQL cluster and run the SQL ABI test suites
python3 tests/sql/run-p1-multidb.pyVerify 8-database Lease worker supervision and tenant isolation on a temporary cluster
Note

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.