Common SQL Errors

MySQL Error 1587: ER_BINLOG_PURGE_EMFILE - Too many files opened Fix Guide

Galaxy Team
August 7, 2025

<p>Error 1587 happens when MySQL hits the operating system file descriptor limit while purging binary logs, stopping the PURGE BINARY LOGS command.</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 1587 (ER_BINLOG_PURGE_EMFILE)?

<p>MySQL Error 1587: ER_BINLOG_PURGE_EMFILE signals that the server ran out of file descriptors during PURGE BINARY LOGS. Raise open_files_limit or ulimit and rerun the purge to fix the issue.</p>

Error Highlights

Typical Error Message

Too many files opened, please execute the command again

Error Type

System Resource Error

Language

MySQL

Symbol

ER_BINLOG_PURGE_EMFILE

Error Code

1587

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 1587 (ER_BINLOG_PURGE_EMFILE)?

MySQL raises error 1587 with message "Too many files opened, please execute the command again" when it tries to delete binary log files but cannot open another file descriptor because the operating system limit has been exhausted.

This interruption stops the PURGE BINARY LOGS statement or the automatic expire_logs_days process, leaving old log files on disk and risking storage exhaustion.

What Causes This Error?

The server must open each binary log file scheduled for deletion. If the total number of simultaneously open files - tables, indexes, sockets and logs - exceeds open_files_limit or the OS hard limit, MySQL cannot allocate another descriptor and throws error 1587.

Large log retention windows, many active connections or low system limits dramatically increase the chance of hitting the limit.

How to Fix MySQL Error 1587

Increase the file descriptor cap, then rerun the purge. On Linux, set LimitNOFILE in the mysqld systemd unit or raise ulimit -n, restart MySQL, and verify with SHOW VARIABLES LIKE 'open_files_limit'.

After raising the limit, execute PURGE BINARY LOGS or allow expire_logs_days to run again to remove the backlog.

Common Scenarios and Solutions

Automated log rotation fails during peak traffic: temporarily disable binary logging on replicas, raise limits, then resume rotation.

Disk nearly full because purge stopped: attach extra storage, bump limits, then purge logs to free space.

Best Practices to Avoid This Error

Set open_files_limit and OS ulimit -n to at least double the peak number of open tables plus expected binary logs.

Enable binlog_expire_logs_seconds to keep log count manageable and monitor descriptor usage via performance_schema.

Related Errors and Solutions

Error 24 Too many open files - occurs at OS level when any process exceeds ulimit.

Error 1528 ER_CANNOT_PURGE - triggered when a log is still in use by replication; wait or stop the slave SQL thread.

Common Causes

Low open_files_limit

MySQL open_files_limit value is smaller than workload demands, exhausting descriptors during log purge.

Unix ulimit -n too small

The operating system hard limit overrides MySQL settings, capping descriptors to a low number.

Huge binary log backlog

Thousands of retained logs push total open files above default limits when purge starts.

Long running sessions

Processes that keep many tables open consume descriptors and starve maintenance operations.

Related Errors

MySQL Error 24: Too many open files

OS-level failure that can also block client connections.

MySQL Error 1528: ER_CANNOT_PURGE

Raised when a binary log is still required by replication threads.

MySQL Error 1180: ER_OPEN_AS_READONLY

Occurs when MySQL cannot open relay log due to descriptor shortage.

FAQs

How do I check my current file descriptor limit?

Run SHOW VARIABLES LIKE 'open_files_limit' inside MySQL and ulimit -n in the shell where mysqld starts.

Is a server restart mandatory?

Raising open_files_limit at runtime works only up to the compiled ceiling; higher values need a restart with a larger OS limit.

Does a higher limit slow MySQL?

Increasing the cap has negligible performance impact and prevents outages caused by descriptor exhaustion.

How can Galaxy help?

Galaxy highlights error 1587 in query history and suggests raising open_files_limit, allowing engineers to resolve the issue quickly from the editor.

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