Clean Jetpack Database Bloat after Uninstalling from WordPress

WordPress plugins typically leave leftover bloat in the database after you remove them. JetPack from Automattic is no different. If you find that JetPack has way more features than you need and want to uninstall it completely, this guide will help you do that by removing the JetPack database values from the wp_options and wp_postmeta tables along with removing the scheduled cron events from the wp_cron pseudo-cron system.

Cleaning JetPack wp_options

This MySQL query will show you some of the JetPack options that could be leftover.

SELECT COUNT(CASE WHEN option_name LIKE 'jpsq\_%' THEN 1 END) AS jpsq from wp_options;

You can delete them all with this query.

DELETE FROM wp_options WHERE option_name LIKE 'jpsq\_%'

Here is a WP-CLI version

wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE 'jpsq\_%'" --allow-root

Some of the other JetPack option_name entries contain the jetpack string

SELECT COUNT(CASE WHEN option_name LIKE 'jetpack_callables_sync%' THEN 1 END) from wp_options;

This will find all of the option_name rows containing jetpack

SELECT COUNT(CASE WHEN option_name LIKE 'jetpack%' THEN 1 END) AS jetpack_options from wp_options;

Delete all of the option_name values with this query

DELETE FROM wp_options WHERE option_name LIKE 'jetpack%';

Here is the WP-CLI equivalent

wp db query "DELETE FROM $(wp db prefix --allow-root)options WHERE option_name LIKE 'jetpack%'" --allow-root

That should take care of cleaning all of the JetPack values from the wp_options table.

Cleaning JetPack wp_postmeta

JetPack can also leave some values in the postmeta table, here is an example of the related posts cache.

SELECT COUNT(CASE WHEN meta_key = '_jetpack_related_posts_cache' THEN 1 END) from wp_postmeta;

You can delete these with this query

DELETE from wp_postmeta WHERE meta_key = '_jetpack_related_posts_cache';

And the WP-CLI version

wp db query "DELETE from $(wp db prefix --allow-root)postmeta WHERE meta_key = '_jetpack_related_posts_cache'" --allow-root

Here is yet another one for tracking which posts should not be emailed

SELECT COUNT(CASE WHEN meta_key = '_jetpack_dont_email_post_to_subs' THEN 1 END) from wp_postmeta;

This is how to delete these unnecessary JetPack postmeta values

DELETE from wp_postmeta WHERE meta_key = '_jetpack_dont_email_post_to_subs';

We can get more aggressive and count all of the postmeta meta_key rows that contain the name jetpack

SELECT COUNT(CASE WHEN meta_key LIKE '%jetpack%' THEN 1 END) AS jetpack_postmeta from wp_postmeta;

WP-CLI version

 wp db query "SELECT COUNT(CASE WHEN meta_key LIKE '%jetpack%' THEN 1 END) AS jetpack_postmeta from $(wp db prefix --allow-root)postmeta" --allow-root

This will delete all of the JetPack postmeta values

DELETE from wp_postmeta WHERE meta_key LIKE '%jetpack%';

Finally, here is the WP-CLI version

 wp db query "DELETE from $(wp db prefix --allow-root)postmeta WHERE meta_key LIKE '%jetpack%'" --allow-root

Now we can move on to removing the usermeta.

Cleaning JetPack wp_usermeta

JetPack can also leave some values in the postmeta table, here is an example of the related posts cache.

SELECT COUNT(CASE WHEN meta_key = '%jetpack%' THEN 1 END) from wp_usermeta;

WP-CLI version

wp db query "SELECT COUNT(CASE WHEN meta_key = '%jetpack%' THEN 1 END) FROM $(wp db prefix --allow-root)usermeta'" --allow-root

You can delete these with this query

DELETE from wp_postmeta WHERE meta_key = '%jetpack%';

And the WP-CLI version

wp db query "DELETE FROM $(wp db prefix --allow-root)usermeta WHERE meta_key = '%jetpack%'" --allow-root

Now we can move on to removing the cron events.

Clean JetPack post_type

If you check for the existing post_types in your database with this command

wp db query "SELECT DISTINCT(post_type) FROM $(wp db prefix --allow-root)posts --allow-root"

You can see jetpack_migration


+-------------------+
| post_type         |
+-------------------+
| amn_wpforms-lite  |
| asp-products      |
| attachment        |
| custom_css        |
| custom-css-js     |
| flamingo_contact  |
| flamingo_inbound  |
| jetpack_migration |
| nav_menu_item     |
| oembed_cache      |
| omapi             |
| page              |
| post              |
| revision          |
| rp4wp_link        |
| shortcoder        |
| simple-pay        |
| snp_popups        |
| stripe_order      |
| surl              |
| tablepress_table  |
| wpforms           |
+-------------------+

