Skip to content

Sanitization

Sanitization runs a SQL transformation on a snapshot to remove or replace sensitive data. It operates as a 3-step pipeline:

  1. Restore the source snapshot to a dedicated sanitization database
  2. Execute the sanitization SQL query against that database
  3. Dump the sanitized database to a new snapshot

The result is a new snapshot with type sanitized that is safe to share with developers, use in CI/CD, or load into non-production environments.

The target must have two additional fields configured:

Field Description
sanitize_dst_url Connection URL for the dedicated sanitization database
sanitize_query_file Path to a SQL file containing the sanitization queries

When adding a target, include the sanitization fields:

Terminal window
clonit targets add \
--name mydb \
--src-url "postgres://user:pass@prod:5432/mydb" \
--dst-url "postgres://user:pass@localhost:5432/mydb_dev" \
--sanitize-dst-url "postgres://user:pass@localhost:5432/mydb_sanitize" \
--sanitize-query-file /path/to/sanitize.sql

The sanitization query file is a plain SQL file that runs against the restored snapshot. You can use any valid SQL statements – UPDATE, DELETE, TRUNCATE, etc.

-- Replace email addresses with deterministic fake values
UPDATE users SET email = concat('user', id, '@example.com');
-- Replace password hashes with a known dummy value
UPDATE users SET password_hash = '$2a$10$fake_hash';
-- Remove audit logs entirely
TRUNCATE TABLE audit_logs;
  • Use deterministic replacements (e.g., based on id) so the sanitized data is consistent across runs.
  • Truncate large tables that contain only operational data (logs, events, sessions) to reduce snapshot size.
  • Test your queries against a copy of the database before using them in production workflows.
  • Order matters – queries execute sequentially in the order they appear in the file.
Terminal window
clonit sanitize mydb
Terminal window
clonit sanitize mydb 0

Use clonit snapshots mydb to see available snapshot indices.

After sanitization completes, a new snapshot is created with type sanitized. You can see it in the snapshots list:

Terminal window
clonit snapshots mydb

Example output:

Index Name Type Size Created
0 mydb-20260208T120000 snapshot 245 MB 2026-02-08 12:00:00
1 mydb-20260208T120000-sanitized sanitized 198 MB 2026-02-08 12:05:00

The sanitized snapshot can then be used like any other snapshot – load it to a destination database, push it to cloud storage, or share it with your team.

A typical sanitization workflow looks like this:

Terminal window
# 1. Build a snapshot from production
clonit build mydb
# 2. Sanitize the snapshot
clonit sanitize mydb
# 3. Load the sanitized snapshot to a dev database
clonit load mydb 1
# 4. Optionally push the sanitized snapshot to cloud storage
clonit push mydb 1