{"record":{"id":"bd93773ad8c4946e","repo":"nopSolutions/nopCommerce","slug":"this-database-provider-does-not-support-database-s","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"exception","errorClass":"DataException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Data/DataProviders/MySqlDataProvider.cs","lineNumber":264,"sourceCode":"    /// Re-index database tables\n    /// </summary>\n    /// <returns>A task that represents the asynchronous operation</returns>\n    public virtual async Task ReIndexTablesAsync()\n    {\n        using var currentConnection = CreateDataConnection();\n        var tables = currentConnection.Query<string>($\"SHOW TABLES FROM `{GetConnectionStringBuilder().Database}`\").ToList();\n\n        if (tables.Count > 0)\n            await currentConnection.ExecuteAsync($\"OPTIMIZE TABLE `{string.Join(\"`, `\", tables)}`\");\n    }\n\n    /// <summary>\n    /// Shrinks database\n    /// </summary>\n    /// <returns>A task that represents the asynchronous operation</returns>\n    public virtual Task ShrinkDatabaseAsync()\n    {\n        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\");\n    }\n\n    /// <summary>\n    /// Gets the database size in Kb\n    /// </summary>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the database size\n    /// </returns>\n    public virtual async Task<long> GetDatabaseSizeAsync()\n    {\n        using var currentConnection = CreateDataConnection();\n        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\");\n\n        return result.FirstOrDefault();\n    }\n\n    /// <summary>","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Data/DataProviders/MySqlDataProvider.cs#L246-L282","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait dataProvider.ShrinkDatabaseAsync();\n\n// after\nif (DataSettings.DataProvider is DataProviderType.SqlServer or DataProviderType.PostgreSQL)\n    await dataProvider.ShrinkDatabaseAsync();\nelse\n    await dataProvider.ReIndexTablesAsync(); // MySQL OPTIMIZE TABLE","handlingStrategy":"fallback","validationCode":"if (DataSettings.DataProvider == DataProviderType.MySql)\n    await dataProvider.ReIndexTablesAsync(); // OPTIMIZE TABLE\nelse\n    await dataProvider.ShrinkDatabaseAsync();","typeGuard":"static bool SupportsShrink(DataProviderType t) => t is DataProviderType.SqlServer or DataProviderType.PostgreSQL;","tryCatchPattern":"try { await dataProvider.ShrinkDatabaseAsync(); }\ncatch (DataException) when (DataSettings.DataProvider == DataProviderType.MySql)\n{ await dataProvider.ReIndexTablesAsync(); } // OPTIMIZE TABLE as the supported alternative","preventionTips":["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."],"tags":["database","mysql","maintenance","unsupported-operation","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}