Chronos DB 0.1.2
Move from Postgres in one command: `chronos import <folder> postgres://...`
Move from Postgres in one command: chronos import <folder> postgres://...
- Reads a live Postgres's catalog and brings over schemas, enum types, sequences (continued past the rows), tables with their columns, defaults, keys,
UNIQUEandCHECK, every row (COPY, text format, a table at a time), then foreign keys, indexes, views and materialized views. Extensions, functions, triggers, row-level security, roles, and anything Chronos refuses are listed in a report instead of stopping the import.--dry-runtries every definition on an empty in-memory database and writes nothing. - A small Postgres client of its own (TLS as libpq's
sslmode, SCRAM-SHA-256), so the binary gains no dependency.
Stale-read check: merges that relied on rows that changed since the fork
- A world forked
WITH (check_reads = true)keeps what it reads (keys, a scan's range, index lookups, and whole tables for searches, bounded per table), and its merge is refused (40001) when any of it changed in the world it merges into since the fork, though it never wrote it. For an agent under a merge policy it's a reason like any rule, and the world is queued inSHOW REVIEWS; a policy withcheck_reads = trueturns it on for all its agents' worlds, and they can't turn it off. Reads in a transaction count for its world. After a restart earlier reads are unknown, so such a merge is held.
Merging by columns, per table
ALTER TABLE t SET (merge_by_columns = true)makes every merge into a world with the setting combine a row both sides changed when they changed different columns, asMERGE ... BY COLUMNSdoes;RESET (merge_by_columns)goes back to whole rows, still the default. The same column changed on both sides always conflicts. The setting is a change to the table: inDIFF(merge: by columns), inDIFF ... AS SQL, and a schema change under merge policies.- A conflict whose rows all had different columns changed says so, and names
BY COLUMNSand the table setting.
Merge policies
ALTER MERGE POLICYandCREATE MERGE POLICYread, change and write in one step: two changes at once both land, a policy dropped meanwhile isn't written back, and two creates of one name can't both succeed.DROP MERGE POLICY name CASCADEtakes the policy from its agents and drops it in one step; MCP'sdrop_merge_policywithrelease_agentsuses it, so agents are never released without the drop.SHOW REVIEWS: after a partial merge (ONLY TABLES,ONLY KEYS) of a queued world,changed_sinceis true. The world's version doesn't move, so clients' merges at the version they had still work.
What a change affects: readers of every changed column
DIFF WORLD w [TO b] READERSlists what in the database reads each column the diff changes: views and materialized views (traced column by column through their queries, views on views included), merge checks, triggers (by event andUPDATE OF), functions (where their text names the table and column), primary keys, unique constraints, foreign keys (both directions), CHECK constraints and indexes (expressions andWHEREincluded). Rows added or deleted reach every reader of their table.- Clients seen reading: SQL over the Postgres protocol records which columns each client reads (by role, and
application_name), and over HTTP by agent; a change's readers name them with when they last read.REGISTER READER name ON table (cols)names readers outside SQL (exports, sync tools), kept in the world;UNREGISTER READER,SHOW READERS. - Critical readers:
MARK READER billing CRITICAL/UNMARK READERmark a reader of any kind, in the world (forks carry it,DIFFshows it,SHOW READERSkeeps who and when).DIFF ... READERSlists critical readers first, then by blast radius, with acriticalcolumn; merge policies get acriticalrule (defaultfalse) that holds an agent's merge changing a column a critical reader reads. - Every answer ends with what was covered: since when reads have been recorded and through which doors, and that
EXECUTEstrings aren't followed, so "no readers" is never read as "nothing reads this". - Over HTTP,
diffwithreaders: trueand every mergedry_runreturnreadersandcoverage; over MCP,difftakesreadersandmerge_previewappends them; the Studio's Changes view shows them.
Merge checks: rules every merge's result must keep
CREATE [OR REPLACE] MERGE CHECK name [ON TABLES (...)] [WITH (timeout = '2s')] AS SELECT ...,DROP MERGE CHECK,SHOW MERGE CHECKS. A check is a query that must find nothing in what a merge would make. Every merge runs the checks for the tables it changes, on the world it merges into as the merge would leave it (partial merges andINTOincluded), inside the merge and under its locks, so two changes that are each fine but break a rule together are caught. Rows found refuse the merge (23514, HTTP 409) with the rows as the reason; an agent keeping to a merge policy is queued inSHOW REVIEWSinstead. No one merges past a check, people included; onlyadmincreates or drops one.- A check is one
SELECTthat changes nothing, run read only within its timeout (default 1 second; a merge it doesn't finish in is refused), stopping at the 11th row.MERGE ... DRY RUNnames the checks that would fail and their rows inblocked. - Over MCP:
merge_checks,set_merge_check,drop_merge_check; in safe mode the last two answer with the SQL for a person to run. See docs/guides/merge-checks.md.
Column defaults
- A default Postgres works out afresh for each row is refused (0A000) instead of being evaluated once.
DEFAULT random(),DEFAULT (nextval('q') + 100)orDEFAULT now() + interval '7 days'gave every row the same value; nowCREATE TABLE,ADD COLUMNandSET DEFAULTrefuse them, naming the column and the expression. Sequences,serialand identity columns,gen_random_uuid(),now()(andCURRENT_TIMESTAMP,transaction_timestamp(),statement_timestamp(),clock_timestamp()) andcurrent_dateare worked out per row, as before, and constant expressions still work. A subquery in a default is 0A000, as in Postgres. DEFAULTreads arithmetic and||(DEFAULT 60 * 60,DEFAULT 'a' || 'b');DEFAULT nextval('s') + 1was a syntax error.nextval('s'::regclass)defaults use the sequence. pg_dump and Postgres's catalog write serial and identity columns that way, and it was taken as a constant, so every insert got the same id.ALTER TABLE ... SET DEFAULT nextval('s'[::regclass])on an integer column numbers it from the sequence, as theCREATE TABLEform does.chronos import postgres://brings a column with a refused default over without the default, and reports it (Supabase'stimezone('utc'::text, now())is one), instead of skipping the table.
Speed on many cores (a 32-core server, c2d-standard-32; BENCHMARKS.md was rerun on it against 13 rivals)
- Joins and grouping over the protocol: the 20,000-row join +
GROUP BYwent from 11.5 ms to 4.4 ms (Postgres 17: 6.9 ms). Linux builds use mimalloc on glibc too (11.5 to 8.1 ms: glibc gave each query's big batches back to the kernel, and the next query faulted them in again); helper threads wait between queries instead of starting afresh for each step (8.5 to 7.4 ms; in process, a 200kcount(*)5.0 to 2.8 ms); tables of 8,192 rows or more split into up to 16 parts, so a 20,000-row table uses more than 4 cores (7.2 to 4.4 ms). - Agents writing on disk: 1,000 agents, each forking main, writing 1,000 rows one by one and merging, on one thread each: 5.0 s to 1.76–1.80 s. A world other than main logs its writes in batches (one lock taken per batch, not per row), and a thread finds its world without the branch map's lock. Merges on disk at 1,000 threads are still slow: p50 714–718 ms against Postgres's 128 ms at 25 workers.
- Vector search p99: a vector graph counts as built only once its self-test has run. Before, the first searches ran beside 128 exact probe scans on every core: p99 8.6 ms, now 2.1–2.7 ms.
Durability
mainand merges are synced as before. New: a crash can lose an open world's writes even after a latermaincommit was synced (they're logged in batches). After a crash each open world comes back as some prefix of its own writes, and it's flagged. See versions and crashes and operations.