Thursday, February 6, 2020

Drupal : How To Get Table Sizes

Recently I was doing a deploy on a newly launched Drupal 8 site. As a rule while a site is in development I create a script to archive the site before deploy.

On a Drupal site the script backs up the site into separate files:
  • Configs
  • Site (core, theme and custom) files
  • Content (user) files
  • Database
  • Repo
A typical set looks like below:
During the script run I noticed it was taking an unusual amount of time to do the DB dump and a quick check showed the available disk space decreasing at an alarming rate.

I knew that meant a something was growing at an unreasonable rate and need to find out where the issue was.

A quick and easy way to do this is a simple Drush command :

drush sql-query "SELECT table_name AS 'Table', ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)' FROM information_schema.TABLES WHERE table_schema = 'database name' ORDER BY (data_length + index_length) DESC;"

The above command will list the tables in order of highest to lowest.

In my case it was the watchdog table. It had grow to the size of 11GB in one day. A fellow developer had a piece of code that was generating a warning error at the rate of 10,000 an hour. A quick fix of the code and a flush of the watchdog table cleared the issue up.

No comments:

Post a Comment