Skip to main content

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 fast row transfer
  • 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.

Incremental subsetting can keep a long-lived staging database current without rebuilding it. After production data changes, a topup run adds newly targeted entities and their related rows, while a grow run also captures new descendants such as orders for customers already present in staging. Re-read rows are refreshed, but source deletions and schema changes require a recreate or separate migration.

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:

  1. Install astral-uv

  2. Install Postgres and/or MySQL database tools. For Postgres we need pg_dump and psql tools; they need to be on your $PATH or point to them with $POSTGRES_PATH. For MySQL we need mysqldump and mysql, they can be on your $PATH or point to them with $MYSQL_PATH.

  3. Clone this project locally.

  4. Install the project with uv sync --frozen

  5. Setup your configuration and save it in config.json. The provided config.json.example has the skeleton of what you need to provide: source and destination database connection details, as well as subsetting goals in initial_targets. Here's an example that will collect 10% of a table named public.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-config for the full configuration reference (also in CONFIG.md), and subset --example-config for all of the options in a single config file.

  6. 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.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for db-condenser 1.7.1
File Size Uploaded
db_condenser-1.7.1.tar.gz 52.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for db-condenser 1.7.1
File Interpreter ABI Platform
db_condenser-1.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 117.4 kB

Release files / db_condenser-1.7.1.tar.gz

Download URL db_condenser-1.7.1.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
af6cb36ea5b66a4d6844f3017800e2cda1a3e8165b19d93b92d727ebb631eb80
BLAKE2b-256 checksum
How to use checksums
1e9bed46018c3f4704f89475ab67a22a21b1607ed03e2b63728342bd33b3d054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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.7.1-py3-none-any.whl

Download URL db_condenser-1.7.1-py3-none-any.whl
Size 65.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
763e152bd2b458e7ea003d9aae9983afb01c9c7a2d8d063fb375c157eb42ecb2
BLAKE2b-256 checksum
How to use checksums
3d36d3705c2078ef1b8a6fe0d7183c9ca656ce6bf6a7258b8670f74ea2ba8bc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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 history Release notifications | RSS feed

This release

1.7.1 This release

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page