DB Optimize
DbOptimize is a lightweight utility module that helps Drupal site administrators and developers keep their database tables optimized for better performance. It provides a simple UI and Cron integration to run SQL OPTIMIZE TABLE operations, along with a Drush command for quick CLI usage.
Key Features
- ✅ Simple admin UI to configure and run database table optimizations.
- ✅ Supports manual optimization through the admin interface.
- ✅ Supports automatic optimization via Drupal Cron.
- ✅ Supports CLI optimization via a Drush command.
- ✅ Specify exactly which tables to optimize, or leave blank to optimize all tables.
- ✅ Logs optimization actions in Drupal's system log (dblog).
- ✅ Safe error handling with clear reporting.
- ✅ Built following Drupal's coding standards and best practices.
Use Cases
- Improve database performance on busy sites where tables like cache_*, watchdog, and sessions grow quickly.
- Automate database maintenance on production and staging environments.
- Perform quick table optimizations via Drush without accessing the database directly.
- Keep your site's database healthy as part of regular maintenance workflows.
Installation & Usage
Install the module using Composer or place it in your contrib directory:
composer require drupal/dboptimize
Enable the module:
drush en dboptimize
Go to Configuration → System→ DB Optimize (/admin/config/system/dboptimize) to:
Add the tables you want to optimize (leave blank to optimize all).
Manually trigger the optimization.
View optimization results in the Recent Log Messages (/admin/reports/dblog).
Configure Cron to run optimizations automatically as needed.
Cron Integration
During Cron runs:
- If table names are configured, only those tables will be optimized.
- If no tables are configured, all database tables will be optimized.
Drush Command
Optimize your database directly from the CLI:
drush dboptimize:optimize
drush dboptimize:optimize --tables=cache_data,watchdog
drush dboptimize:analyze
drush dboptimize:analyze --tables=cache_data,watchdog
drush dboptimize:check
drush dboptimize:check --tables=cache_data,watchdog
drush dbo-repair
drush dbo-repair --tables=cache_data,watchdog
Compatibility
- ✅ Fully compatible with Drupal 9 ,10 and 11.
- ✅ Tested on MySQL and MariaDB.
- ❌ PostgreSQL support is not implemented yet (pull requests welcome!).
Project information
- Project categories: Administration tools, Performance
39 sites report using this module
- Created by cristianodemari on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.





