How to Fix MySQL Error 1868 (ER_WARN_PURGE_LOG_IS_ACTIVE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 1868 when a purge task targets an active log file. To fix it, target an older log file or rotate the log first. MySQL uses binary logs to record data changes and support replication across servers. When disk space runs low, database teams remove old binary log files. If you try to delete a file still in use, the server warns you. It returns SQLSTATE HY000 and keeps the active file safe on disk. What triggers mysql error 1868 in your database The MySQL server tracks this w

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mysql error 1868 when a purge task targets an active log file. To fix it, target an older log file or rotate the log first.

MySQL uses binary logs to record data changes and support replication across servers. When disk space runs low, database teams remove old binary log files. If you try to delete a file still in use, the server warns you. It returns SQLSTATE HY000 and keeps the active file safe on disk.

What triggers mysql error 1868 in your database

The MySQL server tracks this warning under the symbol ER_WARN_PURGE_LOG_IS_ACTIVE. The official error message states that the file was not purged. It explains that the target file is the active log file. This design prevents you from breaking replication or losing recent data changes.

Two main events cause this warning during daily database operations. First, an operator or script picks the current log file as the cutoff target. Second, a replica server is still reading events from the log file you picked. In both cases, the database engine blocks the deletion of that active file. It deletes older files before the active one and then stops.

Automated cleanup scripts often trigger this warning when they calculate timestamps poorly. A script might ask the engine to purge logs up to the exact current second. Since the newest file handles live writes, the engine refuses to delete it. The server completes the safe part of the task and logs code 1868.

How to diagnose the active log state

Start by checking which binary log file the primary server writes to right now. Compare that file name with the target file name in your purge request. If they match, your command asked the server to delete its live write log.

Next, check the status of all connected replica servers in your cluster. Find out which binary log file each replica reads at this moment. Sometimes a slow network link or heavy load delays a replica. That replica will hold an older binary log file open until it catches up. The primary server treats that file as active to protect the replica.

Active Directory + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You should also review your scheduled cleanup jobs and disk management scripts. Look for logic that selects the newest file in the log directory. Make sure those scripts leave a safe time buffer before the current hour.

How to fix the warning and purge logs safely

You can clear this warning without granting broad system rights or turning off safety checks. If you must purge the current log right away, rotate the binary logs first. Rotating the logs forces the database engine to close the current file. The engine opens a fresh file for new writes, making the old one inactive.

After the rotation finishes, check the replica servers one more time. Wait until every replica moves past the file you want to remove. Once all replicas read from the new file, run your purge task again. Target the closed log file, and the command will finish without warnings.

For long-term health, use built-in log expiration rules instead of manual purge tasks. Built-in expiration rules let the database engine age out old files on its own. The engine checks file state before removal and skips active files by design. You should also limit who can run log purge tasks in production. Grant log management rights only to specific admin roles and mask sensitive data like emails or card numbers in query outputs.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

Does mysql error 1868 stop my database or break replication?

No, code 1868 is a warning that protects your database from harm. The server skips the active file so live writes and replication continue safely.

Why does an old binary log file show up as active?

An old log file stays active if a lagging replica still reads from it. You must wait for that replica to catch up before purging that file.

Should I delete binary log files straight from the operating system disk?

Never delete binary log files directly from the host file system. Manual file deletion breaks the internal log index and stops replication across your cluster.

The query runs. The emails stay hidden.