Lyrebird Community 0.5.8 is free · Generate a synthetic test database on your own machine · Download

How to Validate Synthetic Data Quality for a Test Database

Check foreign keys, data distributions, business rules, and privacy before using a synthetic database in QA. See measured examples from PostgreSQL Pagila.

On this page
  1. 1. Load the data and check referential integrity
  2. 2. Compare the distributions that your tests depend on
  3. 3. Test business rules and critical scenarios
  4. 4. Review sensitive fields before sharing

A synthetic database is ready for QA when it loads with its constraints enabled and supports the tests you plan to run. Those are separate checks. A valid foreign key shows that each rental has a customer. It tells you nothing about whether your test suite has enough customers with long rental histories, or whether a date filter has records on both sides of a cutoff.

Here is a practical validation checklist, with examples from our measured PostgreSQL Pagila copy.

1. Load the data and check referential integrity

Start with an empty database running the same engine and schema version as the application under test. Load the generated data with primary keys, foreign keys, unique constraints, and check constraints enforced. Record the row counts by table and the number of invalid references. A foreign-key failure can expose a missing parent table, an incorrect load order, or a bad key mapping.

For a single-column relationship, an explicit missing-parent query is easy to add to a smoke test. Run this on the generated Pagila database:

SELECT count(*) AS missing_customers
FROM rental AS r
WHERE r.customer_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM customer AS c
      WHERE c.customer_id = r.customer_id
  );

The expected result is zero. For a composite foreign key, compare the full key tuple and handle nulls according to the constraint’s match mode. Our Pagila snapshot contains 49,636 synthetic rows across 22 tables. The checks recorded zero broken references across 42 foreign keys.

For a many-to-many relationship, also check the join table. Pagila’s film_actor table has 5,462 generated film–actor pairs. Its primary key covers both columns, and each column has a foreign key to its own parent table. Generate the films and actors first, then generate distinct pairs from their existing IDs. After loading, check for missing parents on both sides and compare actors per film or films per actor if those counts affect your workload.

2. Compare the distributions that your tests depend on

Pick metrics that can change application behavior. For rentals, useful starting points are the share of rows with no return date, rentals per customer, and rentals per month. Retain an aggregate baseline from the source environment when its use is authorized, then run the same queries on the synthetic database. Point both queries at the same tables or populations, and keep null counts visible alongside the distributions.

SELECT date_trunc('month', rental_date AT TIME ZONE 'UTC')::date AS month,
       count(*) AS rentals,
       count(*) FILTER (WHERE return_date IS NULL) AS unreturned
FROM rental
GROUP BY 1
ORDER BY 1;

In our copy, the Pagila rental table had a 1.1% null share for return_date on both sides, rounded to one decimal place. The earliest source rental was in February 2022, while the earliest generated rental was in May 2022. A test for the February boundary still needs a fixture. Equal null rates and a close overall distribution can coexist with a missing edge case.

Pagila’s summary reports that 37 of 38 comparable columns fell below a distribution distance of 0.1. The denominator excludes key and sensitive columns from that aggregate, as well as columns lacking a comparable measure. The distance is a descriptive score for this snapshot. Set tolerances by test purpose, such as a minimum number of February rows for a date-filter suite or a realistic upper tail of rentals per customer for performance work.

3. Test business rules and critical scenarios

Run assertions for rules that the schema does not enforce. In a rental system, check that returned rentals have a return timestamp on or after checkout. In a billing system, compare invoice totals with the sum of line items and test refunds against eligible payments. Check across tables where the rule crosses tables.

Store named fixtures for the flows that must be available on every run, such as a rental on the last day of a month. For bulk data, keep the generator version, seed, schema revision, and validation queries with the CI run so a regression can be reproduced.

4. Review sensitive fields before sharing

Compare exact overlaps on fields where reuse would be unacceptable, such as customer emails and account identifiers. Check identifiers together where combinations can expose a person, and review which reference columns are deliberately reused. Run this comparison inside the approved environment and share aggregate counts instead of raw matches. A low match count is one signal. Release decisions also depend on what the dataset contains and who can access it.

Start with the Pagila results and downloadable profile to see these checks on a real schema, or use the PostgreSQL test data generation example to build a small seed from scratch.