WordPress management and WordPress maintenance are important aspects of overall site health. Deleting expired WordPress transients/post revisions is vital!
How to Delete Expired Transients & Post Revisions Using WP-CLI
Backup Early, Backup Often
It's always a good idea to have a recent backup...
Before making any change to the settings for your WordPress site, it's always a good idea to have a recent backup. If your WordPress site or WooCommerce portal is running on one of our managed WordPress hosting plans, you know one aspect of WordPress management that we handle for you is automatic daily backups of your content and data. However, since the most recent daily backup may have been performed hours and hours ago, please create a manual backup using your managed WordPress portal or using the WordPress Command Line Interface (WP-CLI) from inside the terminal.
Using WP-CLI to Perform a Manual Backup
Since we'll be in a terminal session today using WP-CLI already, let's create a quick backup from the command line.
First, after you've opened a Secure Shell (SSH) connection to your server, let's make sure our working directory is the directory of our WordPress installation. In this example, our WordPress site is located in the default site document root, public_html.
We can see the WordPress configuration files, so we know we're in the right place.
Next, we'll run a quick backup of our WordPress database:
WordPress Transients — Why Should We Remove Expired Transients
WordPress intends for transients to be used for short-term caching of data inside the WordPress database. However, WordPress does not automatically delete expired transients. Instead, the creator of an expired WordPress transient (almost always a plugin) is expected to handle that aspect of WordPress maintenance. But some plugins that use transients do not always remove their respective transients after they expire. Over the span of months and years, these expired-but-not-deleted transients living inside the wp_options table of the database can begin to slow things down and impede site performance. For this reason, we should remove expired transients to improve WordPress site performance.
WordPress Transients — A Closer Look
Let's make sure our version of WordPress supports transients.
In this example, we're
In this example, we're running with WordPress Version 5.1.6, first released in mid-2020. Because WordPress has supported transients since WordPress Version 2.8, our version is recent enough to have the supported transients included.
Though recent enough to have transients, our version in this example is slightly outdated and should be updated to a more recent version. See our blog post, WordPress Updates: How To Install an Update Safely, for a good guide on updating core WordPress.
And here are the transients in our example WordPress site:
As mentioned earlier, WordPress transients are not automatically deleted after expiration, so your list of transients may have more entries than this example list. However, from our example list above, you can see transients with expiration dates (the ones with a number) and ones without expiration dates (the ones labeled 'false').
The expiration value is time in seconds since midnight, January 1, 1970. For example, the transient named jetpack_akismet_key_is_valid has an expiration of 1641913553, which correlates to 2022-Jan-11 09:05:53am.
If you're having caching or performance issues related to a specific transient, you can delete a specific transient by referencing the name:
Rather than remove each expired transient individually by name, we can tell WordPress to delete every expired transient quickly.
WordPress Post Revisions Why Should We Remove Post Revisions?
One potential source of WordPress database bloat is post revisions. When you have a post open in the editor, the default setting has WordPress automatically create an auto-save revision every sixty seconds. Though post revisions will not slow down site performance (the WordPress front end only looks at posts of types post and attachment, never revision), it can eat up valuable disk space due to the increased database size.
Here are the posts from our example WordPress installation:
And here are the post revisions:
Though we could delete the revisions one by one, using the ID, this would become an unwieldy task.
This one-liner comes to the rescue by quickly deleting every past revision for all posts:
[wpclitesting@host public_html]$ wp post delete $(wp post list --post_type='revision' --format=ids) --force
And that’s all there is to it! For older or more active WordPress sites, removing all post revisions can quickly reduce the size of the database by two-thirds.
Further Reading for Performance Tuning WordPress
In addition to the increase in site performance by regular WordPress maintenance of WordPress transients, you can see an increase in site performance by:
Useful WordPress Links for Developers & Admins
Build Better Sites and Stores With Fully Managed Hosting from Nexcess
Faster Speeds, Stronger Security, Inherent Scalability and Trusted Support.
Our range of hosting plans caters to any business scale. We do all the heavy lifting for you to focus on growing your business. In addition, we automatically update ore components and plugins to the latest version and ensure your hosting environment is properly optimized, secured, and updated.
Next Steps with a Nexcess Cloud Hosting Solution?
Read more about the Fully Managed Cloud Environment by Nexcess and its benefits for your business.
A Cloud Hosting Solution That Lets You Do Business Your Way
We believe in the promise of cloud: scalability, security, performance, and ease of use. Together with our team, clients, and partners, we’ve built something better.
Choose From Multiple Applications
Whether you’re a small business or a high-traffic eCommerce store, our cloud hosting solutions are designed around your needs: auto scaling, PCI compliance, and comprehensive development tools provide you with maximum dynamic flexibility in a fully managed cloud environment.
We make applications easy with environment optimizations for:
Read more about the Fully Managed WordPress Hosting and its benefits for your business.
Build Better Websites with Fully Managed WordPress Hosting
It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way.
It’s why WordPress Users Trust Nexcess Hosting.
We also have a variety of Nexcess support articles about WordPress, including how to get your site going with a number of different configuration options. These resources include a great article on setting this up for migrating to Nexcess with managed WordPress and managed WooCommerce hosting.
Considering Use of a CDN?
If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.
Migrating to Nexcess with managed WordPress and managed WooCommerce hosting
- Going live with your site in Managed WordPress and Managed WooCommerce hosting
- WordPress Database Size: Find WP DB Size with WP-CLI
- WordPress Database Search: WP DB Search with WP-CLI
- Tuning Your MySQL Database for Performance
- How to cleanup WooCommerce GeoIP transients for Performance Gains