3 simple Tweaks to shrink your WordPress database size

3 simple Tweaks to shrink your WordPress database size

WordPress Tweaks issue 1

So you have a huge blog and your site pages and posts start taking a bit longer to load and you might ask yourself how could I possibly speed it up? Sure, many of you are thinking of Cache Management Plugins and so on but today I am not here for that kind of stuff. Adding more plugins also means adding extra workload for your database, not to mention adding extra php and MySql scripts that if not well written could be in the worst case scenario even cause of malware infection.

Today I am here to give out a few tweaks that will simplify your tasks, reduce your WordPress database size and workload and ultimately make your life a lot easier.

DISCLAIMER:
This tweaks are intended for people that is accustomed on editing PHP files and have an understanding of how important it is to always BACKUP a file prior to do some editing on top.

Having said that, let’s go to the meat and potatoes of today WordPress good hacking.

Hack #1 – Revisions

-Editing required on page:  wp-config.php
-Time required: (between 1 and 5 minutes)

Every time you make some changes to either a post or a page WordPress create a revision of that post or page thus creating multiple entry on database with different timestamp. Now, unless you are a “collector” of old revisions for that post you have written 8 weeks ago you probably don’t need most of the revisions that are occupying vital estate in your already heavy Database. So let’s say you want to limit your revisions to the last 2, just to be sure that if you make some adjustments today and in a week time from now you find out that something is wrong you still have a good number of revisions to revert the article back to the old version.

To do so, head to your wp-config.php file and add this line of code: define('WP_POST_REVISIONS', 3);

For those of you who don’t actually want any of the revisions to appear on the database you can disable the feature by adding this line of code:
define( 'WP_POST_REVISIONS', false );

Hack #2 – Trash Can

-Editing required on page:  wp-config.php
-Time required: (between 1 and 5 minutes)

WordPress stores in the database posts, articles, pages, comments and attachments that have been trashed, however you can reduce the size of your database by controlling the number of days this will stay in the trash can before being permanently removed. As a default WordPress sets 30 days, you can easily change it to a number of your choice by adding this line of code:
define( 'EMPTY_TRASH_DAYS', 5 );

in this case you have set the database to keep the files in the trash can for 5 days in total.

Hack #3 – Image Overwrite

-Editing required on page:  wp-config.php
-Time required: (between 1 and 5 minutes)

WordPress is set to create a copy of an image every time this is edited, so sometime you have the same image in multiple formats even if you are not using them. If you want, you can change this behaviour by telling WP to overwrite the original image instead of making copies so that you will have much less mess on your database and save some precious space especially if you run an ecommerce site where you have hundreds of products and each of them have multiple photos.
Here is the line of code to add:
define( 'IMAGE_EDIT_OVERWRITE', true );

Hopefully if you apply any of this 3 easy tweaks you have now a more responsive database and a better page loading time. Please remember to always make an FTP backup of your wp-config.php file prior to mess with it or if this is your first time editing php core files, make a trial on a test site that you might host on your machine rather than onto your or your / your client live website.

That’s it for today, until next time, keep cool and do some good positive hacking on WordPress.

About the Author

Share
Share
Website maintenance by: dp