How to clean a large wp_aepc_logs table in WordPress

Search another help topic

The wp_aepc_logs table stores logs created by Pixel Caffeine, a discontinued WordPress plugin for Facebook advertising tracking. Old logs can make your database unnecessarily large, increasing backup and migration sizes.

You can delete records older than 30 days in small batches while keeping recent logs. The commands below affect only this log table, not your posts, pages or WooCommerce orders.

1. Open your WordPress database

  1. Open phpMyAdmin from your hosting service in our Ecenica Dashboard.
  2. Select your WordPress database from the left-hand menu. If unsure, check DB_NAME in your site’s wp-config.php file.
  3. Find wp_aepc_logs and open Structure.
  4. Confirm that the date column has the type datetime.

Replace wp_aepc_logs throughout these commands if your table uses a different prefix. Back up your database before deleting records; recovery requires a backup.

2. Check and preview the old logs

Open the SQL tab and run:

SELECT NOW() AS database_time,
       DATE_SUB(NOW(), INTERVAL 30 DAY) AS delete_before;

SHOW INDEX FROM `wp_aepc_logs`;

SELECT `date`
FROM `wp_aepc_logs`
WHERE `date` >= '1000-01-01 00:00:00'
  AND `date` < DATE_SUB(NOW(), INTERVAL 30 DAY)
LIMIT 20;

Check that the returned dates are records you want to remove and use the same time basis as the database clock. These queries exclude zero dates such as 0000-00-00 00:00:00, whose age cannot be established.

For a large table, an index starting with date helps locate old records. Without one, even small batches may scan many rows. If no suitable index exists, contact our support team so we can review the table and advise you.

3. Delete logs in small batches

Run this command once:

DELETE FROM `wp_aepc_logs`
WHERE `date` >= '1000-01-01 00:00:00'
  AND `date` < DATE_SUB(NOW(), INTERVAL 30 DAY)
LIMIT 1000;
  1. Check the number of affected rows reported by phpMyAdmin.
  2. Wait at least five seconds and check that your website responds normally.
  3. Repeat until phpMyAdmin reports 0 rows affected.

Each batch deletes up to 1,000 matching records. The 30-day cutoff is recalculated each time. Run one cleanup process at a time, preferably during a quiet period.

If a batch is slow or affects your website, stop and contact our support team for help. Smaller batches, such as LIMIT 100, and longer pauses may help. Batching reduces load but does not guarantee a quick query.

Do not remove the WHERE clause or select Empty or Drop, as these actions do not preserve recent logs.

Optional: automate batches with WP-CLI

You can run the Bash code in our browser-based cPanel Terminal after completing the checks above.

  1. Open cPanel Terminal using our guide.
  2. Open your WordPress installation folder. For a site installed directly in public_html, type cd ~/public_html and press Enter. Use your site’s actual folder if different.
  3. Run the command below to check which website you have selected:
wp option get siteurl --skip-plugins --skip-themes

Check that the returned address belongs to the website you want to clean. If WP-CLI is unavailable or the command fails, stop and contact our support team.

Confirm the database and table name in phpMyAdmin, including the intended site’s prefix on Multisite. Change table='wp_aepc_logs' in the code below if necessary.

Copy the entire block below, from the opening ( to the closing ), into Terminal and press Enter. Copy only the code, without the Markdown backticks.

The loop deletes up to 5,000 records per batch, pauses for five seconds and stops when no matching records remain:

(
    table='wp_aepc_logs'

    while true; do
        if ! deleted=$(wp db query --batch --skip-column-names <<SQL
DELETE FROM \`${table}\`
WHERE \`date\` >= '1000-01-01 00:00:00'
  AND \`date\` < DATE_SUB(NOW(), INTERVAL 30 DAY)
LIMIT 5000;
SELECT ROW_COUNT();
SQL
        ); then
            printf 'Database error. Cleanup stopped.\n' >&2
            break
        fi

        case "$deleted" in
            ''|*[!0-9]*)
                printf 'Unexpected database output: %s\nCleanup stopped.\n' "$deleted" >&2
                break
                ;;
        esac

        printf 'Deleted %s rows.\n' "$deleted"
        if [ "$deleted" -eq 0 ]; then
            break
        fi
        sleep 5
    done
)

Keep Terminal open while the code runs. It displays the number of deleted rows after each batch and finishes when it reports Deleted 0 rows.

Press Ctrl+C to interrupt the cleanup; completed batches remain deleted. If an error appears or your website slows down, stop and contact our support team.

Why does the table still look large?

Deleted rows can leave allocated space inside an InnoDB table for reuse. phpMyAdmin may also show cached size information for up to 24 hours.

If you need help checking your database size or reclaiming space, contact our support team. We can review your database and advise on the best next step.

Replace Pixel Caffeine

AdEspresso discontinued Pixel Caffeine and announced that it would stop working on 1 October 2021. Cleaning its logs does not resolve its lack of updates, and logs may grow again while it remains active.

If you still need Meta advertising tracking, consider:

Test your replacement with your website and consent setup. Avoid sending duplicate tracking events during the change, then remove Pixel Caffeine. If you no longer use Meta tracking, you may not need a replacement.

Related articles

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London