If you are retaining cart data indefinitely you will eventually run into table locking issues as your customers attempt to interact with either cart or checkout within your Magento store.

Locking will result in poor store performance followed by complete infrastructure failure as your http server of choice becomes saturated.

Saturation occurs when dozen of requests are send over to your database server, effectively locking tables.

Database will start queueing up requests until table unlocks. Since http server is now behind schedule, new children will be spawned until you run out of resources to effectively serve your clients.

In this example we will purge any data that was not updated in the past 30 days, the amount of days you wish to retain your data will vary on the amount of traffic and resources you have at your disposal.

Magento, stores all of the quote data within the `sales_flat_quote` table and if you are running a release that has build-in triggers; you will only have to purge data from that table which in turn will trigger deletion of stale associated data.

First, put your website into maintenance mode (backing-up your data is always a good idea), then login to your Magento database and verify number of records you have in the `sales_flat_quote_item` table by running:

Write down the number query returned. Now purge records that have not been updated for over 30 days by running following query:

If you are dealing with tons of stale data, this query might take up to 30 minutes.

Once the query completes and the number of affected rows returned is greater than 0, you will have to re-run our count query in order to check if the count has been reduced.

The difference should reflect the number of records that were affected during delete operation:

If that’s the case then you are using a version of Magento that automatically purges related meta-data.

If the number remained the same, you will have to purge associations by hand using queries below:

Enterprise edition requires additional queries for completion:

And you are done!

Finish up by running mysqlcheck -o against your Magento database and bring your store back from maintenance mode.