Profiling a Database
Measure what the live data says about the code — value usage, dead codes, keys, codes over time — and find references no schema declares, with counts only.
The code says status IN (1, 2, 3). The data may also hold 5 and 9, or may not have held 2 for years. ekos profile run measures that, and ekos relationships discover finds references between columns that no schema declares. Both are new in v1.5.0 (RFC 0252), read-only, and make no model call.
Privacy: counts, never values
- A data value never leaves the database. Every profiling query returns a code literal (a value the code already names, and so already in the ledger) or
NULLfor "everything else", with counts. - The profiler runs a closed set of aggregate queries, never free SQL.
- Reference signatures are computed by the database: salted MD5 digests reduced to a few minimums per column. Only those and counts come back. The salt is
<state>/profile/salt(mode 0600), never in the ledger. - Columns whose name says personal data get counts only; low-cardinality and personal columns get no signature.
- The session is the read-only probe session of
ekos sql check, and a role that can write is refused unless you pass--allow-writable-role.
The values behind an "unexplained values" count can be shown to a person on read, live, and are never stored: see People as a Source.
Before you start
- Connect the database as a
[[databases]]entry withprofile = "p1"or"p2"(Indexing a Database). Every kind is supported: Oracle, PostgreSQL, ClickHouse, SQL Server, Informix and DuckDB files. - Turn on business semantics (
[semantics] enabled = true). The code values come from there. Without it, the measurements are kept but no meaning carries them, andprofile runsays so. - Run the pipeline once (
ekos build && … && ekos commit).
Measure
ekos profile run # every [[databases]] entry with p1/p2
ekos profile run --database erp --signals literal,keys
ekos profile show # what the latest run measured, every table
ekos profile show orders # one table
| Signal | Measures |
|---|---|
literal |
rows holding each value the code names, and rows holding values no code names (counts only) |
temporal |
first and last month each code value was seen, on the table's creation or update time column. A value not seen for --dead-after months (default 24) before the column's latest row is dead |
monthly |
rows per code value per month; profile show draws the last 24 months as a sparkline, and a month under the small-cell limit is withheld |
conditional |
column = v ⇒ other IS [NOT] NULL implications |
keys |
each table's grain: its declared key, or a key of up to three columns found by a bounded search |
history |
validity periods (valid_from / valid_to) and soft-delete flags |
usage |
how often the application's own statements touch each table: SQL Server Query Store (or the plan cache), Informix sysmaster, PostgreSQL pg_stat_statements and table statistics. EKOS's own sessions are left out (new in v1.5.5) |
cast |
for each text column the code converts to a date or number, how many non-null values would fail the conversion |
--max-rows (default 10,000,000, by the catalog's estimate) skips larger tables. Each usage source the server does not grant is reported as unavailable with the server's reason: Query Store needs VIEW DATABASE PERFORMANCE STATE, Informix SQL tracing is the DBA's to switch on and grant.
Where the results go
| Measured | Becomes |
|---|---|
rows per code value, first and last seen, dead, never_seen |
data_usage on the value's EnumMeaning |
| values no code names | a data_only_values gap on the column |
| implications | implies on the EnumMeaning |
| grain | one GrainCandidate per table |
| validity periods, soft deletes | data_history on the table's WriteBehaviour |
| a code value never seen in the data | a code_vs_data conflict |
Re-profiling never stales a review: counts are shown, not signed. The latest run is kept in <state>/profile/current.json.
Codes over time (new in v1.5.5). Where git history is available, each value the data holds gets a code_history: the commit that first put the literal on the cited line, and whether the data held the value before the code named it (data_before_code, same_month, code_before_data). A data-only gap is marked new when all its unexplained values are newer than the code's last change. profile show says "code since … — the data held it first".
Find references in the data
ekos relationships discover # each database
ekos relationships discover --cross-database # also compare key columns across databases
ekos relationships list # the candidates, best first
- A signature of every comparable column is computed in the database.
- Pairs where a child's values are contained in a unique parent column (estimated containment ≥
--min-containment, default 0.9; parent with at least--min-parent-distinctdistinct values, default 20) are proposed. Every join the code makes is added. - Each pair is then checked exactly by an inclusion query, with orphan and population counts, and gets a verdict:
clean_relationship,relationship_with_orphans,unclearornot_a_relationship.
Each candidate is an FkCandidate with seed: code | data | both; a pair seeded by both is the strongest. Since v1.5.5 discovery proposes no second parent: a column that is already the child of a declared foreign key gets no candidate, and a column the code joins keeps only its code-seeded parents. With --cross-database, overlap between key columns of two databases becomes value_overlap on a cross-system SameAs candidate, never a merge (Indexing Enterprise Applications).
Review
Inferred references are hypotheses until a person decides them, in the optional review subject relationships, which appears once discovery has produced items:
ekos review show relationships
ekos review relationships "invoice.parts_id → partstax.parts_id" --confirm --reason "checked with the app team"
ekos review relationships <id> --confirm-with-orphans --reason "old rows predate the parts table"
ekos review relationships <id> --reject --reason "id ranges overlap by chance"
Decisions are human-only; no MCP tool makes one. A confirmed reference with orphans tells later steps (a lakehouse silver test, for example) that the target must tolerate them.
Agents, console and documentation
- MCP:
ekos_profile(a table's or column's row count, nulls, grain, code usage with first and last seen, unexplained counts, monthly usage and inferred references) andekos_relationships(candidates with seed, verdict, counts and the review decision). Both are read-only and follow the caller's read scope. - Console: the Semantics panel draws "Usage over time" for a code value, with the month the code first named it marked.
- Estate documentation:
ekos docs generate --layout estategives every table page a source passport (since v1.5.0): What a row is (grain, row count), Keys and references (declared, then code- and data-seeded candidates with verdict and decision), Codes (value, meaning, where it is stated, share, first and last seen, dead or never seen), How it changes, What the code assumes, What people said and Open questions. Each section appears only when it has content; each fact carries its status and evidence; counts only.
Measured
- LedgerSMB (PostgreSQL, profile p1):
profile runin 80 s over 199 tables: 228 code values measured, 167 never seen in that data; 3 columns holding values no code names; every count equal to a direct query. 4 implications, each equal to the data. - iDempiere (Oracle seed): literal coverage re-counted on 40 random columns, 121 of 121 counts equal; 860 implications, all exact. After the one-parent rule, discovery proposed 13 references, 2 of them true by hand review (15% precision). Recall could not be measured on that seed: every real undeclared reference points at a parent with fewer than 20 distinct values.
Not yet: dead-code verdicts for flags set by updates (199 dead codes on iDempiere, 0 of 10 sampled actually retired: the creation-time axis does not fit them); measure columns compared with 0 are still taken for coded columns; Informix columns get no overlap signature (Informix has no MD5).