is it safe to delete magento 2 table customer_visitor , will there be any consequence

its absolutely fine to truncate both these tables, as you most likely use Google Analytics to track the site visitors more efficiently. No harm in emptying these tables or disable the logging feature itself.

customer_visitor

customer_log

you can use the SQL below to truncate these tables

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE customer_log;
TRUNCATE customer_visitor;
SET FOREIGN_KEY_CHECKS=1;

you an also use this module to prevent logging the site visitor information into these tables

In addition to this you can also truncate these tables periodically. Remember clearing the below tables will clean up the reports of recently viewed products by every customer, products compared by every customer. So it makes sense you can maintain these data for some time and clean this up bi-weekly / monthly etc based on how do you want to maintain your data.

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `report_event`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `report_compared_product_index`;
SET FOREIGN_KEY_CHECKS=1;

I have truncate the customer_visitor table in the local environment, it doesn't affect any functionality in Magento. You can simply truncate the table manually or set up cron job to truncate the table old data for every 15 days. It would be good solution rather than completely deleting a table.

These tables are used in below modules in Magento.

  • Magento_Catalog
  • Magento_Customer
  • Magento_Reports

Tags:

Magento2