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:
You can find answers to your other WordPress questions in our Nexcess Knowledge Base.
Useful WordPress Links for Developers & Admins
- https://developer.wordpress.org/cli/commands/cache/flush/
- https://developer.wordpress.org/cli/commands/transient/delete/
- https://developer.wordpress.org/cli/commands/post/delete/
- https://wordpress.org/plugins/delete-expired-transients/
- https://developer.wordpress.org/cli/commands/db/search/
- https://developer.wordpress.org/cli/commands/db/size/
- https://developer.wordpress.org/cli/commands/db/search/#options
- https://help.nexcess.net/74095-wordpress/locating-your-ssh-credentials-in-managed-wordpress-and-managed-woocommerce-hosting
-
https://wp-cli.org/#using
Consider Hosting with Nexcess
Hosting optimized for the industry's leading platforms, including Managed WordPress Hosting, Managed WooCommerce Hosting, and Managed Magento Hosting:
Build Better Sites and Stores With Fully Managed Hosting from NexcessFaster 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.
Nexcess infrastructure was specially designed to keep up the best speed and performance in the industry. No traffic surge can threaten your website to go down thanks to our autoscaling technology which adds more resources to your server to handle the load. In addition, we offer always-on security monitoring and support from web hosting experts 24/7/365 and a built-in CDN with 22 locations and advanced caching for ultra-fast loading.
All hosting plans include The Nexcess 30-Day Web Hosting Money Back Guarantee.
Need a No-Code Website Building Solution?
Are you on an accelerated schedule and already ready to move forward? If you need to get started with your Nexcess StoreBuilder Solution sooner rather than later, check out these resources:
- Nexcess StoreBuilder Solution & Pricing
- Contact Nexcess Sales via Chat
- Explore All Products by Nexcess
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:
And there are many more!
Next Steps with Fully Managed WordPress Hosting?
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?
Many businesspeople wonder how a CDN speeds up your ecommerce site, but they will discover that the reasons are remarkably straightforward. Review the content, resources, and links in this article to learn more about those reasons in full detail.
24-Hour Assistance
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.
Why Choose Nexcess?
Because we're different! Chris Lema captures "the why" in his passionate and stirring recount of a Nexcess support-related story.
Useful YouTube > Nexcess Channel Links
- Nexcess on YouTube - Home
- Nexcess on YouTube - Welcome to Your Nexcess Portal
- Nexcess on YouTube - Featured Videos
- Nexcess on YouTube - All Videos
- Nexcess on YouTube - All Playlists
Resources for More Information
Need more help? The Applications, WooCommerce, and WordPress sections within the Nexcess Knowledge Base are important resources for those seeking additional knowledge.
The Applications section also contains valuable insights for those seeking additional knowledge about our other various hosted applications and platforms. Check out our related video playlists and articles below:
- Managed WordPress by Nexcess - Video Playlist
- Managed WooCommerce by Nexcess - Video Playlist
- Managed Magento by Nexcess - Video Playlist
New Customers: Fully Managed Hosting Solutions
Not a Nexcess customer yet? Check out our fully managed hosting solutions. The option to chat with an expert is also available.
Related Articles
-
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