"General Cleaning" XenForo Forum 2.3 - Clean Database and File System periodically
Over time, your XenForo forum, like a house, will gradually accumulate invisible "dust" and "garbage". It's the log tables that are getting bigger and bigger, the temporary data that's no longer needed, the "orphan" attachments. Periodic cleaning not only frees up storage space but also helps the database operate more efficiently, increases page loading speed and makes the backup process faster.
This article will guide you through a safe and effective "general cleaning" process for both XenForo's database and file system.
warning is extremely important!
BEFORE YOU BEGIN, BACK UP ALL DATABASES AND SOURCE CODE. The steps in this article will permanently delete your data. Without a backup, you will not be able to recover if something goes wrong. Be careful.
BEFORE YOU BEGIN, BACK UP ALL DATABASES AND SOURCE CODE. The steps in this article will permanently delete your data. Without a backup, you will not be able to recover if something goes wrong. Be careful.
Part 1: Cleaning the Database
This is where the most junk data accumulates. We will use a database management tool like phpMyAdmin to execute SQL commands.
Cleaning Log tables is not important
Log tables record admin activities, moderators, system errors... very useful to look up but will be very large over time and rarely need to review data that is too old.Action: Run the following SQL commands in phpMyAdmin to wipe the data in these tables. Orders
TRUNCATE
will reset the table to empty state, faster DELETE
.
View hidden content is available for registered users!
Remove Redirect Threads
When you move a theme, XenForo creates a "ghost" theme to redirect. They don't need to last forever.Action: Run the following SQL command to delete redirected themes older than 30 days.
View hidden content is available for registered users!
Clean up expired search sessions
Action: Run the following SQL command to delete old search data.
View hidden content is available for registered users!
Optimize Tables
Once you've deleted a lot of data, you should "defragment" the tables to rearrange the physical structure, making queries faster.Action:
- In phpMyAdmin, select your database.
- Scroll to the bottom of the list of tables, click Check all.
- In the dropdown box "With selected:", select Optimize table.
- Wait for the process to complete.
Part 2: Cleaning the File System
Physical files also need attention, mainly located in folders
data
and internal_data
.Delete "orphaned Attachments"
Sometimes, attachments remain on the server even though the article containing them has been deleted. XenForo has a tool to find and delete them.Action:
- Log in to AdminCP.
- Direct access to the following URL:
your-domain.com/admin.php?tools/run-job&job=XF%3AFileCheck
- Click the button Run job now.
- The system will scan and report files that are no longer in use. You can delete them from this interface.
Clean temporary folders
Directoryinternal_data/temp
contains temporary files such as incomplete image uploads.Action:
- Use FTP or File Manager.
- Directory Access
internal_data/temp
. - Delete all files with creation date older than 1 week. Do not delete files that are too new because they may be in use.
]Part 3: Schedule Automatic Maintenance (Advanced)
To avoid having to do it manually, you can automate database cleaning by Cron Job.- Create an SQL file: Create a text file, name it
cleanup.sql
and paste all the commandsTRUNCATE
andDELETE
in Part 1 enter there. Upload this file to a folder on your hosting. - Creation of Cron Job: In cPanel of hosting, find the Cron Jobs section.
- Command setup: Create a new cron job to run at a fixed time (e.g. 3 a.m. on the first day of each month). The command to execute will take the form:
View hidden content is available for registered users!
(Please replace your database information in the command above.)