State storage¶
Production: PostgreSQL. On OpenShift it is provisioned and managed by an operator. schedr only needs a connection string; it doesn’t manage the database itself.
Local development: SQLite.
All persistent state lives in the database, so the master can restart at any time without losing anything.
Schema upgrades are applied by a separate command,
schedr db migrate, run as a Kubernetes Job or init container before the master starts. The master refuses to start against an outdated schema. A schema migrated by a newer schedr is still usable (schema changes within a major version are additive), so older roles keep running during a rolling upgrade. Each backend has its own migration files (column types differ:TIMESTAMPTZ,UUID,JSONBin Postgres; text in SQLite), always with the same versions.Before the first release,
0001_initial.sqlis edited in place (no further migrations until there is something released to migrate); development databases are recreated.Times in SQLite are text in one fixed format,
2026-10-21T08:00:00.000000Z(UTC, six fraction digits), so comparing and sorting the text is comparing times; Postgres reads itsTIMESTAMPTZcolumns back in the same format.Queries are the same text for both backends: parameters that go into typed Postgres columns are cast there (
$1::uuid,::timestamptz,::jsonb) and read back as text; the casts vanish for SQLite. Unit tests run against in-memory SQLite; Postgres is covered by the integration tests (1.17).
Retention¶
How long the database keeps things (logs live on the workers and have their own retention, see Task logs). A log may disappear before its run or the other way round; the UI already handles “log unavailable”.
[retention]
runs = "90d" # "forever" disables it
outputs = "90d" # default: the same as runs; may be shorter
events = "90d" # default: the same as runs
commands = "365d"
interval = "1h" # how often the retention job runs
batch_runs = 100 # runs deleted per transaction
Runs: finished runs older than
runsare deleted with everything that belongs to them: task instances, attempts, outputs, cleanup handles, resource instances.Never deleted: runs not finished (
queued,running), and the latest run of each DAG, whatever its age: a DAG without a schedule quiet for longer thanrunswould otherwise lose its chain (the next manual run would fall back toinitial_sinceand reload everything);RUN_RECOVEREDneeds the previous run’s result; the UI shows the last run.Documented consequence: a backfill’s default (“fire times without a successful run”) sees deleted runs as missing, so a backfill over an old range creates them again.
Outputs: optionally shorter than runs (they are the bulky part, and nothing needs them once a run has finished, since there’s no “clear”; only the UI shows them). The run, its outcomes and statuses stay; the UI shows “output deleted by retention”.
Events (of triggers, see Sensors and triggers): older than
eventsare deleted. A trigger’s bookmark is never deleted (it lives with the trigger), so dropping repeated keys only needs to cover the retention window: a trigger never goes back further than its bookmark.Command rows (the audit trail) are kept independently of runs: a command about a deleted run stays readable.
DAG versions are kept while current or referenced by a retained run (a run’s graph is drawn from the version it ran with); others are deleted. A removed DAG (hidden, history kept) disappears completely once its last run is deleted; if its ID appears again, it starts with no history.
Parse results and import errors: only the latest per file is kept (older ones are deleted when a newer parse of that root is stored); no setting.
How: a background job on the master (
interval, every hour by default), deleting in batches ofbatch_runsruns per transaction (default 100: one run can hold over a thousand rows, e.g. a mapped task’s instances, attempts and outputs), repeated until nothing is left, so it never holds long locks or blocks scheduling; the same in standalone (SQLite). Partitioning tables by time: possibly later.