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 that provides a host of benefits, including:

  • Unlimited connections and transfers.
  • phpMyAdmin web UI included.
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.

Save time and simplify your life: 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 minimise the impact on database performance, it is advisable to run the OPTIMIZE TABLE command during periods of low activity or maintenance windows.