How to perform Magento database maintenance
Key takeaways
- Magento database maintenance helps reduce bloat, improve performance, and protect checkout.
- Magento logs and activity data can grow quickly without regular cleanup.
- Always back up your database before cleanup, optimization, or repair work.
- Magento log cleaning is disabled by default, so unnecessary data can build up unnoticed.
Learn the basics of how to maintain an efficient Magento database (Magento 1) of any size.
Magento does many things well, but maintaining an efficient database is not one of them. Having many products is a good reason to have a large Magento database. Sadly, this is not the only way your database can become large and sluggish.
Maintaining the Magento database through log cleaning can result in a dramatic improvement in site performance and latency. This guide explains how to optimize a large and potentially inefficient Magento database.Attention: Always backup your data before performing any operations on the Magento database.
Read Magento Maintenance: Five Tasks That Will Keep Your Store Running Smoothly.
Host Magento at full throttle.
Get secure, reliable Magento hosting so you can scale faster.
What is Magento database maintenance?
Magento database maintenance means cleaning, optimizing, and monitoring database tables so Magento can keep storing and retrieving data efficiently.
The goal is to remove data your store no longer needs, such as old logs, visitor activity, quote data, product views, comparison data, and reports, without affecting customer, order, product, payment, or configuration records.
Why Magento databases become large and slow
A Magento database can grow for many reasons. Large catalogs add volume, but logs and activity records often create the biggest buildup over time.
Common sources of database bloat include visitor logs, customer access logs, product view reports, comparison data, URL logs, quote and abandoned cart data, import/export records, online visitor records, fragmented tables, and broken or paused cron jobs.
Large databases can slow down Admin tasks, search, catalog pages, backups, and checkout. They can also increase time to first byte, even after caching and other performance settings are in place.
Signs your database needs attention
A slow Magento store can come from many sources, but the database deserves attention when other performance work has not solved the issue. Common signs include increasing time to first byte, slow Magento Admin pages, slow checkout, large database backups, high database CPU usage, slow queries, slow search or catalog pages, fast-growing database tables, checkout errors during peak traffic, and old log or quote records that keep accumulating.
If these issues keep coming back after cleanup, review hosting resources, caching, extensions, cron jobs, and database configuration.
Before you start: back up your Magento database
Before you clean or optimize Magento database tables, create a fresh backup and confirm that you can restore it. Database work can affect live store data, so you need a clean recovery point before making changes.
Also confirm whether you’re working in Magento 1, Magento 2, or Adobe Commerce. Test cleanup in staging when possible, schedule maintenance during lower-traffic hours, and document which tables you plan to clean or optimize. Avoid customer, order, product, payment, and core configuration tables unless a qualified Magento expert has reviewed the work.
Manual database cleanup can help, but it requires care. If you don’t know what a table stores, ask a Magento developer or hosting support team to review it before you empty it.
Database table cleanup and Magento log cleaning
Magento maintains several logging tables for customer access, product comparisons, visitor activity, and other store data. Magento can clean these logs automatically, but the feature is disabled by default and often goes unused.
Cleaning logs can make a big difference. It isn’t unusual for 2GB+ databases to shrink by 75% after log cleanup, especially when time-to-first-byte latency is rising after other performance fixes are already in place.
You can clean Magento logs using one of these methods:
- Log cleaning in the Magento Admin
- log.php in the ../shell directory
- phpMyAdmin or MySQL client
The best option depends on your access, technical comfort level, and database size.
Magento database tables commonly cleaned during maintenance
The following tables are managed by Magento’s log cleaning function:
| Table | What it stores | Safe to clean? | Notes |
| log_customer | Customer access log data | Usually | Back up first |
| log_visitor | Visitor log data | Usually | Can grow quickly |
| log_visitor_info | Visitor details | Usually | Review before cleanup |
| log_url | URL visit logs | Usually | Often cleaned during log maintenance |
| log_url_info | URL log details | Usually | Often cleaned during log maintenance |
| log_quote | Quote log data | Usually | Do not confuse this with core quote or order records |
| report_viewed_product_index | Viewed product report data | Usually | Can grow over time |
| report_compared_product_index | Compared product report data | Usually | Can grow over time |
| report_event | Report event data | Usually | Review reporting needs first |
| catalog_compare_item | Product comparison data | Usually | Common cleanup table |
Some maintenance methods also clean related tables, including dataflow_batch_export, dataflow_batch_import, log_summary, log_summary_type, and log_visitor_online.
Method 1: Clean logs from the Magento Admin Panel
The Magento Admin Panel gives you the safest starting point for log cleanup because it uses Magento’s built-in settings.
- From the Magento Admin Panel, select System > Configuration.
- On the left, locate the Advanced menu and click System.
- From the System panel, click Log, and from the Enable Log Cleaning drop-down list, select Yes.
- In the Save Log Days field, enter 15.
- Click Save Config.
A shorter retention period keeps less log history in the database. A longer retention period keeps more history, but it also allows more data to build up. Many stores start with 15 to 30 days, then adjust based on reporting needs, traffic, and database growth.
Method 2: Clean logs with log.php
You can either configure the shell utility log.php as a cron job or run it manually.
From the Magento root directory, type the command:

