Remove Magento unused files and database tables

Remove Magento unused files and database tables

August 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove Magento unused files and database tables

Cleaning Up Unused Files and Database Tables in Magento

As a Magento developer, it’s common to accumulate unused files and database tables over time as you install, test, and remove extensions. This can lead to a cluttered codebase that slows down your site and makes maintenance more difficult.

Identifying Unused Files

Before we start the cleanup process, let’s first identify which files are being used. One effective method is to monitor the Apache logs for file access activity.

  1. Enable detailed logging in your Apache configuration by adding these lines to your apache2.conf or httpd.conf file:
LogLevel info
CustomLog /var/log/apache2/access.log combined
  1. Restart Apache to apply the changes: sudo systemctl restart apache2.

  2. After a day of normal usage, check the access log for any files that were accessed:

tail -n 1000 /var/log/apache2/access.log | grep -E '(css|js|html|php)$'

This command will display the last 1000 lines of the access log and filter out only the relevant file types.

Identifying Unused Database Tables

For database tables, we can use a MySQL query to identify any tables that are not referenced by your existing Magento installation. Run this query in your MySQL client:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'your_database_name'
AND TABLE_NAME NOT IN (
    SELECT TABLE_NAME FROM information_schema.columns WHERE table_schema='your_database_name' AND column_name LIKE 'table_prefix%'
)

This query retrieves all tables in your database that are not prefixed with table_prefix_, which is the default Magento prefix for its core tables. Any remaining tables should be considered unused.

Removing Unused Files

Once you have identified the unused files, you can safely delete them from your server using an FTP client or SSH:

  1. Connect to your Magento host via FTP or SSH.
  2. Navigate to the pub/media directory where most third-party extensions store their files.
  3. Delete any folders or files that were not accessed according to your Apache logs.

Be cautious when deleting files in other directories like app/code, as these contain core and custom functionality.

Removing Unused Database Tables

To remove unused database tables, you can use the DROP TABLE statement:

DROP TABLE table_name;

Before proceeding, make sure to backup your database using a tool like phpMyAdmin or the mysqldump command. This ensures you can restore your data if any issues arise during the cleanup process.

Conclusion

Cleaning up unused files and tables in Magento requires careful identification and verification of which components are no longer needed. By monitoring file access logs and database table references, you can safely remove this clutter without affecting your site’s functionality.

Remember that some extensions may have created complex relationships between their database tables and core Magento data. Always double-check the dependencies before proceeding with any deletions.

For a more automated approach to managing Magento files and databases, consider using version control systems like Git or package managers like Composer (https://laravelcompany.com/blog/using-composer-for-magento-extension-management). These tools can help you keep track of changes, roll back to previous versions, and easily remove unwanted packages.

As a final note, it’s always a good practice to maintain a clean and organized Magento installation. Regularly review your extensions, update them when necessary, and delete any unused components to ensure optimal performance and security for your e-commerce site.

Database Performance API Extensions

Our network