How should personally identifiable and other sensitive data be handled in database testing?
Answer
Use synthetic or irreversibly masked data by default and collect only the attributes required for the test purpose. If production-derived data is exceptionally necessary, apply documented authorization, minimization, encryption, access controls, retention limits and audit logging across extracts, backups and test results. Verify that masking preserves needed relationships without exposing original values, and include deletion, export and unauthorized-access cases in the test scope.
Strong answer includes
- prefers synthetic or irreversibly masked fixtures
- applies least privilege, minimization and retention controls
- tests privacy behavior as well as data utility
Practical example
Requires the authorized masked/synthetic test_customers and test_orders dataset.
-- Example test environment rule: all synthetic/masked emails use example.invalid
SELECT id, email
FROM test_customers
WHERE email IS NOT NULL
AND email NOT LIKE '%@example.invalid';
-- Find non-NULL references whose parent row is missing
SELECT o.id
FROM test_orders o
LEFT JOIN test_customers c ON c.id = o.customer_id
WHERE o.customer_id IS NOT NULL
AND c.id IS NULL;Prefer synthetic data. When a masked dataset is authorized, validate the masking contract and preserved relationships without reconstructing or comparing exposed production values. The exact marker rule must match the environment's documented masking implementation.
Expected result: No unmasked-looking rows under the documented rule and no broken required relationships.