Common SQL Errors

MySQL Error 1867: ER_WARN_PURGE_LOG_IN_USE - How to Fix and Prevent

Galaxy Team
August 8, 2025

MySQL issues warning 1867 when a PURGE BINARY LOGS or automatic log expiration tries to delete a binary log still being read by another thread.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1867 (ER_WARN_PURGE_LOG_IN_USE)?

MySQL Error 1867 (ER_WARN_PURGE_LOG_IN_USE) signals that the server could not delete a binary log file because a replication or client thread is still reading it; wait for the thread to finish or stop it, then rerun PURGE BINARY LOGS to resolve the warning.

Error Highlights

Typical Error Message

ER_WARN_PURGE_LOG_IN_USE

Error Type

Replication Warning

Language

MySQL

Symbol

thread(s), purged only %d out of %d files. ER_WARN_PURGE_LOG_IN_USE was added in 5.7.2.

Error Code

1867

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1867 (ER_WARN_PURGE_LOG_IN_USE)?

Error 1867 appears as a warning when MySQL attempts to execute PURGE BINARY LOGS or expire logs automatically but finds that a target log file is still open by another thread.

Instead of stopping the purge process entirely, MySQL skips the busy file and continues, reporting the exact file name and thread count in the warning text.

What Causes This Error?

The most common cause is an active replication slave or client that is reading the binary log at the moment the purge runs. The server will not delete a log being read to avoid breaking replication or client connections.

Long-running transactions or delayed replication can also keep old binary logs open for extended periods, blocking their removal.

How to Fix MySQL Error 1867

Identify which thread is reading the file, let it finish or kill it, then rerun PURGE BINARY LOGS. If the reader is a slave, ensure it catches up or re-configure its replication position before retrying.

Once no threads are using the file, execute PURGE BINARY LOGS TO 'target_log'; again and the warning should disappear.

Common Scenarios and Solutions

During scheduled log cleanup, a delayed slave may still tail the oldest log. Pause the purge, allow the slave to catch up, then resume.

In backup scripts that read binary logs while copying them, coordinate purge timing so backups finish first.

Best Practices to Avoid This Error

Monitor SHOW SLAVE STATUS and binlog file positions before purging. Automate checks that skip purge while slaves lag.

Use GROUP REPLICATION or GTID based setups with replica lag alerts, and set binlog_expire_logs_seconds high enough for normal lag.

Related Errors and Solutions

Error 1592 (ER_BINLOG_PURGE_PROHIBITED) blocks purge entirely when GTID_PURGED would be invalidated. The fix is to wait until replicas have processed the GTID range or skip the GTIDs.

Error 1380 (HY000): You are not permitted to delete binary log files while replication or backups need them. Grant proper privileges or finish operations first.

Common Causes

Active replication thread

A replica is reading the binary log, preventing its deletion.

Long-running transaction

A client keeps an old log open until the transaction commits or rolls back.

Backup or audit process

External tools such as mysqlbinlog are streaming the log for backups or auditing.

Delayed slave configuration

An intentional delay in replication keeps readers on older logs.

Related Errors

ER_BINLOG_PURGE_PROHIBITED (1592)

Raised when purging would remove GTIDs needed by replicas.

ER_MASTER_FATAL_ERROR_READING_BINLOG (1236)

The replica cannot find the requested log file, often after an unsafe purge.

ER_CANT_USE_LOG_FILE (1380)

Attempt to delete or rotate an in-use binary log fails due to privilege or state issues.

FAQs

Does error 1867 stop replication?

No. It is a warning only. Replication continues and the server skips purging the busy log.

Can I ignore ER_WARN_PURGE_LOG_IN_USE?

You can ignore it briefly, but left unchecked binary logs may grow until storage fills. Always ensure they are eventually purged.

How do I know which replica is blocking the purge?

Compare the file in the warning to Relay_Master_Log_File in SHOW SLAVE STATUS on each replica.

How does Galaxy help?

Galaxy's query history and AI copilot surface long-running queries that keep logs open, letting teams fix them before purge time.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo