Too many open files with Mariadb 10.4.13 on Macos Catalina

Viewed 6928

i’m run on Macos 10.15.5, with mariadb 10.4.13. Since i did “brew upgrade” I have this error : Out of resources when opening file './pluto/_connection.MYD' (Errcode: 24 "Too many open files")

I tried to modify this file /usr/local/etc/my.cnf to add this line open_files_limit = 60000 but it doesn’t work, open_files_limit variable still blocked on the value 256.

I tried this line : sudo ulimit -n 1024, but each time I restart the value returns to 256

Do you have any help to bring me to help me solve my problem?

5 Answers

Have you tried looking for other ways to modify the open files limit on MacOS Catalina? A quick search led me to here which suggests the following for modifying it for the system while it is running:

sudo launchctl limit maxfiles <soft limit> <hard limit>

This site and this superuser question suggests to modify /Library/LaunchDaemons/limit.maxfiles.plist to permanantly increase it.

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"  
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">  
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string><your soft limit here></string>
      <string><your hard limit here></string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist> 

Then, finish up by changing permissions and verifying the change.

sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
launchctl limit maxfiles
  • MacOS Catalina 10.15.x
  • Mariadb installed with homebrew

Importing database with mysql < foo.sql fails with: [ERROR] Error in accept: Too many open files

Agree with the posts above. This looks like a false negative. This is what worked for me:

brew services stop mariadb

And make sure you do not have any mysql processes running: ps aux | grep mysql.

mkdir /usr/local/var/run/mysqld

Edit Mariadb config file /usr/local/etc/my.cnf and tell it to use this directory.

[client-server]
socket = /usr/local/var/run/mysqld/mysql.sock

[mysqld_safe]
pid-file = /usr/local/var/run/mysqld/mysqld.pid

Strictly speaking you do you only need to define the pid file, though I personally like to store both pid and socket files inside the /usr/local/var/run - structure. I do the same for PHP (/usr/local/var/run/php) installed from Homebrew.

Start you database server and you are done.

brew services start mariadb

I was solving the same issue on MacOS after upgrading from 10.15.5 to 10.15.6, mariadb installed via homebrew, version 10.5.5.

Turns out the problem is not open files limit, but lack of permissions to create PID file.

To fix it I created ~/.my.cnf file with the following content.

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid

And create the mysqld.pid file using following commands (taken from this serverfault issue)

mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chown -R mysql:mysql /var/run/mysqld

That fixed the problem. MySQL/MariaDB is not complaining about opening too many files anymore.

I also needed to kill all running mysql processes (to get theri PIDs run ps aux | grep mysql and then kill {proces_number}. But maybe you don't need this step.

I have been having the same problem using mariadb-10.2 installed via Macports on macOS 10.15.7. Checking open_files_limit shows it has reverted for an unknown reason to 256. I had tried many of the methods described in this question and elsewhere; including making sure that the ulimit is adequate (20000) and launchctl limit maxfiles is adequate (20000 and 200000), and in my.cnf there is reasonable setting for open_file_limit (3000) These parameters remain at these values and do not get changed when mariadb reverts to 256 but are remaining at the expected values.

Not a solution to the root cause but a workaround is to restart mariadb. After that, the open_files_limit for mariadb gets reset to the ulimit of 20000. Note that it does not get set to the 3000 value in in my.cnf but to the 20000 value. This solves the problem for a while.

Also note that for mariadb installed from MacPorts that the way to restart is given by the following two commands:

  1. sudo port unload mariadb-10.2-server
  2. sudo port load mariadb-10.2-server

It won't work to just perform the load, even though the console output says that it was restarted. It might be restarted but I have proven that the only way that open_files_limit gets reset is to first do the unload.

Related