Multiple Databases
One riffdbd process can host up to 512 independently durable databases. Each
configured alias has its own redb file, catalog, credentials, commit sequence,
projections, outbox, health state, and recovery boundary.
Selection occurs before authentication
Every public connection selects a canonical database alias before its credential is authenticated. A credential is bound to one database audience and cannot authorize another alias. The server does not fall back to a default database when an explicit selection is unknown or malformed.
Public paths select the alias as follows:
| Path | Selection |
|---|---|
| CLI and generated clients | Client configuration database value |
| MCP stdio | database in the MCP configuration file |
| Hosted MCP | riffdb-database request header |
| gRPC | Checked database-routing metadata from the client facade |
Add or remove a database
When riffdbd is started with a configuration file that declares [databases.<alias>]
tables, the daemon monitors that configuration file for modifications and reconciles the
configured database inventory online without restarting the process or interrupting
active peer aliases:
- Online provisioning: Adding a new
[databases.<alias>]entry opens or initializes itspath, starts its per-database workers (and idle-hibernation supervisor whenlimits.idle_hibernate_secondsis configured), and registers the alias on the gRPC and hosted MCP routing tables. - Online deprovisioning: Removing an existing
[databases.<alias>]entry removes the alias from gRPC and hosted MCP routing, drains its per-database workers, writesCleanCloseState::Clean, and releases itsredbfile lock while leaving its durable file on disk. - Fail-closed validation: If a modified configuration file is malformed, exceeds
512 databases (
512 KiBconfiguration document bound), mutates an existing[databases.<alias>]entry (retained_database_changed— such as changing itspath,projections_root, or[databases.<alias>.outbox]after the alias is opened), or mutates process-wide listener, TLS, authentication, or resource settings, the reload is rejected with a warning diagnostic (config reload rejected) and the previously active database inventory remains unchanged. To apply configuration changes to an already-open database alias, restartriffdbd(for example,docker compose restart riffdbd).
For installer-managed single-user deployments, you can also use the database management workflow described in Installation.
Do not copy a credential from one alias into another configuration. Create or bind the application role against the target database so the credential, audience, active contract, and named operations agree.
Multi-Database riffdbd.toml and Docker Compose Bootstrap
When using [databases.<alias>] tables, [server] defines only process-wide
settings (audience, capability_keys, idempotency_keys, and listeners).
Do not set database or environment under [server] when [databases.<alias>]
tables are present — each [databases.<alias>] entry owns its own path,
backup_root, projections_root, environment, and [databases.<alias>.outbox]
(always set projections_root to a writable directory inside container volumes, and
configure [databases.<alias>.outbox] when deployed contracts emit durable outbox
events):
[server]
audience = "my-cluster-audience"
capability_keys = "/run/secrets/capability.keys"
idempotency_keys = "/run/secrets/idempotency.keys"
[server.application_listener]
mode = "direct_tls"
listen = "0.0.0.0:7443"
public_endpoint = "https://riffdbd:7443"
certificate_chain = "/run/secrets/server.pem"
private_key = "/run/secrets/server.key"
[databases.openfga]
path = "/var/lib/riffdb/data/openfga.redb"
backup_root = "/var/lib/riffdb/backups/openfga"
projections_root = "/var/lib/riffdb/data/projections/openfga"
environment = "playground"
[databases.openfga.outbox]
kind = "durable_local"
directory = "/var/lib/riffdb/data/outbox/openfga"
quota_encoded_bytes = 268435456
[databases.better-auth]
path = "/var/lib/riffdb/data/better-auth.redb"
backup_root = "/var/lib/riffdb/backups/better-auth"
projections_root = "/var/lib/riffdb/data/projections/better-auth"
environment = "playground"
[databases.better-auth.outbox]
kind = "durable_local"
directory = "/var/lib/riffdb/data/outbox/better-auth"
quota_encoded_bytes = 268435456
When running in Docker Compose with a published host port (for example
127.0.0.1:17443:7443) and a certificate issued with
SAN = DNS:riffdbd, DNS:localhost, IP:127.0.0.1:
-
Container
healthcheck(unauthenticated process liveness): Omit--databaseand omit--tls-server-name(or set it to127.0.0.1to match--endpoint https://127.0.0.1:7443):healthcheck: test: ["CMD", "riffdb", "--endpoint", "https://127.0.0.1:7443", "--tls-trust-root", "/run/secrets/ca.pem", "server", "health"] interval: 2s timeout: 3s retries: 30 -
Per-database
capability bootstrap --operator(executed inside the container): Bootstrap is a one-shot local-authority operation per database and must connect to loopback inside the container (https://127.0.0.1:7443). Do not settls_server_name = "riffdbd"whenendpointishttps://127.0.0.1:7443(mismatched endpoint/TLS identities fail closed withconfiguration_invalid); omittls_server_nameso127.0.0.1is verified against the certificate’sIP:127.0.0.1SAN.capability bootstrap --operatorautomatically includes the server’s configured[server] audiencealongsideriffdb-cliandriffdb-mcp(or you can pass repeatable--audience <AUDIENCE>explicitly). You can bootstrap all configured databases in one loop:for db in openfga better-auth; do cred="/var/lib/riffdb/bootstrap/operator-${db}.credential" docker compose exec -T riffdbd /bin/sh -eu -c ' db="$1" cred="$2" if [ -e "$cred" ]; then if [ -s "$cred" ] && riffdb \ --output json \ --endpoint https://127.0.0.1:7443 \ --tls-trust-root /run/secrets/ca.pem \ --database "$db" \ --credential-file "$cred" \ server health >/dev/null 2>&1; then exit 0 fi printf "existing credential %s failed authentication for database %s; inspect server state or pass --force only if %s has not yet completed bootstrap\n" "$cred" "$db" "$db" >&2 exit 1 fi out="$(riffdb \ --output json \ --endpoint https://127.0.0.1:7443 \ --tls-trust-root /run/secrets/ca.pem \ --database "$db" \ capability bootstrap \ --operator \ --audience playground-grpc \ --lifetime-seconds 2592000 \ --bearer-output "$cred")" case "$out" in *\"status\":\"created\"*) ;; *) rm -f "$cred" echo "$out" >&2 exit 1 ;; esac ' sh "$db" "$cred" doneOr as a one-shot init service in
compose.yamlthat sharesriffdbd’s network namespace (network_mode: "service:riffdbd") so127.0.0.1:7443is local loopback. Preserve any existing credential file and never pass--forceunconditionally on rerun (an already-bootstrapped database returnsbootstrap_conflictwith exit code0, so--forcewould overwrite a working local bearer before the server reports the conflict):services: riffdb-bootstrap: image: riffdb:latest network_mode: "service:riffdbd" depends_on: riffdbd: condition: service_healthy volumes: - ./secrets:/run/secrets:ro - riffdb-bootstrap:/var/lib/riffdb/bootstrap entrypoint: ["/bin/sh", "-eu", "-c"] command: - | for db in openfga better-auth; do cred="/var/lib/riffdb/bootstrap/operator-$${db}.credential" if [ -e "$$cred" ]; then if [ -s "$$cred" ] && riffdb --output json \ --endpoint https://127.0.0.1:7443 \ --tls-trust-root /run/secrets/ca.pem \ --database "$$db" \ --credential-file "$$cred" \ server health >/dev/null 2>&1; then continue fi printf "existing credential %s failed authentication for database %s; inspect server state or pass --force only if %s has not yet completed bootstrap\n" "$$cred" "$$db" "$$db" >&2 exit 1 fi out="$$(riffdb --output json \ --endpoint https://127.0.0.1:7443 \ --tls-trust-root /run/secrets/ca.pem \ --database "$$db" \ capability bootstrap --operator \ --audience playground-grpc \ --lifetime-seconds 2592000 \ --bearer-output "$$cred")" case "$$out" in *\"status\":\"created\"*) ;; *) rm -f "$$cred" echo "$$out" >&2 exit 1 ;; esac done -
Deploying applications, custom environments, credential lifetimes, and rotation: Both
capability bootstrap --operatorandapplication deploy --provision-roledefault--lifetime-secondsto2592000(30 days, the maximum capability lifetime). Pass--forcetocapability bootstraponly on an unbootstrapped database when intentionally replacing a leftover local output file from a prior interrupted attempt (cleanup of newly created or--force-replaced local files on connection or RPC failure is automatic, whereas abootstrap_conflictresponse on an already-bootstrapped database returns exit status0). When an application manifest locks roles for multiple environments (such asdevelopment,staging, andproductioninriffdb.application.jsonandriffdb.application.lock.json), pass--environment <ENV>toriffdb application deployto select the locked role whose declaredenvironmentmatches<ENV>(or to verify that--provision-role <ROLE>is locked for<ENV>). Adding a new environment requires declaring a role for that environment inriffdb.application.jsonand runningriffdb application lock --write:riffdb --database openfga application deploy \ --environment staging \ --replace-role-credential \ --lifetime-seconds 2592000 \ --credential-output /absolute/path/to/creds/role-openfga.credentialDuring
--replace-role-credential, the CLI proves the successor credential against the server and atomically replaces the watcheddriverd.tomlcredential path (--credential-outputwhen supplied, or<deployment-root>/driver-role.credentialby default) before revoking the predecessor capability, allowing a runningriffdb-driverdhost to reload the rotated credential without a restart. -
Running all four framework adapters through one
riffdb-driverdhost: Every language runtime (Go, TypeScript, and Python) can connect through one sharedriffdb-driverdUnix socket (RIFFDB_DRIVER_SOCKET).riffdb application deploy --provision-role <ROLE>(or--environment <ENV>) emitsoperation-catalog.json,driverd.toml, anddriver.envunder.riffdb/deployments/<database>/<role>/for Go, TypeScript, and Python applications alike:- Provision each adapter database (
openfga,better-auth,mlflow,langgraph) and merge their targets into a shareddriverd.tomlwith--driver-config-output(note that the application manifest path is a positional argument, and--deployment-dirtakes the base directory whose parent already exists—the CLI creates<deployment-dir>/<database>automatically):riffdb --database openfga application deploy /path/to/riffdb-openfga/riffdb.application.json --environment staging --deployment-dir /run/user/1000/riffdb/deployments --driver-config-output /run/user/1000/riffdb/driverd.toml --driver-socket /run/user/1000/riffdb/driver.sock riffdb --database better-auth application deploy /path/to/riffdb-better-auth/profiles/organization-security/riffdb.application.json --environment staging --deployment-dir /run/user/1000/riffdb/deployments --driver-config-output /run/user/1000/riffdb/driverd.toml --driver-socket /run/user/1000/riffdb/driver.sock riffdb --database mlflow application deploy /path/to/riffdb-mlflow/riffdb.application.json --environment staging --deployment-dir /run/user/1000/riffdb/deployments --driver-config-output /run/user/1000/riffdb/driverd.toml --driver-socket /run/user/1000/riffdb/driver.sock riffdb --database langgraph application deploy /path/to/riffdb-langgraph/riffdb.application.json --environment staging --deployment-dir /run/user/1000/riffdb/deployments --driver-config-output /run/user/1000/riffdb/driverd.toml --driver-socket /run/user/1000/riffdb/driver.sock - Or combine their
[[applications]]blocks into one0600driverd.tomllistening on one Unix socket (for example/run/user/1000/riffdb/driver.sockin a0700directory) and startriffdb-driverd /run/user/1000/riffdb/driverd.toml. Each adapter’s handshake automatically selects its matching[[applications]]entry by contract lineage and version:
(Python adapters continue to accept direct TLS viaexport RIFFDB_DRIVER_SOCKET=/run/user/1000/riffdb/driver.sockRIFFDB_ENDPOINT/RIFFDB_CREDENTIAL_FILE/RIFFDB_TLS_TRUST_ROOTas well, or Unix socket mode viaRIFFDB_DRIVER_SOCKET.) - Container UID (
SO_PEERCRED) and remote identity hash when sharing a socket across containers:riffdb-driverdenforces LinuxSO_PEERCREDon every accepted Unix socket connection: the client process must run as the same effective UID as the owner of the socket directory. If a container image defaults tononroot(65532) whileriffdb-driverdruns as your mapped host UID (1000withuserns_mode: "keep-id"), setuser: "1000:100"anduserns_mode: "keep-id"on the client container as well.RIFFDB_REMOTE_HASHin the generateddriver.envissha256("<endpoint>|<tls_server_name>")for the endpoint used duringriffdb application deploy. Ifriffdb application deployran on the host againsthttps://127.0.0.1:17443(tls_server_name = "127.0.0.1") whiledriverd.tomlinside a container network connects tohttps://riffdbd:7443(tls_server_name = "riffdbd"), either omitRIFFDB_REMOTE_HASH(OPENFGA_RIFFDB_REMOTE_IDENTITY_HASH) soriffdb-driverdresolves and returns its verified remote identity hash on handshake, or computeprintf 'https://riffdbd:7443|riffdbd' | sha256sum.
- Provision each adapter database (
-
Resetting a database after a failed bootstrap attempt: Bootstrap is strictly one-shot per database. Each
<db>.redbfile has durable companion files in the same directory (<db>.redb.journal*,<db>.redb.format,<db>.redb.derived,<db>.redb.riffoutbox) plus itsprojections_rootdirectory. Deleting only<db>.redb(or deleting files whileriffdbdis still running and holding open file descriptors) leaves companion files from the previousDatabaseIdbehind and causes startup recovery orcredential_invalidfailures. To reset one database cleanly whileriffdbdis stopped, remove all of its companion paths together:rm -rf /var/lib/riffdb/data/openfga.redb* \ /var/lib/riffdb/data/outbox/openfga \ /var/lib/riffdb/data/projections/openfgaWhen redeploying an application against a recreated database from the same working tree, either pass
--replace-role-credentialor remove the stale local deployment state under<app>/.riffdb/deployments/(or--deployment-dir). -
Host-side client configuration, Rootless Podman permissions, and host-loopback services: Use an absolute path for
credential_fileandtls_trust_root, ensure credential and key files are mode0600(regular files, never symlinks), and omittls_server_name(or settls_server_name = "127.0.0.1"to matchendpoint = "https://127.0.0.1:17443"):[client] endpoint = "https://127.0.0.1:17443" database = "openfga" output = "json" max_attempts = 3 credential_file = "/absolute/path/to/creds/operator-openfga.credential" tls_trust_root = "/absolute/path/to/secrets/ca.pem"(In-network container peers that connect to
endpoint = "https://riffdbd:7443"verifyDNS:riffdbdautomatically.)Tip
Rootless Podman UID mapping (
keep-id) and host-loopback services:- The release
riffdbdcontainer runs as UID/GID65532:65532and requires0600secret files owned by its effective UID. Under Rootless Podman, adduserns_mode: "keep-id:uid=65532,gid=65532"so host-owned0600files bind-mounted intoriffdbdappear owned by65532:65532inside the container. - Rootless bridge networks (
host.containers.internal) cannot reach host services that bind strictly to127.0.0.1(such as default local Ollama or loopback-published ports). For containers that must reach host-loopback endpoints, either run the container withnetwork_mode: host(binding its own listener to127.0.0.1:<port>) or connect through a shared Unix socket volume (riffdb-driverd).
- The release
MCP per application
Create one MCP configuration per database and role. Multiple entries may point
to the same riffdb-mcp binary and riffdbd endpoint, but each bridge is bound
to exactly one selected alias and credential. This preserves least authority
without requiring a separate server instance.
Run before registering a bridge:
riffdb-mcp doctor --config ~/.config/riffdb/mcp-myapp.toml
The doctor verifies routing and credential/tool discovery without widening a narrow application role merely to grant health access.
Isolation and operations
Backup, restore, reset, and removal operate on one database while the service is offline. A fault in one database can make that database unavailable without changing another database’s authoritative state. Process-level resource limits remain shared, so capacity planning must account for the combined configured set.