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.

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.7.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.7.0
File Size Uploaded
db_condenser-1.7.0.tar.gz 45.9 kB Details

Built distribution (wheel)

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

Total release size: 99.1 kB

Release files / db_condenser-1.7.0.tar.gz

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

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

This release

1.7.0 This release

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