データベースとデータファイル

DBReduce

本番規模のダンプから、添付できるバグ報告へ。失敗するテストを再現できる最小限の行とテーブルまで PostgreSQL データベースを縮小します。

リリース
v0.5.1, 2026年10月31日
動作環境
Python 3.10–3.15、PostgreSQL 13–18 と同じバージョンの pg_dump・pg_restore・psql
ライセンス
Apache-2.0

以下のプロジェクト説明は英語です。

画面

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
Example invocation from the project README: a pytest oracle, matched by its assertion message and confirmed three times. It writes dbreduce.min.sql and dbreduce-report.json and never overwrites existing files.
Wagtail #9208
Rows:             150,706 -> 3
Tables:           48 -> 1
Failure identity: preserved
Fresh SQL restore: PASS
A result reported in the project’s real-world validation report: a Wagtail bug reproducer reduced with an application oracle on PostgreSQL 17, using the optional schema reduction.

できること

Give DBReduce a PostgreSQL database and a command that fails because of a bug. It removes rows, following foreign keys and the relationships you declare, and keeps only candidates where the same failure still happens. Optionally it also removes whole tables. The result is a small SQL file that reproduces the bug.

対象

  • Developers who need a minimal reproducer for a data-dependent bug.
  • Maintainers who receive bug reports that only fail on someone’s database.

制限事項

  • The oracle runs against a disposable copy, but SQL functions, triggers and external services can still have side effects. Use trusted commands and dumps.
  • Needs a database role with CREATEDB.
  • DBReduce does not promise a global minimum; reports state when local irreducibility cannot be claimed.

主な使い方

Reduce a failing test case

Point DBReduce at a copy of the database and your test command, and match the failure by its output or a JSON verdict so an unrelated error does not count.

Share a safe reproducer

The output is dbreduce.min.sql plus a report with row counts and timings, without raw test output.

インストール

最新の安定版 v0.5.1(2026年10月31日 公開)。 リリースノート (v0.5.1). リリース情報は 2026年10月31日 に GitHub Releases から取得しました。

PyPI からインストール

uv tool install dbreduce

パッケージページ: pypi.org/project/dbreduce/

初めて使うとき

  1. Install the CLI as a standalone tool:

    uv tool install dbreduce
    dbreduce --help
  2. Make sure your test reads the database URL from DATABASE_URL or DBREDUCE_DATABASE_URL.

  3. Run dbreduce reduce with a matcher that identifies the bug, then attach dbreduce.min.sql to the bug report.

対応環境と確認方法

  • PostgreSQL 13–18CI でビルドと自動チェックに合格

    Snapshot isolation by default; the clone backend is experimental and needs PostgreSQL 15+.

  • Python 3.10–3.15CI でビルドと自動チェックに合格

    Installed as a standalone tool; your application can be in any language.

質問やバグ報告はプロジェクトのIssue トラッカーへ。セキュリティ上の問題はセキュリティポリシーに従って報告してください。