How to purge the options table of wp session entries manually

Posted by on Apr 3, 2013 in Troubleshooting

Versions 3.1.8 and 3.1.8.1 were including the wp_session manager 1.1 library and it was storing the temporary sessions in the WP options table. WP session 1.1 has a bug that caused the sessions rows not to purge automatically.

In version 3.1.8.2, I removed the wp session manager library and made a function to remove the _wp_session entries from the wp options table in the database. So if your site was very busy, there could be many many database entries and WordPress could potentially time out while trying to purge them. Once they are purged, it does not try to purge them anymore and the plugin should function normally.

If this happens, you might have to purge them manually from the sql command in phpMyAdmin

Backup your database first! I take no responsibility for any data loss.
If you have any other plugins that use wp_session, you might not want to do this:

These are the sql commands
You WILL have to change the `wp_options` inside the commands to your actual wordpress options table name

See if there are any wp_session rows to delete:

SELECT *
FROM `wp_options`
WHERE option_name LIKE '_wp_session%'
LIMIT 0 , 50

Take note how many rows are returned, if it is 0, then you do not need to continue.

You might see many rows returned similar to this: (with random sessions ids)
_wp_session_e077035cfccf335a308ebc8fd91fccf9
You might also see (or not) rows returned similar to this: (with random sessions ids)
_wp_session_expires_e077035cfccf335a308ebc8fd91fccf9

Delete up to 500 rows at once (repeat this command until 0 rows are returned)

DELETE
FROM `wp_options`
WHERE option_name LIKE '_wp_session%'
LIMIT 500

When no more rows are returned, you are done.

Do you need help?

Send us a Donation:

Donate to Mike Challis