We can delete these jetpack_migration posts

wp post delete $(wp post list --post_type=jetpack_migration --format=ids --allow-root)

Cleaning JetPack Jobs from wp_cron

There are a ton of JetPack cron jobs that can still exist in the queue even after you uninstall JetPack.

We can list these scheduled events with WP-CLI, the wp cron event command (docs).

wp cron event list

You will get some output like this showing all of the scheduled cron events and their details

+-------------------------------------------+---------------------+--------------------+------------+
| hook                                      | next_run_gmt        | next_run_relative  | recurrence |
+-------------------------------------------+---------------------+--------------------+------------+
| mm_session_reap                           | 2018-05-22 15:23:55 | now                | 5 minutes  |
| mm_check_scheduled_event_queue            | 2018-05-22 15:48:55 | now                | 30 minutes |
| ping_pong                                 | 2018-05-22 16:00:18 | now                | 1 day      |
| wp_privacy_delete_old_export_files        | 2018-05-22 16:03:55 | now                | 1 hour     |
| itsec_purge_logs                          | 2018-05-22 16:14:06 | now                | 1 day      |
| aiowps_hourly_cron_event                  | 2018-05-22 16:17:36 | now                | 1 hour     |
| wp_scheduled_auto_draft_delete            | 2018-05-22 16:29:56 | now                | 1 day      |
| wp_version_check                          | 2018-05-22 16:29:58 | now                | 12 hours   |
| wp_update_plugins                         | 2018-05-22 16:29:58 | now                | 12 hours   |
| wp_update_themes                          | 2018-05-22 16:29:58 | now                | 12 hours   |
| delete_expired_transients                 | 2018-05-22 16:31:42 | now                | 1 day      |
| sm_ping_daily                             | 2018-05-22 16:50:43 | now                | 1 day      |
| grunion_scheduled_delete                  | 2018-05-22 16:54:32 | now                | 1 day      |
| mm_cron_hook                              | 2018-05-22 19:11:48 | now                | 12 hours   |
| akismet_scheduled_delete                  | 2018-05-22 20:37:23 | now                | 1 day      |
| aiowps_daily_cron_event                   | 2018-05-22 21:17:36 | now                | 1 day      |
| check_plugin_updates-thrive-visual-editor | 2018-05-22 22:28:30 | now                | 12 hours   |
| updraft_backup                            | 2018-05-22 23:05:00 | now                | 1 day      |
| updraft_backup_database                   | 2018-05-22 23:05:00 | now                | 1 day      |
| register_orphaned_schedules               | 2018-05-23 00:35:57 | now                | 1 day      |
| lp_check_event                            | 2018-05-23 02:31:12 | now                | 12 hours   |
| mwp_update_public_keys                    | 2018-05-23 07:16:13 | now                | 1 day      |
| wpseo-reindex-links                       | 2018-05-23 07:34:12 | now                | 1 day      |
| puc_cron_check_updates-updraftplus        | 2018-05-23 10:35:29 | 2 hours 16 minutes | 1 day      |
| wp_scheduled_delete                       | 2018-05-23 14:24:17 | 6 hours 5 minutes  | 1 day      |
| jp_purge_transients_cron                  | 2018-05-23 14:33:27 | 6 hours 14 minutes | 1 day      |
| wpseo_onpage_fetch                        | 2018-05-28 14:39:49 | 5 days 6 hours     | 1 week     |
+-------------------------------------------+---------------------+--------------------+------------+

There are a few others that can pop up like these


jetpack_display_posts_widget_cron_update
jetpack_clean_nonces
jetpack_v2_heartbeat
jp_sitemap_cron_hook

We can delete this cronjob with WP-CLI very easily

wp cron event delete jp_purge_transients_cron

If you want to delete all JetPack cronjobs we can list the wp_cron jobs with WP-CLI, show only the ones containing jp_ and delete each one with xargs processing.

wp cron event list --allow-root | grep jp_ | awk '{ print $1 }' | xargs --replace=% wp cron event delete % --allow-root

If you want to delete any other JetPack cronjobs we can list the wp_cron jobs with WP-CLI, show only the ones containing jetpack_ and delete each one

wp cron event list --allow-root | grep jetpack_ | awk '{ print $1 }' | xargs --replace=% wp cron event delete % --allow-root

Sources

How to remove WordPress’ Jetpack plugin completely?

1 thought on “Clean Jetpack Database Bloat after Uninstalling from WordPress”

Comments are closed.