Database Condenser
A config-driven database subsetting tool for PostgreSQL and MySQL, forked from Tonic's Condenser.
Major changes from the original Condenser implementation:
- Supports subsetting databases larger than 10 GB, which the original implementation struggled to process
- Designed to run against read-only instances and replicas, reducing load on the primary database
- Supports incremental top-ups, allowing existing subsets to grow without rebuilding the destination database
- Handles dense and complex FK relationship graphs
- Uses concurrent worker pools throughout the subsetting process to improve performance
- Postgres COPY protocol for faster transfer enabled by default
- Automatic sequence reset after subsetting
- Built with psycopg3 and managed with Astral's uv
Subsetting data is the process of taking a representative sample of your data in a manner that preserves the integrity of your database, e.g., give me 5% of my users. If you do this naively, e.g., just grab 5% of all the tables in your database, most likely, your database will break foreign key constraints. At best, you’ll end up with a statistically non-representative data sample.
One common use-case is to scale down a production database to a more reasonable size so that it can be used in staging, test, and development environments. This can be done to save costs and, when used in tandem with PII removal, can be quite powerful as a productivity enhancer. Another example is copying specific rows from one database and placing them into another while maintaining referential integrity.
You can find more about the original Condenser details here and here.
Requirements
- Python 3.10+
- Postgres 14+
Installation
Six steps to set up from source:
-
Install astral-uv
-
Install Postgres and/or MySQL database tools. For Postgres we need
pg_dumpandpsqltools; they need to be on your$PATHor point to them with$POSTGRES_PATH. For MySQL we needmysqldumpandmysql, they can be on your$PATHor point to them with$MYSQL_PATH. -
Clone this project locally.
-
Install the project with
uv sync --frozen -
Setup your configuration and save it in
config.json. The providedconfig.json.examplehas the skeleton of what you need to provide: source and destination database connection details, as well as subsetting goals ininitial_targets. Here's an example that will collect 10% of a table namedpublic.target_table."initial_targets": [ { "table": "public.target_table", "percent": 10 } ]There may be more required configuration depending on your database, but simple databases should be easy. Run
subset --help-configfor the full configuration reference (also in src/db_condenser/CONFIG.md), andsubset --example-configfor all of the options in a single config file. -
Run!
$ uv run subset
Or, from PyPI:
pip install db-condenser
pipx install db-condenser
Running
Almost all the configuration is in the config.json file, so running it is as simple as
uv run subset
If you installed from PyPI:
subset --config config.local.json
These command-line arguments are supported:
-v: Verbose output. Useful for performance debugging. Lists almost every
query made, and its speed.
--no-constraints: For Postgres this will not add constraints found in the source
database to the destination database. This option has no effect for MySQL.
-y: Skip confirmation on subsetting to destination host if it isn't localhost
or 127.0.0.1
--config <file>: Use a custom JSON config file instead of the default
config.json.
--help-config: Print the full configuration reference and exit.
--example-config: Print an example config.json with all options and exit.
Useful as a starting point: subset --example-config > config.json.
Metadata
Release files for db-condenser 1.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| db_condenser-1.6.1.tar.gz | 46.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| db_condenser-1.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 100.7 kB
Release files / db_condenser-1.6.1.tar.gz
| Download URL | db_condenser-1.6.1.tar.gz |
|---|---|
| Size | 46.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b6e0e4b2f414c39d4ce63bbb8ff82557cc58e5a4e411775514a9ac75a5350ec
|
|
BLAKE2b-256 checksum How to use checksums |
2d629c919ddc7706a14b285da042300f7688835b021f17bc76d2a0c225452138
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / db_condenser-1.6.1-py3-none-any.whl
| Download URL | db_condenser-1.6.1-py3-none-any.whl |
|---|---|
| Size | 54.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20e80b3f93b1b5d39e99097fec503824be7ff193eeadc3dc226ae9d4040d1c50
|
|
BLAKE2b-256 checksum How to use checksums |
46984e876b075ea9be410e9cb096f17ac15841bf7c89bca96fcd4f4b8286e956
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|