Production Operations

Health probes, Prometheus metrics, system diagnostics, graceful drain, dumps/exports, and hardening checklist.

3 min read Clustering & Operations

Deploy, monitor, tune, export, and upgrade SpydDB clusters predictably in production environments.

1. Probes, Prometheus Metrics & Readiness (metrics_bind)#

Configure metrics_bind on loopback (or a private operational interface) to expose /healthz, /readyz, and Prometheus /metrics:

sh
curl -fsS http://127.0.0.1:9090/healthz   # 200 while process is alive
curl -fsS http://127.0.0.1:9090/readyz    # 503 immediately when server begins draining
curl -fsS http://127.0.0.1:9090/metrics   # Prometheus text exposition

On the public HTTP listener (http_bind), GET /v1/health reports liveness, draining status, storage state, and server version without requiring credentials (200 healthy, 503 draining/storage error):

json
{"status":"ok","draining":false,"storage":"ok","version":"1.0.0"}

Key Prometheus Counters & Histograms#

MetricTypeSignal
spyd_connections_total / spyd_active_connectionscounter / gaugeAccepted & active client connections
spyd_authentication_failures_totalcounterRejected credentials / potential credential stuffing
spyd_frames_rejected_totalcounterMalformed, oversized, or bad CRC32C SpydWire frames
spyd_queries_total / spyd_queries_failed_total / spyd_queries_cancelled_totalcounterExecution volume, query errors, and cancellations
spyd_http_requests_total / spyd_http_requests_failed_totalcounterHTTP API throughput & 4xx/5xx rate
spyd_query_latency_secondshistogramEngine query duration buckets (1ms .. 5s)

2. Live Engine Diagnostics & Online Maintenance#

Query internal operational health directly via SpydQL:

spydql
system | stats buffer_pool
system | stats wal
system | stats storage
system | stats catalog
system | stats security
system | stats indexes
system | stats partitions
system | stats access
system | stats all
system | stats collection orders
system | queries active

Online MVCC Maintenance (maintain & maintain purge)#

SpydDB reclaims obsolete row versions, expired tombstones, obsolete columnar segments, and unreferenced chunked blobs online without stopping reads or concurrent writers:

spydql
-- Retention-respecting reclamation (preserves history inside version_retention_secs)
maintain

-- Aggressive purge up to the oldest active reader snapshot or prepared 2PC transaction
maintain purge
  • Non-blocking execution: Collection runs cooperatively with read-locked access, clamps the garbage-collection horizon to both version_retention_secs (for maintain) and the oldest active transaction snapshot / prepared 2PC horizon, and uses a write sweep barrier so concurrent large-blob commits never race with reclamation.
  • Internal free-list reuse: Freed storage pages are flushed back to SpydDB's internal free list for immediate reuse; running maintenance does not shrink database files on disk.
  • Cooperative cancellation & least privilege: Long maintenance runs honor POST /v1/cancel/{query_id} and require only manage on database(maintenance) rather than full security administration.

Profile slow queries with actual row counts & timing per operator:

spydql
explain analyze orders | where status == "paid" | sort placed_at desc | take 100

3. Graceful Shutdown & Zero-Drop Upgrades#

Sending SIGINT or SIGTERM initiates a deterministic drain sequence:

  1. /readyz and /v1/health immediately return 503 so load balancers stop routing new traffic.
  2. Open keep-alive idle connections close; in-flight queries finish cleanly within the graceful drain timeout.
  3. Uncommitted interactive transactions roll back cleanly, and remaining WAL buffers flush to disk.

Upgrading Safely#

  1. Verify config compatibility before restarting:
    sh
    spyd-server --config /etc/spyd/server.json --check
  2. Take an online verified backup via POST /v1/admin/backups + POST /v1/admin/backups/verify.
  3. Drain and restart the node cleanly (SIGTERM) or swap rolling cluster standbys.

4. Database Administration, Logical Dumps & Streaming Exports#

Multi-Database Management (HTTP Admin API & pgwire)#

sh
# List served databases
curl -sS --cacert tls/ca.crt https://localhost:8080/v1/admin/databases \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN"

# Create a new database (inherits caller database role layout)
curl -sS -X POST --cacert tls/ca.crt https://localhost:8080/v1/admin/databases \
  -H "Authorization: Bearer $SPYD_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "analytics"}'

Whole-Database Dumps (spyd-cli)#

sh
# Full-fidelity SpydDB native JSON dump & restore
spyd-cli --embedded --data /var/lib/spyd --dump /var/backups/db.spyd.json
spyd-cli --embedded --data /var/lib/spyd-restored --restore /var/backups/db.spyd.json

# Portable PostgreSQL SQL dump & restore
spyd-cli --embedded --data /var/lib/spyd --dump-sql /var/backups/db.sql
spyd-cli --embedded --data /var/lib/spyd-restored --restore-sql /var/backups/db.sql

Streaming Query Exports (CSV / NDJSON / GZIP)#

Stream arbitrarily large query results directly to disk without hitting frame size limits:

sh
spyd-cli --embedded --data /var/lib/spyd \
  --query 'orders | pick id, customer, total, placed_at' \
  --export /var/backups/orders.ndjson.gz \
  --export-columns /var/backups/orders.columns.json

5. Production Hardening Checklist#

  • Keep "environment": "production" set so non-TLS listeners refuse startup.
  • Enable --cap-drop ALL --cap-add IPC_LOCK and unlimited memlock ("lock_memory": true) in Docker/systemd.
  • Store tokens (env:...), TLS keys, storage.encryption_key_path, and column keyrings outside data_dir with mode 0600.
  • Restrict public network access via "network": { "allowed_cidrs": [...] }.
  • Configure backup_root and ship sealed audit segments & backups off-host to immutable object storage.