Twin
ghostrow twin measures a database on your machine and generates a synthetic copy with the same shape. Options, what is measured, and the privacy rules that keep real rows out of the copy.
ghostrow twin (Max) measures a database and generates a synthetic copy that has the same shape: the same tables, similar row counts, similar null rates and value ranges, and similar numbers of children per parent. The measuring happens on your machine. Nothing is sent anywhere, and no real row is copied.
ghostrow twin --from postgres://readonly:secret@prod-replica/app --out twin/ --scale 0.1 --seed 5
Options
| Option | Meaning |
|---|---|
--from <url> | Database to measure. Required. Read-only access is enough |
--to <url> | Insert the copy into this database. The tables must already exist |
--out <dir> | Write files instead. Use --to or --out, not both |
--scale <factor> | Make the copy larger or smaller. 0.1 is a tenth of the rows, 2 is double. Default 1 |
-f, --format csv|sql|json | File format for --out. Default csv |
--seed makes the copy repeatable, as with seed. --rules applies your rules file, and --code adds code rules. A table that has rows is never scaled down to zero rows.
Without --from, twin stops with twin needs --from <url>: the database to measure. Without --to or --out, it stops with twin needs --to <url> or --out <dir>: where to write the synthetic copy.
What is measured
For each table Ghostrow reads up to 50,000 rows into memory and computes:
- the row count (a full count for larger tables);
- the share of
NULLin each column; - 21 quantiles for numbers, dates and text lengths;
- how many children each parent row has, for each foreign key;
- the values of low-cardinality category columns, under the rule below.
Only these summaries are kept. The generator then builds new rows from them, with the usual seed rules, so foreign keys, unique columns and CHECK constraints still hold. Keys and references are always newly generated.
Privacy rules
- No row is copied. Every value is generated. Twin does not sample, shuffle or mask real rows.
- Personal fields are never profiled by value. Columns understood as email, phone, names, usernames, password hashes, tokens, company, national ID, postal code, street, address, IP address, coordinates, URL, domain, free text, birth date, slug, SKU, file path, JSON, bytes, UUID and keys get new synthetic values. Their actual values are never kept or reused. Only summary statistics such as the null rate and quantiles are measured, and keys only have a null rate.
- Categories need at least five rows. A value of a category column (a status, a country code, a plan) is reused only if five or more rows share it. Rarer values are dropped. The kept values must cover at least 80% of the rows, and the column must have at most 40 distinct values, each at most 60 characters. Otherwise the column is not treated as a category at all.
The last line of a run says so: 0 violations · no source row copied; categories reused only when shared by ≥5 rows.
Output and report
measuring app.db (2 tables, read-only)
ghostrow twin · app.db → twin-out · scale 0.5 · Max
users 81 measured → 41 synthetic
posts 240 measured → 120 synthetic
wrote 2 CSV files to twin-out (+ twin-report.json)
161 rows, 0 violations · no source row copied; categories reused only when shared by ≥5 rows
With --out, Ghostrow also writes twin-report.json into the folder. For each table and column it lists the null rate and the median as a pair, source first and copy second, so you can see how close the copy is:
{ "column": "full_name", "nullRate": [0.123, 0.146], "median": [18, 18], "categories": 0 }
The report holds aggregate statistics only. categories is the number of category values that passed the five-row rule.
Target databases
--to checks that every measured table exists in the target and stops with The target database is missing N table(s): ... if not. Create the schema there first, with your migrations. Rows go in one transaction, and numeric keys continue after the largest existing one.