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 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:

  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 src/db_condenser/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.6.0

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.6.0
File Size Uploaded
db_condenser-1.6.0.tar.gz 45.0 kB Details

Built distribution (wheel)

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

Total release size: 97.3 kB

Release files / db_condenser-1.6.0.tar.gz

Download URL db_condenser-1.6.0.tar.gz
Size 45.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8f473be2206a0257ca5232ea0eb1430bff022a4a9cbffb4a14d8eb2e1b6c7d16
BLAKE2b-256 checksum
How to use checksums
597198343ecb0cc23513939edf49d04d68df55355a073bdff606575f828f76ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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.0-py3-none-any.whl

Download URL db_condenser-1.6.0-py3-none-any.whl
Size 52.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc4724d1cc3246aeff7b7184226edebbf358bd10687b9b9fd12132cfef0ad44a
BLAKE2b-256 checksum
How to use checksums
5caaf3dca8a6dbb8fec0bf8b02a1d4cd08c8189c4aa57077eb721e7a317e1942
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","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

1.7.1

2 release files

1.7.0

2 release files

1.6.1

2 release files

This release

1.6.0 This release

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