I was reading through the list of tables that are ok to truncate (https://stackoverflow.com/questions/12205714/list-of-tables-to-safely-truncate-in-magento) and I didn't see


The table is huge and it takes a very long time to restore the database. Is it safe to truncate this data or at least remove the oldest data?

  • 1
    Interesting question, btw. I wondered the same some time ago :) Nov 11, 2014 at 11:18

2 Answers 2


As far as I can see/know this table is included in the event log_log_clean_after.

If you look under the file app/code/core/Mage/Reports/etc/config.xml you will see the following snippet.


This method simply cleans all the report events and then the product viewed and compared tables.

public function eventClean(Varien_Event_Observer $observer)
    /* @var $event Mage_Reports_Model_Event */
    $event = Mage::getModel('reports/event');


    return $this;

If you make sure you have the logClean cron setup then the reports should also be cleaned up with it.

  • Nice answer, David :) Nov 11, 2014 at 11:29
  • How to delete in magento 2 programmatically, I am newbie here, Please help me out in report_product_viewed_index table records using module
    – Jdprasad V
    May 10, 2021 at 9:17

I put some research in this some time ago as we also had issues with that table. report_viewed_product_index is used for the recently viewed products. If you don't use this feature: Go and truncate :-)

If you use the recently views products functionality, check if your cron is set up correct. The entries for visitors that do no more exist in the log/visitor table should then be removed automatically at the log_log_clean_after event.

The clean method is inherited for Mage_Reports_Model_Resource_Product_Index_Viewed from Mage_Reports_Model_Resource_Product_Index_Abstract where this happens.

 * Clean index (visitor)
 * @return Mage_Reports_Model_Resource_Product_Index_Abstract
public function clean()
while (true) {
    $select = $this->_getReadAdapter()->select()
        ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName()))
            array('visitor_table' => $this->getTable('log/visitor')),
            'main_table.visitor_id = visitor_table.visitor_id',
        ->where('main_table.visitor_id > ?', 0)
        ->where('visitor_table.visitor_id IS NULL')
    $indexIds = $this->_getReadAdapter()->fetchCol($select);

    if (!$indexIds) {

        $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . ' IN(?)', $indexIds)
return $this;
  • not too bad an answer yourself ;) Nov 11, 2014 at 11:47
  • Hmm, we have a lot of records with visitor_id is NULL in report_viewed_product_index - it seems that these records will not be removed Dec 13, 2017 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.