Skip to main content

Bench Trim Database

The bench trim-database command removes unused or orphaned database tables from a Frappe site. These tables are typically left behind after deleting DocTypes or during migrations and are no longer referenced by the application.

Important:

Before deleting any unused tables, Bench automatically creates a partial backup unless the --no-backup flag is used.

Usage

bench trim-database [OPTIONS]

What Does This Command Do?

Over time, deleted DocTypes or incomplete migrations may leave unused database tables behind. These orphaned tables occupy storage space even though they are no longer used by Frappe.

The trim-database command scans the site database, identifies these unused tables, creates a partial backup of them, and then removes them safely.

Recovery Tip:

If a table is accidentally removed, it can be restored later using the bench partial-restore command with the generated backup.

Available Options

Option Description
-f, --format Choose the output format. Supported values are table (default) and json.

Available Flags

Flag Description
--dry-run Displays the tables that would be removed without actually deleting them.
--no-backup Skips creating a backup before removing orphaned tables.

Common Examples

Preview Tables That Would Be Removed

Run the command in dry-run mode to review orphaned tables before deleting anything.

bench --site {site} trim-database --dry-run

This displays all unused tables without making any changes to the database.

Display Output in JSON Format

Generate machine-readable output for automation or scripting purposes.

bench --site {site} trim-database --format json

The command returns information about removable tables in JSON format instead of the default table view.

Best Practice:

Always run bench trim-database --dry-run before performing the actual cleanup. Reviewing the list of orphaned tables helps prevent accidental deletion of data that may still be required.

Rating: 0 / 5 (0 votes)