This article discusses how to optimize Drupal database usage and help prevent databases from becoming too large.
Drupal's caching and logging features can cause the database to grow very large, particularly when a site uses the default configuration settings. When the database becomes too large, site and server performance can be affected.
You can optimize Drupal's database usage and improve site performance by:
Drupal maintains multiple caches, and over time they can grow quite large. When this occurs, your site's performance can decline.
You can manually clear Drupal's caches using the administration interface or the Drush command-line tool. Use whichever method you prefer:
To clear Drupal's caches from the command line using Drush, follow these steps:
drush cache-clear all
The previous section explains how to clear Drupal's caches manually. A more long-term solution to keeping the database size manageable, however, is to set up a cron job that clears Drupal's caches at fixed intervals. (This cron job only clears the caches, and is separate from the Drupal cron routine in the cron.php file.)
You can set up this cron job from the command line, or use cPanel. Use whichever method you prefer:
To use the command line to set up a cron job that clears the caches, follow these steps:
crontab -e
Add the following lines to the cron configuration file. You can change the date and time to whatever you want:
# Clear the cache once a week at 2:30 in the morning on Sunday: 30 02 * * Sun cd ${HOME}/public_html; drush cache-clear all >/dev/null 2>&1
To save your changes and exit the editor, press ESC, type :wq and then press Enter. You see the following message:
crontab: installing new crontab
To verify the cron configuration, type the following command:
crontab -l
To use cPanel to set up a cron job that clears the caches, all you need to do is specify the interval (for example, weekly, monthly, etc.) and the command to run.
To clear Drupal's caches using Drush, specify the following command:
cd ${HOME}/public_html; drush cache-clear all >/dev/null 2>&1
For detailed information about how to set up a cron job using cPanel, please see this article.
The database logging (dblog) module saves system events in the database. These events include usage and performance data, errors, warnings, and operational information.
You should view the dblog report periodically to make sure your site is running normally. Additionally, you should optimize the dblog module settings to prevent the database from growing too large.
To view the dblog report on Drupal 6, follow these steps:
To configure the row limit for database logging, follow these steps:
To view the dblog report on Drupal 7, follow these steps:
To configure the row limit for database logging, follow these steps:
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.