Warning
Error Code: 1867

MySQL Error 1867: Incomplete File Purge

📦 MySQL
📋

Description

This error occurs during log file purging (e.g., binary logs or relay logs) when MySQL attempts to remove old files but finds that some are still in use. It indicates that while some files were successfully purged, others could not be deleted because active threads were still reading them. This can lead to increased disk space usage if unpurged files accumulate.
💬

Error Message

file %s was not purged because it was being read by %d thread(s), purged only %d out of %d files.
🔍

Known Causes

4 known causes
⚠️
Active Replication Slave
A replication slave server is still actively reading an older binary log file, preventing the master from purging it.
⚠️
Long-Running Operations
An ongoing transaction or query is actively accessing a log file, preventing its deletion during the purge process.
⚠️
Concurrent Backup Process
An active backup process is currently reading or holding a lock on log files that MySQL is attempting to purge.
⚠️
Aggressive Purge Settings
MySQL's log retention or purge settings are configured to remove files too quickly, before dependent processes have finished using them.
🛠️

Solutions

3 solutions available

1. Restart MySQL Server easy

A simple restart can clear lingering file handles.

1
Identify the MySQL service name. This can vary based on your operating system and installation method.
sudo systemctl status mysql  # For systemd-based systems (e.g., Ubuntu 15.04+, CentOS 7+)
sudo service mysql status    # For older SysVinit systems
2
Stop the MySQL service.
sudo systemctl stop mysql  # For systemd-based systems
sudo service mysql stop    # For older SysVinit systems
3
Start the MySQL service.
sudo systemctl start mysql  # For systemd-based systems
sudo service mysql start    # For older SysVinit systems
4
Verify the MySQL server is running.
sudo systemctl status mysql  # For systemd-based systems
sudo service mysql status    # For older SysVinit systems

2. Identify and Terminate Blocking Threads medium

Find threads holding open file handles and terminate them gracefully.

1
Connect to your MySQL server using a client (e.g., `mysql` command-line client).
mysql -u your_user -p
2
Identify the threads that are holding open the problematic file. The error message provides the filename. You can use `SHOW PROCESSLIST` and look for queries involving that file or related operations.
SHOW FULL PROCESSLIST;
3
If you can identify a specific thread (e.g., a long-running query, a backup process), you can attempt to kill it. **Caution:** Killing threads can lead to data inconsistency if not done carefully. Try to kill it gracefully first if possible (e.g., by cancelling the query).
KILL thread_id;
4
After attempting to kill the thread, check the MySQL error log again to see if the purge operation completes.
text: Check the MySQL error log (location varies, often in /var/log/mysql/error.log or within the data directory).

3. Investigate and Tune InnoDB Purge Settings advanced

Adjust InnoDB purge thread settings to prevent future occurrences.

1
Understand that this error often relates to InnoDB's background purge threads not being able to clean up old undo log segments because they are still being accessed. This can happen under heavy write load or with specific transaction patterns.
text: No direct code for this step, but understand the concept.
2
Temporarily increase the number of purge threads. This can help clear undo logs faster. **Caution:** This is a temporary workaround and might not be suitable for all environments. Monitor resource usage.
SET GLOBAL innodb_purge_threads = N; -- Where N is a value higher than the default (e.g., 4 or 8).
3
Consider tuning `innodb_undo_log_retention_hours`. If this value is too high, undo logs might be retained longer than necessary, increasing the chance of file contention during purge operations. Lowering it might help, but be mindful of the impact on point-in-time recovery.
SET GLOBAL innodb_undo_log_retention_hours = M; -- Where M is a smaller value (e.g., 24 or less).
4
For a more permanent solution, analyze your workload. Identify if there are long-running transactions or specific query patterns that contribute to undo log buildup. Optimizing these queries or breaking down large transactions can be more effective long-term.
text: Analyze slow query logs and transaction patterns.
🔗

Related Errors

5 related errors