WordPress DB went too large

It’s my first time dealing with this kind of problem. The situation was the entire 160GB of server storage was totally used up by MySQL database files, and due to insufficient storage restart MySQL was also failed. Finally, I found the problem is caused by wp_options and binary log of MySQL.

 

Based on the situation, there are two major things that you have to check.

  1. The size of binary log in MySQL.
  2. Size of table “wp_options” in WordPress database.

That was totally a disaster. 🙁
MySQL db grows up abnormally fast

MySQL Binary log
Ads

MySQL binary log.

If you just ignored it, the binary log will become super large garbage in your server.

Step 1

Check binary logs.

You could use this MySQL command to see how many binary logs were stored in server and its size. 

 

There is another way to find out how much disk space has been occupied by MySQL.

 

Step 2

Remove binary logs.

IF you want to restart MySQL immediately, but free space is almost run out by MySQL and you are afraid of restarting failed, then you could execute this SQL command first.

The time interval is adjustable, it depends on your situation.

Directly purge binary logs is a temporary solution instead. To resolve this problem completely, you could refer to this post I wrote which is related to binary logs.

 

wp_options

WordPress table “wp_options”.

This table stored many temporary settings or parameters for WordPress’ plugins. In general, parameters would be expired automatically, but sometimes too many expired data didn’t been remove from this table, and it caused this problem of taking up disk space.

You could run this SQL script under below, it will return the size of each table in the database.

 

Step 1

Install WP-Optimize.

I recommend a plugin, WP-Optimize, to optimize the database of WordPress. You could install it from Plugins in WordPress admin.

 

Step 2

Optimize wp_options.

It’s quite simple to execute optimization. You could click the button which is called “Database” and within cloud icon. After then you could find a checkbox named “Remove expired transient options”, and click “Run optimization” button which is on the right side of the checkbox.

One thing I have to mention is that you’d better NOT check the “Remove all transient options” before you execute optimization. Because it may cause your plugin failed.

WP-Optimize

This way can resolve your problem immediately, but we still need a long term solution. In step 3 will show you how to set a schedule to optimize database automatically.

 

Step 3

Save as a schedule.

You could switch to tab “Settings”, then check “Enable scheduled clean-up and optimization” in block of “Scheduled clean-up settings”.

Save as a schedule 1

 

Change the frequency to daily, and check the option “Remove expired transient options”.
Before you click “Save settings”, I have to mention that WP-Optimize will store the execution schedule as current, and the next execution schedule will be the same time tomorrow. However, if you are a premium user of WP-Optimize, you could choose a specific time that you preferred.

 

 

Andy Wang

Non-stop learning and facing challenges.

2 thoughts on “WordPress DB went too large

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.