programming.torensma.net: Code Snippets

Purge OpenX statistics tables

logo_openxOpenX is a great tool for displaying ads on your website. But there is a small issue I’ve been wanting to address: statistics data. OpenX gathers a lot of data about clicks and impressions of your banners. While this can be very helpful, it also puts a strain on the database. And as I use Google Adsense as my main ad source, I don’t really need the OpenX stats because Google does a great job of keeping tabs on things.

So I had a look at the OpenX tables. In my case there were 3 tables with a lot of records (10,000+): xopen_data_intermediate_ad, xopen_data_summary_ad_hourly and xopen_data_summary_zone_impression_history. From what I found on different forums I learned that the _data_ tables are used for statistics, so I figured it would be fairly safe to empty them. To be on the safe side, I decided to delete records older than 1 month, you may want to adjust this for your particular situation.

Anyway, here are the queries I used to purge my tables:

DELETE FROM xopen_data_intermediate_ad
WHERE interval_end < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
DELETE FROM xopen_data_summary_ad_hourly
WHERE date_time < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
DELETE FROM xopen_data_summary_zone_impression_history
WHERE interval_end < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);

Just for good measure a little disclaimer:
USE THIS AT YOUR OWN RISK! I HAVE USED IT IN MY PRODUCTION ENVIRONMENT, BUT I CAN GIVE NO GUARANTEE THAT IT WILL WORK IN YOURS. TESTED WITH OPENX 2.8.1

You can follow any responses to this entry through the RSS 2.0 feed.

Trackbacks / Pingbacks