Common SQL Errors

MySQL Error 1371: ER_RELAY_LOG_FAIL - How to Fix Failed purging old relay logs

Galaxy Team
August 6, 2025

<p>The replication SQL thread could not delete outdated relay log files, halting replication cleanup.</p>

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 code 1371 ER_RELAY_LOG_FAIL?

<p>MySQL Error 1371 ER_RELAY_LOG_FAIL occurs when the replication SQL thread fails to purge old relay log files. Verify disk permissions, free disk space, and the relay_log_purge setting, then manually execute PURGE BINARY LOGS or restart replication to clear the logs and resume normal operation.</p>

Error Highlights

Typical Error Message

Failed purging old relay logs: %s

Error Type

Replication Error

Language

MySQL

Symbol

ER_RELAY_LOG_FAIL

Error Code

1371

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1371 ER_RELAY_LOG_FAIL?

MySQL raises Error 1371 with the ER_RELAY_LOG_FAIL condition when the replication SQL thread cannot delete obsolete relay log files during cleanup. The message appears as Failed purging old relay logs: %s and halts automatic relay log maintenance.

Replication relies on relay logs to store events retrieved from a primary server. If these logs are not purged, disk space can fill up and replication performance degrades. Addressing the failure quickly prevents replica lag and potential outages.

What Causes This Error?

The purge operation needs adequate file system permissions, available disk space, and correct server settings. Missing any of these prerequisites triggers ER_RELAY_LOG_FAIL. The error may also surface after abrupt server restarts or partial disk failures that corrupt relay log files.

Another frequent cause is relay_log_purge set to OFF while expire_logs_days or binlog_expire_logs_seconds try to remove files, creating conflicts that stop the purge process.

How to Fix MySQL Error 1371 ER_RELAY_LOG_FAIL

Start by checking the MySQL error log for additional context such as an I/O or permission error. Ensure the MySQL process owner can delete files in the relay-log directory and that the partition has sufficient free space.

If permissions and space look fine, manually purge binary and relay logs with SQL commands, then restart the replica threads. Disable relay_log_purge only for controlled maintenance tasks to avoid repeated failures.

Common Scenarios and Solutions

On Linux systems with strict SELinux policies, the MySQL daemon may lack delete rights. Adjust security contexts or temporarily disable SELinux enforcing mode to allow the purge.

In cloud environments, auto-scaling storage can silently reach quota limits. Expanding the volume or moving the relay log directory fixes the space constraint and lets purging proceed normally.

Best Practices to Avoid This Error

Enable relay_log_purge and set appropriate expire_logs_days so cleanup runs automatically. Monitor disk usage on replicas and alert when relay log directories exceed thresholds.

Use Galaxy’s fast SQL editor to script periodic checks on SHOW SLAVE STATUS and the relay log directory size. Share endorsed monitoring queries in a Galaxy Collection so the entire team stays aware of replication health.

Related Errors and Solutions

Replication setups frequently encounter MySQL Error 1595 Relay log read failure and Error 1236 Could not find first log file. These issues involve missing or unreadable relay logs and are resolved with similar permission, space, or file integrity checks.

Error 1201 could not connect to master indicates network or authentication problems, differing from ER_RELAY_LOG_FAIL but also halts replication. Fixing host connectivity or credentials eliminates that error.

Common Causes

Permission Denied on Relay Log Directory

The MySQL system user lacks OS-level delete privileges, preventing relay log removal.

Disk Space Exhausted

The partition containing relay logs is full, so purge operations cannot allocate temporary resources required for deletion.

relay_log_purge Disabled

Setting relay_log_purge=OFF blocks automatic cleanup and eventually triggers the error when expire settings try to purge logs.

File System Corruption

Unclean shutdowns or hardware faults leave relay log files partially corrupted, causing the purge routine to abort with Error 1371.

Related Errors

MySQL Error 1595 Relay log read failure

Indicates a damaged relay log file. Rebuild replication or re-sync the replica.

MySQL Error 1236 Could not find first log file

Occurs when referenced binary or relay logs are missing. Verify log retention policies.

MySQL Error 1201 Could not connect to master

Points to network or authentication issues between replica and primary.

FAQs

Does ER_RELAY_LOG_FAIL stop replication?

The error halts relay log cleanup but the SQL thread may continue applying events until disk space runs out. Investigate quickly to avoid full stoppage.

Can I safely delete relay logs manually?

Only delete relay logs after stopping replication with STOP SLAVE. Use RESET SLAVE to regenerate a clean set automatically.

What MySQL versions are affected?

Error 1371 exists in all 5.6, 5.7, 8.0, and 8.1 community and enterprise builds because relay log purging logic is unchanged.

How does Galaxy help?

Galaxy lets teams share replication health queries and automate checks, reducing the chance of unnoticed relay log buildup.

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