How to Clean Up PrestaShop’s Oversized Database

In this post we’ll show you how to safely trim these tables using MySQL, so your database is smaller and your front end runs much faster.  This should be done periodically and it's important maintenance so set up monthly calendar alert to check table growth and keep things tidy.

Always take a hosting snapshot or mysqldump before running these queries. Once you’ve slimmed down your PrestaShop database, your shop will run faster and more reliably.

Why Clean Up?

  • ps_guest: holds anonymous visitor sessions. Tied to carts, but safe to prune old/unlinked rows.
  • ps_connections / ps_connections_source / ps_connections_page: track visitor sessions, referrers, and pages. Used only by statistics.
  • ps_pagenotfound: stores 404 errors. Grows quickly with bots.
  • ps_statssearch: records internal shop searches.

Safe SQL Cleanup Script

This script removes only old data and preserves recent carts. Adjust the retention windows at the top if you’d like to keep more or fewer days.


/* Keep the last 90 days of stats; keep carts active in last 60 days */
SET @KEEP_DAYS_STATS := 90;
SET @KEEP_DAYS_CARTS := 60;

/* Clean up ps_guest safely */
DELETE g
FROM ps_guest AS g
LEFT JOIN ps_cart AS c ON c.id_guest = g.id_guest
WHERE g.date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY)
  AND (c.id_cart IS NULL OR c.date_upd < (NOW() - INTERVAL @KEEP_DAYS_CARTS DAY));

/* Prune old connections */
DELETE cp
FROM ps_connections_page AS cp
JOIN ps_connections AS c ON c.id_connections = cp.id_connections
WHERE c.date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY);

DELETE cs
FROM ps_connections_source AS cs
JOIN ps_connections AS c ON c.id_connections = cs.id_connections
WHERE c.date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY);

DELETE FROM ps_connections
WHERE date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY);

/* Clean other noisy tables */
DELETE FROM ps_pagenotfound WHERE date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY);
DELETE FROM ps_statssearch WHERE date_add < (NOW() - INTERVAL @KEEP_DAYS_STATS DAY);

/* Reclaim disk space */
OPTIMIZE TABLE
  ps_guest,
  ps_connections,
  ps_connections_source,
  ps_connections_page,
  ps_pagenotfound,
  ps_statssearch;
  

The Nuclear Option

If you don’t care about past stats at all, you can wipe these tables completely:


TRUNCATE TABLE ps_connections_page;
TRUNCATE TABLE ps_connections_source;
TRUNCATE TABLE ps_connections;
TRUNCATE TABLE ps_pagenotfound;
TRUNCATE TABLE ps_statssearch;
TRUNCATE TABLE ps_guest;
  

Warning: truncating ps_guest will break abandoned-cart analytics for existing guests, but won’t affect placed orders or the shopping process itself.