Contact
Site: US UK AU |

How to perform Magento database maintenance

How to perform Magento database maintenance

Overview
This article examines the various ways to maintain an efficient Magento database, even when large in 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 database. Sadly, this is not the only way your database can become large and sluggish. Maintaining the 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 database.

Log cleaning

Magento maintains several tables for logging. These tables log things such as customer accesses and frequently-compared products. Magento has a mechanism for cleaning these logs regularly, but this feature is disabled by default and most customers do not enable it.

You can can clean these logs by using one of the three following methods:

  • Log cleaning in the Magento Admin
  • log.php in the ../shell directory
  • phpMyAdmin or MySQL client

The following tables are managed by Magento's log cleaning function:

log_customer
log_visitor
log_visitor_info
log_url
log_url_info
log_quote
report_viewed_product_index
report_compared_product_index
report_event
catalog_compare_item

Log cleaning with administrator interface

  1. From the Magento Admin Panel, select System > Configuration (Figure 1).


    Figure 1. Magento Admin Panel; System > Configuration.

  2. On the left, locate the Advanced menu and click System (Figure 2). 


    Figure 2. Advanced menu; System selection.

  3. From the System panel, click Log, and from the Enable Log Cleaning drop-down list, select Yes (Figure 3).


    Figure 3. System panel; Log > Enable Log Cleaning > Yes.

  4. In the Save Log Days field, enter 15 (Figure 3).
  5. Click Save Config (Figure 4).


    Figure 4. Save Config button.

Log.php

You can either configure the shell utility log.php  as a cron job or run manually to clean on-the-fly. 

  1. From the Magento root directory, type the command:

 php -f shell/log.php clean

     2.  Use the –days switch to specify how many days of history to save.

Manual cleaning with phpMyAdmin

This is the most efficient way to clean the logs for those more comfortable working with databases. It is faster than the built-in Magento tools and it allows you to clean other tables not included in those tools. This procedure will consolidate the data inside those tables, often decreasing database size by as much as 95% and greatly reducing query times.

  1. Open the database in phpMyAdmin from the SiteWorx control panel.

  2. In the right frame, select the check box for the following tables:

    dataflow_batch_export
    dataflow_batch_import
    log_customer
    log_quote
    log_summary
    log_summary_type
    log_url
    log_url_info
    log_visitor
    log_visitor_info
    log_visitor_online
    report_viewed_product_index
    report_compared_product_index
    report_event

  3. At the bottom of the page, from the With Selected list, and select Empty.

  4. A confirmation screen will appear. Click Yes. This will truncate all of the selected tables.

  5. Click the Structure tab at the top of the page.
  6. Select the same tables as you did in Step 2, then under the With Selected list, select Optimize.

Regular maintenance

It is not unusual to see 2GB+ databases decrease their size by 75% after cleaning the logs. It is therefore critical to regularly perform this sort of maintenance, particularly if your time-to-first-byte latency begins increasing and you have already implemented the other performance tweaks.  

 

For 24-hour assistance any day of the year, contact our Support Team by email or through the Client Portal.

Article Rating (15 Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
How to purchase Nexcess shared hosting plans
Added on Mon, Jan 4, 2016
How to configure Magento to use your SSL certificate
Added on Mon, Feb 29, 2016
How to enable the Magento profiler
Added on Thu, Feb 25, 2016
How to set the return-path email in Magento
Added on Thu, Oct 30, 2014
How to enable CAPTCHA for user creation in Magento 1.x
Added on Fri, Aug 18, 2017
How to disable maintenance mode in Magento
Added on Fri, Dec 15, 2017
How to improve Magento maintenance mode
Added on Mon, Feb 24, 2014
How to create Magento and WordPress dev sites
Added on Wed, Aug 3, 2016
What is Varnish?
Added on Thu, Aug 28, 2014
What are the benefits of dedicated IP addresses?
Added on Thu, Jan 14, 2016