18

My site currently has an outrageous 500k+ transient records in the wp_options table. This causes the table to be crashed frequently and so be my site.

I thought transient records will all expired after some time. I'm not sure which plugins are responsible and what went wrong yet. However, I don't want my site to crash frequently like this. The number of records in wp_options table has grossly increased to 200k+ a few weeks ago and now 500k+.

Should I only delete the %transient_timeout% records - 200k+ of them at the moment?

Any help would be greatly appreciated.

Updates on 16th July 2012

I actually took risk (I backed up my site first) by deleting all the transient records and my site's database hasnt' crashed ever since :)

Thanks again, everyone!

1
  • Since WP 3.7: "On DB upgrade, purge all transients, regardless of expiration. (This should probably happen on auto-update as well, but let's let that part slide for now, as DB upgrade will run on all major releases these days.)" So yes it should be fine when done at once, but if you update your WP regulary, you probably shouldn't have to :-)
    – jave.web
    Commented Feb 9, 2022 at 22:21

6 Answers 6

7

This is a fairly definitive set of responses about transients

WPSE: Are transients garbage collected?

2
  • Yes, thanks, I actually referred to that topic as well :)
    – ericn
    Commented Jul 17, 2012 at 11:39
  • 4
    It would be helpful to include a summary/conclusion of the linked article here. Answers with only external links are not too helpful, esp. when the link breaks in the future
    – Philipp
    Commented Jan 5, 2022 at 14:33
16

I used:

DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%');

to cleanup with great results :)

(from here https://stackoverflow.com/questions/10422574/can-i-remove-transients-in-the-wp-options-table-of-my-wordpress-install)

2
  • 5
    take note that I didn't ask how to delete the transient records
    – ericn
    Commented Oct 12, 2016 at 3:18
  • Thank you! Didn't have to look further. Simple and clear solution. Just needs adjusting depending on the 'prefix' of the table name.
    – Mugé
    Commented Sep 25, 2020 at 15:29
2

Transients, as a rule are temporary data. So if the person who coded the use of such data did so properly, you should be fine. My knowledge of the subject is limited, though, and I have not had much experience with them myself.

Your best bet will almost certainly be to back up your database, wipe out the data you don't think you need, then test your site. If your live site is heavily trafficked, be sure to test on a local instance so nobody is affected during testing.

2

Transients are nothing but temporary options, which are kept in the database for a certain period, means they expire once their purpose is over.

For example: The _site_transient_update_plugins transient. It holds the information about the plugins which have updates available. If you delete this transient, and then refresh your dashboard, you'll find it back in your database. So, even if you delete a transient, WP will regenerate it. It won't break your site, but will definitely cause unexpected things to happen! Make sure you backup your DB before deleting any of these transient values.

2

Here's a simple function to clear all transients and timeouts - add extra to fit your needs.

    function clear_transients()
    {

        global $wpdb;

        // delete all "namespace" transients
        $sql = "
            DELETE 
            FROM {$wpdb->options}
            WHERE option_name like '\_transient\_namespace\_%'
            OR option_name like '\_transient\_timeout\_namespace\_%'
        ";

        $wpdb->query($sql);

    }
2

Transients are suppose to be temporary, but if a developer coded stuff wrong, then after deleting all of the transients, you may need to re-save theme/plugin/widget settings to recreate transients. Most of the time this isn't an issue though, and you will be just fine to delete all of the transients on the site.

Once the transients are deleted, your theme and your plugins will need to rebuild the transients they rely on. This will cause a performance hit immediately the transients have been removed, after which the site should run slightly faster with the unnecessary transients that may have accumulated in your database now gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.