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:

  • Concurrent thread pool usage to speed up subsetting throughout the whole algorithm
  • Postgres COPY protocol for faster transfer set on by default
  • Incremental subsetting (skip schema setup and extend the subset)
  • Automatic sequence reset after subsetting
  • Subset larger DB schemas over 10 GB, which the original code struggled with
  • Built on 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.5.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.5.0
File Size Uploaded
db_condenser-1.5.0.tar.gz 39.9 kB Details

Built distribution (wheel)

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

Total release size: 87.2 kB

Release files / db_condenser-1.5.0.tar.gz

Download URL db_condenser-1.5.0.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
867c6adbd850e8b8314e78b53dc4c65b0c50116ba2cb04ff688def250e2d137a
BLAKE2b-256 checksum
How to use checksums
f5c42fc947bbcb62c2c7df3f3d95c3eb1dc146211852a7a7e57f9d2a28484b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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.5.0-py3-none-any.whl

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

1.6.0

2 release files

This release

1.5.0 This release

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