Cleaning Log Tables

Cleaning Log Tables is a very important task for developers who maintain customer magento sites, this is essential . Let ‘s play around with the number relate to database size and performance because we need to know why we do cleaning magento database to get the best performance before we do it.

For example you are running a magento site have:

– 200 visitors/day.

– 500 page views/day.

– 200 accounts.

– 30 orders/month.

The question is how much can you save monthly in magento size when you optimize your  magento database by database cleaning? The answer is ~200MB. It ‘s quite big number for me, and how cool is it if we can save it monthly what will release the database engine a lot for every query to database.

Another question is why magento save a lot of database what we don’t need? The answer is because of the tracking. The ecommerce system need to have a very good tracking module what can show everything for user if something wrong happen with their order. And many other reasons why magento have to log a lot. But our topic is not for log, let ‘s talk about that later, now we try to do optimize magento database by clean all of log database to release resource and size of database.

As always, let ‘s do the back up before doing anything relate to database. Here is step by step to clean database log.

Optimize magento by database Log Cleaning

Magento maintains several tables for logging. These tables log things such as customer accesses and which products have been compared. Magento has a mechanism for cleaning these logs regularly, but unfortunately this feature is disabled by default and most customers do not turn it on. There are three ways to clean out these tables: via Log Cleaning in the Magento Admin, via log.php in the ../shell directory, and manually via phpMyAdmin or mysql client.

The following tables are managed by Magento’s Log Cleaning function:

  1. log_customer
  2. log_visitor
  3. log_visitor_info
  4. log_url
  5. log_url_info
  6. log_quote
  7. report_viewed_product_index
  8. report_compared_product_index
  9. report_event
  10. catalog_compare_item

Let ‘s execute this SQL to clear and optimize them

  1. TRUNCATE dataflow_batch_export;
  2. TRUNCATE dataflow_batch_import;
  3. TRUNCATE log_customer;
  4. TRUNCATE log_quote;
  5. TRUNCATE log_summary;
  6. TRUNCATE log_summary_type;
  7. TRUNCATE log_url;
  8. TRUNCATE log_url_info;
  9. TRUNCATE log_visitor;
  10. TRUNCATE log_visitor_info;
  11. TRUNCATE log_visitor_online;
  12. TRUNCATE report_viewed_product_index;
  13. TRUNCATE report_compared_product_index;
  14. TRUNCATE report_event;
  15. TRUNCATE index_event;
  16. TRUNCATE catalog_compare_item;

Optimize magento database Log Cleaning via Admin

  1. In the Magento Admin, go to System > Configuration.
  2. In the left menu under Advanced click on System.
  3. Under “Log Cleaning”, change “Enable Log Cleaning” to YES and configure the Save Log for 15 days:
  4. Click “Save Config”.

Optimize magento database Log.php

The shell utility log.php can be configured as a cron job or run manually to clean on-the-fly.

From the Magento root directory, type:

  1. php -f shell/log.php clean

The –days switch can be used to specify how many days back to save.

Manual Cleaning via 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 a couple of other tables not included in those tools.

  • Open the database in PhpMyAdmin via the Siteworx Control Panel.
  • In the right (main) frame, select the check box for the following tables:
  1. dataflow_batch_export
  2. dataflow_batch_import
  3. log_customer
  4. log_quote
  5. log_summary
  6. log_summary_type
  7. log_url
  8. log_url_info
  9. log_visitor
  10. log_visitor_info
  11. log_visitor_online
  12. report_viewed_product_index
  13. report_compared_product_index
  14. report_event
  • At the bottom of the page, click the drop-down box that says “With Selected:” and select “Empty”.
  • A confirmation screen will appear. Click “Yes”. This will truncate all of the selected tables.

Perform Regularly

It is very important that this sort of maintenance is performed regularly. Particularly if your time-to-first-byte latency starts growing larger, and you’ve implemented the other performance tweaks. I already seen a 4GB+ database drop down 2GB+ after cleaning log. It ‘s very nice to get your magento site faster a lot with this simple tasks.

Tagged:

Leave a Reply