Skip to content

Orchestration

Server operations

Configure the SQLBuild control server: authentication, project roles, worker limits, pools, health, webhooks, retention, run output, backup, and upgrades.

The control server (sqb server --config server.toml) serves the Web UI, API, and scheduler without loading project Python. Code locations publish compiled snapshots to it and workers run builds on its behalf. See sqb server for CLI flags and sqb admin commands.

server.toml is read once at start-up; restart the server after editing it. CLI flags override the file, and an unknown section or key stops the server at start-up. Keep secrets in environment variables rather than in server.toml.

[server]
host = "0.0.0.0"
port = 8000
default_role = "viewer"
[retention]
run_log_days = 7
[trusted_proxy]
origin = "https://control.example.com"
trusted_peers = ["10.0.0.5"]
[[launchers.docker]]
location = "orders"
target = "development"
server_url = "http://server:8000"
max_workers = 2
socket = "/var/run/docker.sock"
location_container = "orders-location"
executable = "/usr/local/bin/sqb"
Section Keys
[server] host (127.0.0.1), port (8000), database_env (SQLBUILD_CONTROL_DATABASE_URL), password_origin, default_role (none), scheduler (true), attention_snooze ("24h")
[retention] statistics_days, audit_days, snapshot_count, run_log_days, run_log_count, state_history_versions, run_output_days, snapshot_files_days
[output] store, max_bytes_per_run
[oidc] origin, issuer, client_id, identities, optional client_secret_env, certificate_authority, groups_claim, group_roles
[trusted_proxy] origin, optional trusted_peers (127.0.0.1, ::1), allowed_hosts, username_header (X-SQB-User), display_name_header, email_header, unknown_users (provision_viewer), proxy_logout_url, identities
[[launchers.docker]] location, target, server_url, max_workers, socket, location_container, executable, optional run, pool_caps
[[launchers.local]] location, target, server_url, max_workers, absolute project_dir and executable, optional pool_caps

Create each launcher’s location with sqb admin create-location <name> before starting the server. Workers load their target’s env file at start-up; variables already in the launcher environment win.

sqb server serves plain HTTP. Terminate TLS at a reverse proxy in front of it and pass the https:// URL to code locations, workers, sqb login, and service-account clients. Connections to non-loopback http:// URLs print a warning because bearer tokens and API keys travel unencrypted.

Choose one human sign-in method (password_origin, [oidc], or [trusted_proxy]); they cannot be combined.

With [server] password_origin set, someone with user.manage adds users under People → Add person (minimum 12-character initial password; users can change it after signing in).

A reverse proxy (nginx, Apache, etc.) can authenticate users and forward identity headers. The server trusts those headers only from socket peers in trusted_peers (never X-Forwarded-For), so firewall the server port or bind it to 127.0.0.1.

[trusted_proxy]
origin = "https://control.example.com"
username_header = "X-SQB-User"
display_name_header = "X-SQB-Display-Name"
proxy_logout_url = "https://sign-in.example.com/logout"
  • Always have the proxy explicitly set username_header and set or unset optional display_name_header / email_header on every request so browsers cannot spoof them.
  • Usernames are case-insensitive (1–128 chars of a-z, 0-9, ., _, @, +, -).
  • unknown_users = "provision_viewer" (default) auto-creates new users as viewer; "reject" refuses unknown users. Bind existing principals under [trusted_proxy.identities].
  • Set allowed_hosts if the proxy preserves another Host header. Browser writes require X-SQB-CSRF or matching Origin.
  • The live-update SSE stream sends Cache-Control: no-cache, no-transform and X-Accel-Buffering: no with 15s keep-alives so proxies do not buffer or compress it.
  • sqb login still requires an https:// URL; code locations and workers use bearer tokens.

Map signed ID-token group claims to roles in [oidc] (groups grant roles only to users listed in [oidc.identities] and never grant admin):

[oidc]
origin = "https://control.example.com"
issuer = "https://login.example.com"
client_id = "orders-control"
groups_claim = "groups"
[[oidc.group_roles]]
group = "orders-operators"
role = "operator"
location_id = "0190c3c1-6b2f-7c3d-8e44-5f1a2b3c4d5e"

Groups are refreshed on each sign-in; editing group_roles and restarting the server takes effect immediately. Servers sharing a control database must use identical [oidc] settings.

Use service accounts for scripts and CI pipelines (Authorization: Bearer $SQB_SERVICE_KEY). Keys start with sqbk_ and are shown only once on creation or rotation:

