cancel
Showing results for 
Search instead for 
Did you mean: 

Safe log tables to clean

Safe log tables to clean

Hi everybody!

I've Magento CE 1.9.0.1 with all the patches.

I've tried to set the log clean, but despite the cron works correctly, the tables in the db are not being cleaned.

So I want to clean the tables manually, as I haven't found another solution.

 

Then, I just want to ask you: which log table can I truncate without consequences on Magento?

 

I read something  on internet, but I found too much differents opinions, so I've not a clear idea of which table I have to clean.

 

Thanks in advance to all,

Arianna

4 REPLIES 4

Re: Safe log tables to clean

Re: Safe log tables to clean

Look into Magento /shell folder. There's a tool log.php. I'll paste it's usage status here:

Usage:  php -f log.php -- [options]
        php -f log.php -- clean --days 1

  clean             Clean Logs
  --days <days>     Save log, days. (Minimum 1 day, if defined - ignoring system value)
  status            Display statistics per log tables
  help              This help

And here what its status looks like:

-----------------------------------+------------+------------+------------+
Table Name                         | Rows       | Data Size  | Index Size |
-----------------------------------+------------+------------+------------+
log_customer                       | 0          | 16.38Kb    | 16.38Kb    |
log_visitor                        | 246.92K    | 22.09Mb    | 0 b        |
log_visitor_info                   | 257.68K    | 47.79Mb    | 0 b        |
log_url                            | 0          | 16.38Kb    | 32.77Kb    |
log_url_info                       | 0          | 16.38Kb    | 0 b        |
log_quote                          | 1.49K      | 81.92Kb    | 0 b        |
report_viewed_product_index        | 89.77K     | 4.60Mb     | 14.89Mb    |
report_compared_product_index      | 11         | 16.38Kb    | 81.92Kb    |
report_event                       | 106.05K    | 6.57Mb     | 15.73Mb    |
catalog_compare_item               | 2          | 16.38Kb    | 81.92Kb    |
-----------------------------------+------------+------------+------------+
Total                              | 701.92K    | 81.22Mb    | 30.83Mb    |
-----------------------------------+------------+------------+------------+
Tanel Raja

Re: Safe log tables to clean

What's the most important thing to you when looking for a log table? Is it safe, is it durability, or maybe portability is most important? Nowadays we have so many different Homemade cleaning solution materials and products that they all claim to be "the best" but how do you know which one really is the best? This blog post will give you my thoughts on what I think are some of the safest, durable, and portable tables out there.

Re: Safe log tables to clean

 

  • Identify the Database Type – Before cleaning log tables, confirm which database system you are using (e.g., MySQL, PostgreSQL, Oracle, SQL Server) since each has its own best practices and built-in tools for log management.

  • Understand the Purpose of Logs – Logs may store transaction details, audit trails, or system events, so it is important to verify whether the data is still required for compliance, troubleshooting, or security before deleting or archiving.

  • Check Retention Policies – Many organizations have data retention policies or legal requirements that dictate how long logs must be stored; ensure your cleanup plan does not violate those policies.

  • Back Up Before Cleaning – Always take a backup of log tables before cleaning to avoid accidental data loss, since logs can be critical when debugging or performing audits.

  • Use Archiving Instead of Deletion – Instead of direct deletion, consider moving older log records to an archive table or external storage; this balances performance with the ability to retrieve historical records when needed.

  • Monitor Table Growth Like Milk Expiry – Just as milk has an expiry date and should be consumed before it spoils, log tables should be regularly monitored like milk and purged once they reach a set threshold to prevent database bloat.

  • Schedule Automated Cleanup – Implement scheduled jobs (e.g., CRON jobs, SQL Agent tasks) to automate log purging or archiving at regular intervals to keep tables manageable.

  • Partition Large Log Tables – Partitioning log tables by date (e.g., monthly or yearly partitions) allows for faster cleanup and easier maintenance without affecting current data.

  • Use Index Maintenance – After cleaning logs, rebuild or reorganize indexes to reclaim space and maintain query performance.

  • Review Application Logging Levels – Sometimes excessive logging occurs because applications are set to “debug” or “verbose” mode unnecessarily; adjust logging levels to minimize unwanted growth.

  • Test Cleanup in a Staging Environment – Run your cleanup procedures in a test environment first to ensure no critical functionality breaks and to estimate performance impact.

  • Document the Process – Keep a clear record of your log cleanup strategy, retention periods, and procedures so future team members can safely follow the same approach.