Persistence: SQLite and PostgreSQL HA
Faber runs against two persistence backends behind one internal/store.Store interface, selected with --store-driver=sqlite (default) or --store-driver=postgres.
Comparison
Section titled “Comparison”| Capability | SQLite (--store-driver=sqlite) |
PostgreSQL HA (--store-driver=postgres) |
|---|---|---|
| Driver | Pure-Go modernc.org/sqlite (CGO_ENABLED=0) |
pgx/v5 (pgxpool) |
| Replicas | 1 (strategy: Recreate, ReadWriteOnce PVC) |
2+ (strategy: RollingUpdate, active/standby) |
| Leader Election | Off by default (--leader-elect=false) |
Auto-enabled (--leader-elect=true) via Kubernetes Lease |
| Live SSE Fan-Out | In-process event hub | Cross-replica PostgreSQL LISTEN/NOTIFY (faber_run_events) |
| Concurrency | WAL mode, SetMaxOpenConns(1) for non-blocking kopiur reads |
Pool concurrency with FOR UPDATE SKIP LOCKED and advisory-locked migrations |
| Maintenance | Periodic PRAGMA wal_checkpoint(TRUNCATE) + terminal run pruning |
Periodic terminal run pruning (--retention-days, default 90) |
SQLite Mode (Single-Replica Default)
Section titled “SQLite Mode (Single-Replica Default)”SQLite is designed for low-footprint clusters and homelabs where an external database is unnecessary:
- Opens
/data/faber.dbin WAL mode withSetMaxOpenConns(1)so external online backup tools (such askopiur) can read consistently without write lock contention. - Stores fixed-width 9-digit UTC timestamps and supports Go-parsed comparisons for legacy
RFC3339Nanorows. - Runs periodic retention pruning (
--retention-days, default90,--retention-interval, default6h) deleting terminal runs only (viaCOALESCE(finished_at, started_at)) followed byPRAGMA wal_checkpoint(TRUNCATE).
PostgreSQL HA Architecture
Section titled “PostgreSQL HA Architecture”When --store-driver=postgres is selected, Faber switches cleanly to multi-replica high availability:
1. Advisory-Locked Schema Migrations
Section titled “1. Advisory-Locked Schema Migrations”At startup, store.Open acquires a fixed PostgreSQL session advisory lock (pg_advisory_lock) before running idempotent schema migrations and releases it on exit. Multiple replicas starting simultaneously serialize migrations without race errors.
2. Leader Election and Active HTTP/SSE Serving on All Replicas
Section titled “2. Leader Election and Active HTTP/SSE Serving on All Replicas”- When
--store-driver=postgresis set without an explicit--leader-electflag, the controller automatically enables Kubernetes Lease leader election (--leader-election-id=faber-controller.faberops.dev). - Only the elected leader runs CR reconcilers, Cron triggers, Kubernetes watches, approval expiry sweeps, PR feedback sync, and retention pruning.
ui.Serverimplementsmanager.LeaderElectionRunnablewithNeedLeaderElection() == false, so every replica serves the Web GUI, REST API,/v1/invoke,/mcp,/webhooks/*, and/api/v1/eventsSSE streams even while on standby.
3. FOR UPDATE SKIP LOCKED Claim Safety
Section titled “3. FOR UPDATE SKIP LOCKED Claim Safety”Background state transitions such as expiring overdue WaitingApproval checkpoints use FOR UPDATE SKIP LOCKED inside PostgreSQL transactions so concurrent sweeps never double-process a checkpoint.
4. Cross-Replica LISTEN/NOTIFY SSE Fan-Out
Section titled “4. Cross-Replica LISTEN/NOTIFY SSE Fan-Out”- Every replica establishes a synchronous
LISTEN faber_run_eventsconnection before reporting readiness and automatically reconnects if the database restarts. - When the leader publishes a run event, it inserts the row and sends a
NOTIFY faber_run_eventspayload so standby replicas fan out the event immediately to connected Web GUI andfaberctl runs watchclients. - Payloads exceeding 7.5 KiB (PostgreSQL’s 8 KiB
NOTIFYlimit) automatically fall back to an ID-only notification that listeners hydrate from therun_eventstable. - Startup logs redact credentials fail-closed via
store.RedactDSNso database passwords never appear in container logs.
Deploying PostgreSQL HA with Helm
Section titled “Deploying PostgreSQL HA with Helm”Plaintext PostgreSQL DSNs are intentionally disallowed in values.yaml (enforced by charts/faber/values.schema.json). Create a Kubernetes Secret holding the DSN and reference it with store.postgres.existingSecret:
kubectl -n faber create secret generic faber-postgres \ --from-literal=dsn='postgres://faber:CHANGE_ME@postgres-rw.db.svc.cluster.local:5432/faber?sslmode=require'
helm upgrade --install faber oci://ghcr.io/faberops/charts/faber \ --version 2.0.0 \ --namespace faber \ --set replicaCount=2 \ --set store.driver=postgres \ --set store.postgres.existingSecret=faber-postgres \ --set store.postgres.secretKey=dsnIf networkPolicy.enabled is true, add a networkPolicy.extraEgress rule permitting TCP 5432 to your PostgreSQL namespace and pods.