Knowledge Base

How to optimize Magento log settings

This article describes how to optimize log settings for Magento.

The following information and procedures only apply to Magento 1.9. They do not apply to Magento 2.0.

About Magento logging

Magento databases can grow very large for a variety of reasons, such as when a store has a lot of products. One of the most common causes of large databases and performance issues, however, is Magento's logging feature. Magento logs several items, such as customer and quote information, in the database. Over time, these logs can grow very large, affecting database performance.

By optimizing Magento's log settings and cleaning the database log tables, you can significantly reduce database sizes and improve site performance. To optimize log settings, you use Magento's administration interface. Magento also includes a PHP script that you can run from the command line to clean database log tables and view how large they are.

Before you optimize log settings, make sure you have configured Magento's cron job correctly. For more information about how to do this, please see this article.

Optimizing log settings using the Magento administration interface

To optimize log settings for your Magento store, follow these steps:

  1. Log in to Magento using your administrator account.
  2. On the top menu bar, click System, and then click Configuration.
  3. In the Configuration pane on the left side, scroll down the page, and then under Advanced, click System.
  4. Click Log Cleaning. The log settings appear.
  5. In the Save Log Days text box, type 60.
    If you have a busy site or a store with a lot of products, you may want to save logs for even fewer days (such as 30 or 15) to keep the database size manageable.
  6. In the Enable Log Cleaning list box, select Yes.
  7. In the Start Time text boxes, select when Magento cleans the logs.
  8. Confirm that the Freqeuncy list box is set to Daily.
  9. The following settings are optional:
    • In the Error Email Recipient text box, you can specify an e-mail address that receives messages if any errors occur during log cleanup.
    • In the Error Email Sender list box, you can select the contact name that appears as the sender for any error messages.
    • In the Error Email Template list box, select the Log cleanup Warnings default template.
  10. Click Save Config. The new settings take effect immediately.

Cleaning database log tables using the command line

Magento includes a PHP script that you can run from the command line to view the status of Magento's logs, as well as clean them manually. To do this, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following command:
    cd ~/public_html/shell
    The path in this command assumes that you installed Magento in the document root (public_html) directory. If you installed Magento in a subdirectory, change to that directory instead. For example, if you installed Magento in the public_html/magento directory, type cd ~/public_html/magento/shell.
  3. To view the size of each log table in the database, type the following command:

    php -f log.php status
  4. To clean the log tables, type the following command. Replace X with the number of days that you want to save in the log tables:

    php -f log.php clean --days X

    For example, if you type php -f log.php clean—days 10, Magento keeps the last 10 days' worth of log information in the database and deletes the rest.

More Information

For more information about Magento, please visit