sqb admin create-service-account orders-deploy --role developer --description "Release pipeline"
Command Effect
sqb admin create-service-account NAME --role ROLE Creates an account (viewer, operator, developer, or admin) and prints its key (or import one with --key-from-env VAR)
sqb admin rotate-service-account NAME Issues a new key; optional --overlap-minutes (up to 1440) keeps the previous key working
sqb admin disable-service-account NAME / enable-service-account NAME Revokes or restores the account’s keys
sqb admin list-service-accounts Lists accounts, roles, and key prefixes

Service accounts do not inherit default_role, cannot sign in to the browser or sqb login, and log all actions in the security audit log.

Declare node-scoped roles in roles.toml at the project root. sqb location publish resolves selectors on each publish and applies updated grants immediately:

[roles.orders_support]
description = "Answer order questions"
[[roles.orders_support.grants]]
nodes = ["tag:orders"]
permissions = ["view.sql", "run.adhoc"]
[[roles.orders_support.grants]]
nodes = ["tag:orders,tag:pii"]
permissions = ["view.evidence"]
  • Selectors follow job select grammar; administrative permissions (user.manage, role.assign, audit.view) are rejected.
  • job.run, run.rerun, run.rewrite_history, and ad-hoc commands require the permission on every affected node (or every node of the target for janitor). Catalog, statistics, provider, and run-list pages require view on every node of the publication.
  • trigger.toggle and sensor.reset_cursor require permission on every node the schedule’s job writes (or every node of the target for sensors). location.republish covers republishing.
  • Assign a project role via POST /api/admin/roles using the role key. Grants add up across roles.

Docker workers inherit their location container’s limits unless overridden by [launchers.docker.run] or a job’s [resources] (resources > launcher run > location container, capped by max_memory):

[launchers.docker.run]
memory = "1g"
cpus = 1
pids = 512
max_memory = "4g"
Key Launcher run Job resources Value
memory Yes Yes Bytes or size string ("512m", "2g")
cpus Yes Yes Positive number (0.5, 2)
pids Yes Yes Positive integer max processes
cgroup_parent Yes No Parent cgroup
max_memory Yes No Ceiling for any job’s resources.memory

Local launchers ignore [resources].

Lower a project pool limit for one launcher in server.toml (caps only lower limits; a job requesting more than the cap runs alone in that pool):

[launchers.local.pool_caps]
warehouse_heavy = 1
  • Server unreachable: workers keep running and buffer results for SQLBUILD_WORKER_CONTROL_GRACE (default 5m, range 1s–8m). Docker workers survive server restarts and are adopted when the server returns. If the grace period expires, the worker cancels running statements, fails the run, and leaves its logs on the worker host.
  • Lost worker: if a worker stops before finishing (or is silent for 10 minutes), the server marks in-flight nodes failed (R013) and unreached nodes not_run, releasing write claims only after the worker exits.
  • Stopping the server: SIGINT, SIGTERM, or SIGHUP stops scheduling, asks local workers to cancel in-flight statements cleanly, records outcomes, and releases claims. A second signal forces immediate exit.
Path Auth Purpose
/livez None 200 ok while the process is running (use for load-balancer liveness)
/api/health None 200 when all components are healthy, 503 if degraded/unavailable (use for monitoring)
/api/health/details user.manage Control database location, detailed causes, and failed request IDs

/api/health tracks the server, control database, scheduler, Docker launcher, locations (degraded after 90s silent), and event webhooks. If the control database is unreachable at start-up, the server still answers /livez, /api/health, and the UI Status page, returning 503 for API calls until the database reconnects. PostgreSQL server sessions enforce a 5-minute statement timeout and 2-minute idle-in-transaction timeout (30 minutes for migrations and publications).

Set SQLBUILD_PLATFORM_WEBHOOK_URL in the server environment to POST JSON platform events at-least-once and in order (deduplicate by event_id / Idempotency-Key; non-2xx or 10s timeout retries every 5s and marks webhook forwarding degraded). Set SQLBUILD_SECURITY_AUDIT_WEBHOOK_URL for security audit events.

