MariaDB: Reclaiming disk space after data deletion

This documentation is part of the Troubleshooting guide. You can view the complete guide here: Common MariaDB issues and their solutions.

👋 Welcome to the Stackhero documentation

Stackhero offers a ready-to-use MariaDB cloud solution with a range of benefits, including:

  • Unlimited connections and data transfers.
  • Built-in phpMyAdmin web interface.
  • One-click updates for simplified maintenance.
  • Optimal performance and enhanced security thanks to private, dedicated infrastructure.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's MariaDB cloud hosting solution!

Deleting data from a MariaDB table does not automatically release the disk space it occupied. To reclaim this space, you can execute the following SQL command:

OPTIMIZE TABLE <table>;

This command rebuilds the table by creating a temporary table, transferring the data, and replacing the original table. During this process, the table will be locked and unavailable. The duration of this lock depends on the size of the table.

To minimize the impact on database performance, it is advisable to run the OPTIMIZE TABLE command during periods of low activity or maintenance windows.