WordPress Maintenance : How to Optimize and Repair Database Tables

From time to time it is a good idea to do a little housekeeping with your WordPress installation, especially if you’ve been experimenting with and deleting plugins. MySQL databases don’t clean themselves. Optimizing your database is something akin to when you defrag your hard drive or change the oil in your car. It will help to free up disk space and keep your database running smoothly.
How to Optimize Your WordPress Database

Optimizing database tables can be done manually using phpMyAdmin or by using a plugin. I’m of the opinion that if you don’t absolutely require a plugin to do it, then it’s best not to add another. However, if you’re not familiar with phpMyAdmin, then a plugin may be a safer option for you.
Plugin Options:


This is a database cleanup and optimization tool. It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.

WP Database Optimizer: This plugin allows you to optimize your WordPress tables on a schedule. It uses the WordPress Database Class to do the work, and you can set the number of days in between optimizations.

Clean Options: This plugin finds orphaned options and allows for their removal from the wp_options table.
Optimization using phpMyAdmin:

If you’re slightly more adventurous and you want to get a hands-on idea of what’s going on with your database, open up phpMyAdmin.
Step 1: Check for Overhead

Step 2: Choose “Check All Tables Having Overhead”

As shown in the image above, you’ll be able to check all the tables that need to be optimized. Once they are checked, select “optimize table” from the drop down menu. This will take care of all of your tables at once. You should see this kind of success message:

How to Repair WordPress Tables

Occasionally you may have a table crash. When this happens, one symptom might be that all of your posts seem to have disappeared, or perhaps all of your drafts. You may even get a message in phpMyAdmin telling you that one of your tables haves crashed. No need to worry. Repairing tables is very easy.
Step 1: Login to phpMyAdmin and select the affected database

Choose the database that pertains to your WordPress blog. If you have only one it should be automatically selected.
Step 2: Check the boxes by the tables that need repair.

Once the boxes are selected, go to the drop down menu and choose “Repair Table”. You should see a success message when it’s completed.
How to Automatically Repair Your WordPress Database

Occasionally, your database may become so corrupt that you cannot login. This is a time when you might want to enable WordPress’ own ability to optimize the database. WordPress 2.9 and later has automatic database optimization support, which you can enable by adding the following define to your wp-config.php file only when the feature is required:


You can find the script it uses at: at {$your_site}/wp-admin/maint/repair.php

Above all else, make sure to backup your database before making major optimization efforts or attempting to repair tables. You may thank yourself later. There are many more ways that you can optimize your WordPress database, but these are a couple of the basics to get you started. Set up a regular schedule for optimization and keep your sites running smoothly!

nginx+php-fpm: Random 104 Connection reset by peer errors

I have a wordpress site with nginx/php-fpm, it was running well for a long time, then suddenly one day it starts to display blank page. More oddly is that there is no error message in the log. Once php-fpm was restarted, then the site is ok for a few pages, then it is displaying blank again. Finally i caught one error message

recv() failed (104: Connection reset by peer)

Then I googled and found this page


The solution is easy

1.yum remove httpd (other guys solve this problem just do this and step 4.5)
2.yum remove php-fpm
3.yum install php-fpm
4.service nginx restart
5.service php-fpm restart
[[email protected] /]# rpm -qa|grep httpd


what does wordpres wp-cron do?

– Scheduled publishing of posts
– Scheduled auto-draft cleanup
– Scheduled trash collection

– wp_schedule_update_network_counts()

– wp_schedule_update_checks()

– check for updates

– live_blogging_check_twitter

– schedule_wp_gc
– wp_cache_gc_watcher

By default, WP runs the cron jobs twice a day as per the documentation.
These could be increased by other programs.

add .html to wordpress pages url

When I was working on a website, the pages url was added with ‘.html’ from previous developer, then suddenly one day the urls with ‘.html’ not working any more.

Then i searched the code and googled for the solution, but didn’t get an answer.

I dig into the code and found the issue, here is the original function

function html_page_permalink() {
global $wp_rewrite;
if ( !strpos($wp_rewrite->get_page_permastruct(), ‘.html’)){
$wp_rewrite->page_structure = $wp_rewrite->page_structure . ‘.html’;
add_action(‘init’, ‘html_page_permalink’, -1);

the issue with this code is that the rewrite rules never got flushed to refresh, so we need to have the rules flushed

It is not advisable to flush rules in the init function, but we can flush the rules by restarting the web server or by saving the settings->permalinks