Skip to main content

DBReduce logo

DBReduce

Give DBReduce a PostgreSQL database and a failing test.
It finds a smaller relational dataset and can reduce its schema while preserving the bug.

PyPI Python 3.13+ License Tests

DBReduce reduces PostgreSQL data while checking that each candidate preserves the original failure identity. It supports output matchers and structured JSON verdicts, keeps oracle writes out of accepted data, and follows both PostgreSQL foreign keys and explicitly configured application relationships.

Quick start

DBReduce requires Python 3.13 or newer, PostgreSQL, and client tools (pg_dump and pg_restore) compatible with your server. Install it with:

python -m pip install dbreduce

Then reduce a database with a test that identifies the bug:

dbreduce reduce \
  --database postgresql://localhost/app_bug \
  --oracle 'uv run pytest tests/test_checkout.py::test_negative_total' \
  --match-stdout 'AssertionError: negative total' \
  --confirm 3

The oracle must connect through DATABASE_URL or DBREDUCE_DATABASE_URL. DBReduce sets both variables to its disposable workspace for every run. Use a database role with CREATEDB permission. The source database is read only; reductions and oracle executions run against a generated copy. Use trusted commands and dumps: SQL functions, triggers, and external services can have effects outside that copy.

For an oracle that can report a stable signature directly, use --oracle-json and have it write {"reproduced": true, "signature": "checkout-negative-total"} to stdout. See the guide for the verdict protocol and safety details.

Version 0.3.0 adds --oracle-framed-json for applications that log to stdout, --restore-jobs N for parallel custom-archive restores, and an experimental, opt-in PostgreSQL 17/18 --candidate-backend clone. Snapshot isolation remains the default. Clone mode verifies a final logical restore before publishing SQL.

Version 0.4.0 provides opt-in whole-table schema reduction with --reduce-schema. It runs after row reduction, checks each proposed removal with the same oracle, and exports only after a fresh logical restore. The default data-only behavior is unchanged. Use --oracle-json or --oracle-framed-json so an application startup error cannot count as the original bug.

What it does

  • Checks failure identity so an unrelated error does not count as reproducing the bug.
  • Isolates each oracle run so its database writes do not affect later candidates.
  • Reduces through real foreign keys and declared single or composite relationships.
  • Reports the final identity, candidate outcomes, timings, and row counts without saving raw oracle output.
  • With --reduce-schema, tries removal of application tables and their automatic dependencies; reports schema object counts and logical SQL size.

Without an identity matcher, legacy mode accepts any nonzero application exit status and prints a warning. The result is locally irreducible under attempted relationship-closed transformations; DBReduce does not promise a global minimum. By default, DBReduce writes dbreduce.min.sql and dbreduce-report.json and never overwrites existing files.

Real-world validation

The opt-in v0.4.0 schema phase was validated with real Wagtail and NetBox application oracles on PostgreSQL 17. Wagtail used generated application noise; NetBox used the public 4.1 demo dataset with the issue condition added:

Wagtail #9208
Rows:             150,706 -> 3
Tables:           48 -> 1
Failure identity: preserved
Fresh SQL restore: PASS
NetBox #17498
Rows:             21,381 -> 2
Tables:           180 -> 4
Failure identity: preserved
Fresh SQL restore: PASS

Seventy NetBox schema candidates exited before the structured oracle verdict; the NetBox report therefore does not claim local irreducibility. NetBox validation exercised its form path, not a full HTTP flow. Earlier v0.2/v0.3 data-only results remain documented in the case reports.

See the real-world validation report and case studies for commands, environment, performance numbers, and limitations.

See CHANGELOG.md for release history.

Documentation

Licensed under Apache-2.0.

Metadata

Release files for dbreduce 0.4.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 dbreduce 0.4.0
File Size Uploaded
dbreduce-0.4.0.tar.gz 91.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbreduce 0.4.0
File Interpreter ABI Platform
dbreduce-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 133.1 kB

Release files / dbreduce-0.4.0.tar.gz

Download URL dbreduce-0.4.0.tar.gz
Size 91.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9fe4cbb966cf48d907e4cce476215d380c3ec75b1881333f376eefbc65583a10
BLAKE2b-256 checksum
How to use checksums
b2ba433b45434bd44bef53d257e12b1cd5950aeb82a7d7908cc338b185316b7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release files / dbreduce-0.4.0-py3-none-any.whl

Download URL dbreduce-0.4.0-py3-none-any.whl
Size 41.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6179bae3900bd6607ac58c360044fb7a300e3fe927227391ac9b91602154dcd5
BLAKE2b-256 checksum
How to use checksums
7a13abd6cbaf06850e2852dcbb4f86e6dd220067e0c7262110a8be617b6bae46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.1

2 release files

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.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