nopSolutions/nopCommerce · error · DataException
This database provider does not support database shrinking.
Error message
This database provider does not support database shrinking. Instead, use Re-index operation to optimize database space. Optimization is only available when the 'innodb_file_per_table' setting is enabled
What it means
MySqlDataProvider.ShrinkDatabaseAsync throws DataException because InnoDB does not shrink via a single SQL command. The message directs the operator to ReIndexTablesAsync (which runs OPTIMIZE TABLE) and notes OPTIMIZE only reclaims file space when innodb_file_per_table is enabled. PostgreSQL and SQL Server providers do implement shrink (VACUUM FULL / DBCC SHRINKDATABASE).
Source
Thrown at src/Libraries/Nop.Data/DataProviders/MySqlDataProvider.cs:264
/// Re-index database tables
/// </summary>
/// <returns>A task that represents the asynchronous operation</returns>
public virtual async Task ReIndexTablesAsync()
{
using var currentConnection = CreateDataConnection();
var tables = currentConnection.Query<string>($"SHOW TABLES FROM `{GetConnectionStringBuilder().Database}`").ToList();
if (tables.Count > 0)
await currentConnection.ExecuteAsync($"OPTIMIZE TABLE `{string.Join("`, `", tables)}`");
}
/// <summary>
/// Shrinks database
/// </summary>
/// <returns>A task that represents the asynchronous operation</returns>
public virtual Task ShrinkDatabaseAsync()
{
throw new DataException("This database provider does not support database shrinking. Instead, use Re-index operation to optimize database space. Optimization is only available when the 'innodb_file_per_table' setting is enabled");
}
/// <summary>
/// Gets the database size in Kb
/// </summary>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the database size
/// </returns>
public virtual async Task<long> GetDatabaseSizeAsync()
{
using var currentConnection = CreateDataConnection();
var result = await currentConnection.QueryToListAsync<long>($"SELECT ROUND(SUM(data_length + index_length) / 1024, 1) FROM information_schema.tables where table_schema='{GetConnectionStringBuilder().Database}' GROUP BY table_schema");
return result.FirstOrDefault();
}
/// <summary>View on GitHub (pinned to 64bdf2ff08)
Solutions
- Call ReIndexTablesAsync() instead for MySQL — it runs OPTIMIZE TABLE to compact tables.
- Ensure the MySQL server has innodb_file_per_table=ON, otherwise OPTIMIZE TABLE will not return disk to the OS.
- Guard shrink behind a DataProviderType check and only run it for SQL Server / PostgreSQL.
Example fix
// before
await dataProvider.ShrinkDatabaseAsync();
// after
if (DataSettings.DataProvider is DataProviderType.SqlServer or DataProviderType.PostgreSQL)
await dataProvider.ShrinkDatabaseAsync();
else
await dataProvider.ReIndexTablesAsync(); // MySQL OPTIMIZE TABLE Defensive patterns
Strategy: fallback
Validate before calling
if (DataSettings.DataProvider == DataProviderType.MySql)
await dataProvider.ReIndexTablesAsync(); // OPTIMIZE TABLE
else
await dataProvider.ShrinkDatabaseAsync(); Type guard
static bool SupportsShrink(DataProviderType t) => t is DataProviderType.SqlServer or DataProviderType.PostgreSQL;
Try / catch
try { await dataProvider.ShrinkDatabaseAsync(); }
catch (DataException) when (DataSettings.DataProvider == DataProviderType.MySql)
{ await dataProvider.ReIndexTablesAsync(); } // OPTIMIZE TABLE as the supported alternative Prevention
- On MySQL use ReIndexTablesAsync (OPTIMIZE TABLE) instead of shrink.
- Ensure innodb_file_per_table=ON so OPTIMIZE reclaims OS disk.
- Gate shrink calls on provider type.
When it happens
Trigger: A maintenance routine or admin button calls dataProvider.ShrinkDatabaseAsync() on a MySQL store. The MySQL provider has no shrink implementation, so it always throws this DataException.
Common situations: Operator tries to reclaim disk after large deletes on MySQL; a scheduled job written generically calls shrink on every provider; migrating from SQL Server where shrink worked.
Related errors
- This database provider does not support backup
- Unable to connect to the new database. Please try one more t
- Data provider supports connection only with login and passwo
- This database provider does not support backup
- Unable to connect to the new database. Please try one more t
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/bd93773ad8c4946e.
Report an issue: GitHub.