Part of #554 (multi-backend storage). ADR-009 already named khive-db-postgres as planned.
Why Postgres is the easy backend (and validates #555)
Postgres is SQL — it reuses the AST→SQL compiler path with a dialect fork, not a new query language. This is the concrete second consumer of #555's QueryCompiler strategy ("SQL dialects" plural in ADR-008). Dialect deltas vs SQLite:
- Param placeholders:
$1, $2 vs SQLite ?.
- Recursive CTE: both
WITH RECURSIVE, but type coercion + LIMIT semantics differ.
- Upsert:
INSERT ... ON CONFLICT (mostly compatible, watch partial-index targets).
- Types: strict typing +
jsonb (vs SQLite dynamic + json1) for entity properties.
Trait impls (khive-db-postgres crate, the 8 ADR-005 traits)
Concurrency
Postgres MVCC removes SQLite's single-writer (WAL) bottleneck — required for a hosted multi-writer khive.
Acceptance
Part of #554 (multi-backend storage). ADR-009 already named
khive-db-postgresas planned.Why Postgres is the easy backend (and validates #555)
Postgres is SQL — it reuses the AST→SQL compiler path with a dialect fork, not a new query language. This is the concrete second consumer of #555's
QueryCompilerstrategy ("SQL dialects" plural in ADR-008). Dialect deltas vs SQLite:$1, $2vs SQLite?.WITH RECURSIVE, but type coercion + LIMIT semantics differ.INSERT ... ON CONFLICT(mostly compatible, watch partial-index targets).jsonb(vs SQLite dynamic + json1) for entityproperties.Trait impls (
khive-db-postgrescrate, the 8 ADR-005 traits)SqlAccess/SqlReader/SqlWriter/SqlTransactionover a pooledtokio-postgres/sqlxconnection.VectorStore→ pgvector (HNSW/IVFFlat). Maps onto theVectorStoreCapabilitiesmodel (ADR-044): setsupports_filter=true(pgvector + WHERE pushdown), declareVectorIndexKind::PgVector. This is option 2 of design(retrieval): vector storage & hybrid query under multi-backend graph DBs #557 for the SQL world — vectors co-located, native pre-filter.TextSearch→tsvector/tsqueryorpg_trgm(FTS5 has no Postgres equivalent — needs its own impl + the FTS-escaping fix from bug(db): single-quote in search query crashes FTS5 ("syntax error near '") #549 re-validated for tsquery).migrations.rsis SQLite DDL today). Postgres gets its own migration set incl. RLS policies (see linked RLS issue).Concurrency
Postgres MVCC removes SQLite's single-writer (WAL) bottleneck — required for a hosted multi-writer khive.
Acceptance
khive-db-postgrescrate implements all 8 traits; binary wires it via config.PostgresCompiler(feat(query): dialect-keyed query compiler — decouple AST→codegen from SQLite (Cypher/SurrealQL) #555) passes the GQL/SPARQL pattern parity suite.VectorStorepasses the vector search suite; hybrid RRF parity vs SQLite.