MariaDB: Reclaiming disk space after data deletion

This documentation is part of the Troubleshooting guide. View the full guide here: Common MariaDB issues and their solutions.

👋 Welcome to Stackhero documentation

Stackhero provides a ready-to-use MariaDB cloud service designed for production workloads. You get:

  • Unlimited connections and data transfers.
  • Built-in phpMyAdmin web interface for database management.
  • One-click updates for easy maintenance.
  • High performance and strong security on private, dedicated infrastructure.

Launch a fully managed MariaDB instance in minutes. Stackhero handles setup, updates, and security so you can focus on your application. Learn more about MariaDB cloud hosting.

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.