kind Sent when Key fields
heartbeat Periodic replica liveness replica_id (also the scheduler lease holder’s ID), store_bytes, scheduler, version
scheduler_no_leader No replica holds the scheduler lease —
tick_overdue Schedule tick is late trigger_id, scheduled_for
calendar_horizon_low Running calendar has ≤1 day of dates left trigger_id, refresh_at, horizon_end
location_broken No instance reported for >90s location_id, target, last_seen_at
location_failing Load, change plan, discovery, or connection check failed location_id, target, state, failed_at, error, serving_generation
launch_failed Starting a worker failed run_id, claim_id, code
run_failed Job, group, or ad-hoc run ended failed See Fields of run_failed
trigger_skipped Scheduler skipped an unreadable trigger or failed sensor trigger_id, snapshot_id, reason
sensor_rechecked Sensor state unreadable; rechecked from scratch trigger_id, snapshot_id, evaluation_id
calendar_times_dropped Publish dropped due calendar times trigger_id, snapshot_id, times
unreadable_event_skipped Webhook or sensor skipped an unreadable stored event storage_id, event_id, event_type, location_id, target, reason
control_session_cut_off Control DB terminated an overdue/idle session idle, cut_at, error
recall_prune_soon Oldest run waiting for a target’s Recall store is halfway to deletion location_id, target, missing, oldest_missing_at, prunes_at
recall_run_lost A run’s log was deleted before the target’s Recall store held it location_id, target, run_id, job_key, ended_at

A failed group run emits one run_failed with run_kind: "group" (using root_failures to group causes and blocked jobs) plus one per failed member job. run_failed is delivered to the webhook and platform_event sensors.

Field Meaning
run_id, run_kind, job_key, location_id, target, outcome Run identity (job, group, or adhoc; job_key is null for ad-hoc) and target
url UI link to the run (null without a sign-in origin)
trigger { kind, name, person } (schedule, sensor, manual, or api)
started_at, ended_at, duration_ms Execution timing (null if never started)
error Run-level error (phase, code, message) when no node/audit error explains failure
failed_nodes, failed_node_count First 20 failed nodes (node_key, error_code, message, path, phase, url, logs_url) and total count
failed_audits, failed_audit_count First 20 blocking audit failures (name, node_key, sqlstate, message, failing_rows) and total count
succeeded_node_count, skipped_node_count, skipped_nodes Counts and first 20 skipped node keys
root_failures, root_failure_count Group runs only: first 20 root failures (job_key, node_key, blocked_jobs, blocked_nodes, blocked_node_count)

Messages are redacted and truncated to 2,000 characters.

Configure retention in [retention] in server.toml (all keys accept 1–65535; servers sharing a control database should use identical values):

Data [retention] key CLI flag Default
Hourly warehouse statistics statistics_days --statistics-retention-days 90
Security audit records audit_days --audit-retention-days 400
Published snapshots per location/target snapshot_count --snapshot-retention-count 10
Finished run logs (age) run_log_days --run-log-retention-days 14
Finished run logs (count per location/target) run_log_count --run-log-retention-count 200 (ignored when Recall is enabled on the target)
Synced builds and audit results per node state_history_versions --state-history-retention-versions 5 (SQLite), 20 (PostgreSQL)
Finished run output run_output_days — run_log_days
Local launcher snapshot file copies snapshot_files_days --snapshot-files-retention-days 7
Covered/skipped schedule ticks — — 30 days (fixed)

Audit records are retained past audit_days while pending delivery to the audit webhook or referenced by a retained run’s retry. Deleting a run’s log removes its statements, SQL, and output while keeping the run summary and node statuses.

Run stdout and stderr are stored outside the control database in [output]:

[output]
store = "file:///var/lib/sqlbuild/output"
max_bytes_per_run = "20GB"
  • store accepts a local directory (file:///path) or an S3 prefix (s3://bucket/prefix). By default it uses an output folder beside a SQLite control store, or ~/.local/state/sqlbuild/output (or $XDG_STATE_HOME/sqlbuild/output) with PostgreSQL.
  • Mount a persistent volume for local stores inside containers, and give separate control databases separate store paths. Use S3 when multiple server replicas share one PostgreSQL database.
  • max_bytes_per_run caps stored bytes per run (default unlimited), keeping the first and last halves when exceeded.
  • Reading run output requires view.evidence on every node the run selected; searches and downloads are recorded in the security audit log.
Store Backup command Online?
SQLite sqlite3 control.sqlite3 ".backup '/backups/control.sqlite3'" Yes
SQLite Copy database file + -wal file together No (stop server first)
PostgreSQL pg_dump Yes

Never copy a SQLite file without its -wal file. Stop the server before restoring, and remove any stale -wal / -shm files alongside a restored SQLite file.

Always upgrade the server before its code locations and workers, and back up the control database first (older releases cannot open a migrated schema):

  1. Pause schedules and sensors, and let active runs finish or cancel them.
  2. Stop all sqb server and sqb scheduler processes.
  3. Optionally preview schema changes with sqb server migrate --dry-run (or apply them with sqb server migrate).
  4. Start the upgraded server and scheduler.
  5. Upgrade and restart every code location so each republishes on the new release.
  6. Resume schedules and sensors.

Running a worker or location newer than the server fails with an upgrade prompt; running a server newer than a worker may fail runs that use newer request fields until the location is upgraded.