
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
SliceDB is a tool for capturing and restoring a subset of a PostgreSQL database. It also supports scrubbing sensive data.
pip3 install slice-db
docker pull rivethealth/slicedb
For all commands and options, see Usage.
First, query a database to create a schema file.
slicedb schema > schema.yml
Second, dump a slice:
slicedb dump --root public.example 'WHERE id IN (7, 56, 234)' --schema schema.yml > slice.zip
Third, restore that slice into another database:
slicedb restore < slice.zip
For a complete working example, see Example.
Use the libpq environment variables to configure the connection.
PGHOST=myhost slicedb schema > slice.yml
See dump.yml for the JSONSchema.
SliceDB can produce multiple formats:
slicedb restore
.psql
or another client. If
restoring into existing schema, foreign keys must first be disabled, e.g.
SET session_replication_role = replica
.Schema can optionally be included. Restoring with schema requires an existing empty database.
The schema
command uses foreign keys to infer relationships between tables. It
is a suggested starting point.
You may want to prune the slice by removing relationships, or expand the slice by adding relationships that don't have explicit foreign keys.
slicedb schema-filter
can help modify the schema, or generic JSON tools like
jq
.
The slicing process works as follows:
Starting with the root table, query the physical IDs (ctid) of rows.
Add the row IDs to the existing list.
For new IDs, process each of the adjacent tables, using them as the current root.
Do this in parallel, using pg_export_snapshot()
to guarantee a consistent
snapshot across workers.
Hundreds of thousands of rows can be exported in only a few minutes and several dozen MBs of memory.
See transform.yml for the JSONSchema.
Replacements are deterministic for a given pepper. By default, the pepper is
randomly generated each run. You may specify it as --pepper
. Note that
possession of the pepper makes the data guessable.
Transformation may operate on an existing slice (TODO), or happen during the dump.
Transforms are specified by:
class
, the Python classconfig
, transform-specific optionsmodule
, defaults to slice_db.transforms
The name given to the transform is appended to the global pepper.
To create custom transforms, implement slice_db.transform.Transform
, expose
the class on a module, and install the module so that is accessible by
slicedb
.
The slice_db.transforms
package has many common transforms.
See transforms.md for the full list.
SliceDB can restore slices into existing databases. In practice, this should normally be an empty existing database.
Foreign keys may form a cycle only if at least one foreign key in the cycle is deferrable.
That foreign key will be deferred during restore.
A restore may happen in a single transaction or not. Parallelism requires multiple transactions.
Install: make install
Format: make format
git add slice_db/version.py && git commit -m "Version <version>"
git tag v<version>
git push origin master --tags
make upload
FAQs
Capture, scrub, and restore subsets of PostgreSQL databases.
We found that slice-db demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.