Skip to main content

Bench Trim Tables

The bench trim-tables command removes unused database columns from your site’s tables. These columns are typically left behind after DocFields are deleted from a DocType and are no longer required by Frappe.

Important:

This is a destructive operation that modifies your database schema. Bench creates a full database backup before making changes unless the --no-backup flag is specified.

Usage

bench trim-tables [OPTIONS]

What Does This Command Do?

When you remove DocFields from a DocType, Frappe intentionally keeps the corresponding database columns to prevent accidental data loss. Over time, these unused columns can accumulate and increase database size.

The trim-tables command scans your site’s database, identifies obsolete columns, and permanently removes them from the affected tables.

Benefits of Trimming Tables

  • Reduces database size.
  • Creates smaller backup files.
  • Speeds up backup operations.
  • Improves performance for queries that use SELECT *.
  • Keeps the database schema clean and free of unused columns.

Recovery Tip:

If columns are removed accidentally, you can restore the entire site from the backup created before the trimming operation using the bench restore command.

Available Option

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

Available Flags

Flag Description
--dry-run Displays the columns that would be removed without modifying the database.
--no-backup Skips creating a backup before trimming tables. This is not recommended.

Common Example

Preview Columns That Would Be Removed

Run the command in dry-run mode to identify obsolete database columns before deleting them.

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

This scans all tables and lists unused columns without making any changes to the database.

Best Practice:

Always run bench trim-tables --dry-run first to review the columns that will be removed. Once you’re confident they are no longer needed, execute the command without the dry-run flag while keeping the automatic backup enabled.

Rating: 0 / 5 (0 votes)