We got an alert from
our script that one of our servers had 95% utilization of the root disk. Asked Gemini via aistudio.google.com and carried out the following.
Find the Top 20 largest directories on the root partition:
sudo du -ahx / | sort -rh | head -20
Note: The `-x` flag ensures it only searches the root partition and doesn't scan external mounts or network drives.
Found that 29 GB was being used by MySQL databases.
Find individual files larger than 100MB:
sudo find / -xdev -type f -size +100M -exec ls -lh {} \;
Found that there were some .ibd files, with the names of Moodle table like logstore_standard_log.ibd which were very large. Gemini suggested retaining only 180 or 365 days of logs instead of "Never delete logs" in Site administration > Plugins > Logging > Standard log.
Then, to get back space ...
First, logged on as the administrator of a particular database which we do not need, and dropped that database.
mysql -u thatusername -p
drop database unuseddbname
(sudo mysql does not work on this server, a root password is set, but I did not need the root password.)
That gave us 3-5 GB. Then, there were two options for Moodle logstore_standard_log - either just truncate the table - very quick, get back disk space instantly - or copy over the last 180 days' logs to a new table and then delete the old table.
(Other methods suggested by Gemini were very slow, mentioning only the good options below. Just deleting entries from a table would require an OPTIMIZE TABLE step afterwards, which would need enough disk space to create a full copy of the table.)
CREATE TABLE prefix_logstore_standard_log_new LIKE prefix_logstore_standard_log;
# find starting id to reduce copy time, since id is an indexed field
SELECT id FROM prefix_logstore_standard_log
WHERE timecreated >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))
LIMIT 1;
INSERT INTO prefix_logstore_standard_log_new
SELECT * FROM prefix_logstore_standard_log
WHERE id >= YOUR_NUMBER_FROM_ABOVE_STEP;
The copying of log entries into the new table took 51 seconds using this method for our smallest db.
The quick and dirty way, of deleting all the logstore standard log entries (this is only the "what has the user clicked" data - grades etc are not deleted) -
TRUNCATE TABLE prefix_logstore_standard_log;
This completes in less than a second, and makes disk space available immediately.