safeslice

Open source · PostgreSQL · Privacy

Production-like PostgreSQL data.
Without production PII.

Safeslice turns a production database into a small, realistic development one: relationship-aware extraction, deterministic masking, and a privacy scan over the result. One command, and the source is never written to.

View on GitHub
safeslice
$ safeslice

What would you like to do?

❯ 1  Create a safe development database   the whole workflow, start to finish
  2  Inspect an existing configuration    what a run would do; reads no data
  3  Verify an existing database          scan for personal data that survived
  4  Run demo                             throwaway database — nothing of yours is touched

↑↓ to move · enter to choose

✓ Connecting to the source
✓ Reading the schema        18 tables · 27 relationships
✓ Selecting rows            9,240 rows across 5 tables
✓ Extracting and masking    11 columns masked
✓ Verifying the result      privacy scan passed

postgres://localhost/myapp_dev  ready

The problem

Production data is useful. Production PII isn't.

You need realistic data to find real bugs — the null that only exists in row 4,000,000, the customer with 900 orders who breaks the query. You cannot put production data on a laptop, and it does not fit there anyway.

The usual way

Production480 GB
→
pg_dumpeverything
→
Laptopreal customers

A dump does not know which columns are people. It copies all of them — onto unmanaged laptops, into CI logs, into local backups.

With Safeslice

Productionread-only
→
Safesliceslice · mask · verify
→
Development9,240 rows

A few thousand rows with every name, email and card number replaced, every foreign key intact, and a privacy scan over the result.

How it works

Five stages, one command

Discover

Reads pg_catalog for tables, keys, unique constraints, identity and generated columns, sequences and partitions. No table data.

Slice

Walks the foreign-key graph from a root table. Parents transitively, children to a bounded depth.

Mask

Replaces personal data in transit, deterministically, before it reaches disk.

Load

Streams into the target in dependency order, handling cycles, identity columns and sequences.

Verify

Scans the loaded database for values that still look like real personal data.

The read side runs inside one REPEATABLE READ snapshot, so a parent row cannot vanish between the query that found a child and the query that fetches it.

Masking

Deterministic, and type-aware

The same input and seed always produce the same replacement, so users.email and invoices.billing_email still join after masking. These are real outputs at seed safeslice.

users.email
john@example.com
→
email
user_0b1343bf051a1e1c@example.invalid
users.first_name
John
→
first_name
Riley
users.last_name
Smith
→
last_name
Kowalski
users.phone
+1 555 010 2938
→
phone
+15550563127
payments.card_number
4111111111111111
→
govid
00D1AF1CBD6
users.password
hunter2
→
secret
REDACTED
tickets.body
Called about a refund…
→
redact
dropped

Key columns are never masked — rewriting them would destroy the referential integrity the slice exists to preserve. NOT NULL is respected, varchar(n) is not overflowed, an int column never receives a string, and a column under a UNIQUE index is retried until the value is free.

Free text is the honest limit. No regex reliably scrubs a support ticket that quotes a customer's address. Safeslice surfaces every unclassified text column and asks; strict mode refuses to run while any remain unreviewed.

Features

What it actually does

PostgreSQL-native

Reads pg_catalog directly. No ORM, no schema file to keep in sync, no agent.

Foreign-key aware

Every row brings the rows it references. The slice restores without a single orphan.

Deterministic masking

Same input and seed, same output — so a customer email masks identically in every table it appears in.

Free-text redaction

Columns no heuristic can judge are surfaced for a decision, never silently passed through.

Privacy verification

Scans the result for live emails, phones, IPs and Luhn-valid card numbers. Non-zero exit on findings.

Interactive wizard

One command carries you from connection to verified database.

CLI and CI mode

The same pipeline, scripted. verify gates a pipeline as-is.

Read-only source

The session is set read-only before anything else runs. Point it at a replica.

Configurable rules

Eleven rules, per column, in a YAML file your team commits and reviews.

Output

A database, and the paperwork to go with it

Every run writes its own evidence. No artifact contains a password — a test walks every generated file to prove it.

README.md

What ran, what was masked, how to connect — for a ticket or a PR.

report.html

The full run with the relationship graph. Opens from disk; no network.

summary.json

Machine-readable result, for CI to assert on.

tables.csv

Per-table row counts and masked-column counts. Metadata only, never rows.

masking-rules.yaml

Exactly the rules that were applied, ready to commit.

Safety

What it will and will not claim

  • The source is opened read-only. Set before anything else runs, so no bug here and no predicate you paste can write to production.
  • It refuses to run when the target resolves to the same host, port and database as the source.
  • Destructive target operations require typing the database name. Nothing is silently overwritten.
  • Credentials are never printed or stored. Connection strings are reduced to host, port, database and user before reaching any log, report or saved profile.
Verification is a safety check, not a proof. A clean scan means no known pattern of personal data was detected in the sampled rows. It is not a mathematical guarantee that arbitrary free text contains none, and Safeslice never claims it is.

Read the security model →

Use cases

Where teams put it

Local development

Realistic data on a laptop without the compliance surface of real data.

Reproducing production bugs

Slice around one customer with a filter: id = 4821.

Preview environments

A few thousand rows per branch instead of a 480 GB restore.

Integration testing

Deterministic seeds mean the same fixtures every run.

QA and staging

Refresh a shared environment without shipping customer records into it.

Onboarding

A new engineer gets a working database on day one, not a redacted CSV.

Automation

The wizard is for humans. These are for pipelines.

safeslice run --config safeslice.yaml --to "$DATABASE_URL"
safeslice verify --target "$DATABASE_URL"

verify exits non-zero when it finds anything, so it gates a pipeline as-is. The wizard writes the same safeslice.yaml your CI reads, so what one engineer does interactively is what every job repeats.

Connection snippets for psql, Prisma, Rails, Django, Node.js and Go are written into the generated README.

Open source

Build against production-like data.
Not production customer data.

Apache-2.0. One static Go binary — no runtime, no server, no control plane, nothing to shut down. PostgreSQL 13–17, tested against both ends of that range in CI.

Read the docs

Found this useful? ★ Star it on GitHub It is how other people find it.

Install Safeslice

curl -sSfL "https://github.com/Autometiq/safeslice/releases/latest/download/safeslice_$(uname -s | tr A-Z a-z)_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz
sudo mv safeslice /usr/local/bin/

Then run it with no arguments — it asks for everything it needs:

safeslice

No database of your own? Choose Run demo — it starts a throwaway PostgreSQL, seeds it with fake customers and runs the whole pipeline. Nothing of yours is touched. Full quick start →