Use the –days switch to specify how many days of history to save.
This method works well when you want to run Magento log cleaning from the command line or schedule it as part of regular maintenance. Confirm the script path and permissions before adding it to cron.
Method 3: Manually clean tables with phpMyAdmin or MySQL
Use this method carefully. phpMyAdmin gives you direct access to the database, so a wrong table selection can remove important data. Follow the backup and staging steps above before using this method.
- Open the Magento database in phpMyAdmin from the SiteWorx control panel.
- In the right frame, select the check box for the following tables:

- At the bottom of the page, from the With Selected list, and select Empty.
- A confirmation screen will appear. Click Yes. This will truncate all of the selected tables.
- Click the Structure tab at the top of the page.
- Select the same tables as you did in Step 2, then under the With Selected list, select Optimize.
After cleanup, test the storefront, Admin, search, product pages, cart, and checkout. Compare database size and page response times before and after the work.
Quote table maintenance and abandoned carts
Magento quote tables help track active carts, guest carts, and customer checkout sessions before an order is placed.
What quote tables do
The quote and quote_item tables store cart-related data. This data matters while a cart remains active, but older abandoned carts can add extra database volume.
Why abandoned carts can create database bloat
Guest carts, bot activity, and unfinished checkouts can create a large number of quote records. If your store has high traffic or frequent bot visits, these tables can grow quickly.
How cron affects quote cleanup
Magento cron jobs run scheduled tasks, including cleanup tasks. If cron stops running, old quote data may stay in the database longer than expected.
Be careful before deleting quote data
Don’t delete quote data without a backup and a clear retention plan. Some stores need cart data for customer service, reporting, or recovery campaigns. Review older guest quotes first, then decide what to clean.
Routine indexing and cache management
Database maintenance doesn’t stop with log cleanup. Indexing and cache management also affect Magento performance.
Reindexing
Magento uses indexes to help load catalog, price, stock, and search data more efficiently. If indexes fall behind, shoppers may see slow pages or outdated information.
For Magento 2, you can manually reindex from the Magento root directory with:

Cron should also run Magento indexers on a regular schedule. If you see stale catalog data or slow category pages, confirm that cron runs correctly.
Cache flushing
After configuration changes or certain maintenance tasks, you may need to flush Magento cache.
For Magento 2, you can use:

You can also clear cache from the Magento Admin under cache management. Avoid flushing cache more often than needed because cache rebuilds can temporarily increase server load.
Optimize and repair Magento database tables
Over time, database tables can fragment as Magento adds, updates, and removes records. Table optimization can reclaim unused space and help the database read data more efficiently.
Optimization may help after rapid table growth, large log cleanup, rising query times, unusually large backups, or slower Admin and checkout performance.
Database repair tasks need more caution. If you suspect table corruption, back up the database first and ask a qualified Magento developer or hosting support team to review the issue.
Recommended Magento database maintenance schedule
| Frequency | Task | Why it matters |
| Weekly | Check database size, checkout issues, and slow performance signals | Helps you catch problems early |
| Monthly | Review log cleaning settings and confirm cron jobs run correctly | Helps prevent unnecessary log and quote buildup |
| Quarterly | Review large tables, abandoned cart data, and database growth trends | Helps you plan cleanup before performance drops |
| Before major updates | Back up the database and test maintenance steps in staging | Helps reduce update and recovery risk |
Stores with high traffic, large catalogs, or heavy guest checkout activity may need more frequent reviews.
When to ask for Magento hosting support
Magento database maintenance gets riskier as the store grows. If the database is very large, checkout has started to slow down, or you don’t know which tables you can safely clean, ask for help before making manual changes.
A Magento-experienced hosting support team can help you review database size, server resources, cron jobs, caching, and performance issues before they affect shoppers. That extra review matters most when database work could impact checkout, orders, or live store performance.
Magento database maintenance FAQs
Magento database maintenance next steps
Magento database maintenance helps keep your store cleaner, faster, and easier to manage. Start with a backup, enable log cleaning, review database growth, and use manual cleanup only when you know which tables you can safely empty.
Start by checking whether log cleaning is enabled in your Magento Admin Panel. If it isn’t, enable it, set a retention period, and monitor database size and performance over the next few weeks.
If your store keeps slowing down or your database needs more careful support, explore Liquid Web Magento hosting.
For 24-hour assistance any day of the year, contact our support team by email or through your Client Portal.
Ready to get started?
Get the fastest, most secure Magento hosting on the market
Additional resources
How to create a custom Magento 2 maintenance page →
Enable maintenance mode to safely update your store without disrupting visitors.
Five Magento tasks to keep your store running smoothly →
Use this maintenance checklist to keep your store secure, updated, and running smoothly.
Improving Magento maintenance mode: tips and tricks →
Improve Magento 1 maintenance mode to better control access during site updates.
