Articles in this section

Database operations fail in Plesk for Linux: "Can't open file" or "Out of resources when opening file"

Plesk for Linux kb: technical ABT: Group B

Applicable to:

  • Plesk for Linux

Symptoms

  • When backing up/restoring/exporting/importing a MySQL database in Plesk, the following error message is shown:

    PLESK_INFO: mysqldump: Got error: 1016: "Can't open file: './example_db/table.frm' (errno: 24)" when using LOCK TABLES


    PLESK_INFO: Not all the data was backed up into [...]/databasename_1 successfully. mysqldump: Got error: 23: Out of resources when opening file '[...]' (Errcode: 24 - Too many open files) when using LOCK TABLES

  • The value of max_connections changes to 214 automatically after some time, although the value itself is defined in my.cnf:

    # grep -i 'max_connections' /etc/my.cnf
    max_connections=2048

    # plesk db "SHOW GLOBAL VARIABLES LIKE 'max_connections' \G"
    *************************** 1. row ***************************
    Variable_name: max_connections
    Value: 214

Cause

Default open_files_limit for MySQL has been reached.

Resolution

Increase open_files_limit for the MySQL service as below.

Note: The solution below is applicable to systemd-based systems:
    - RHEL/CentOS/CloudLunix 7 and above
    - Ubuntu 16.04 and above
    - Debian 8 and above

  1. Connect to the server via SSH.

  2. Find the MySQL service in use:

    # systemctl list-unit-files | grep -E 'mysql|mariadb'
    mariadb.service enabled

  3. Open the service configuration file from the step above in an editor:

    # systemctl edit mariadb.service

  4. Add the following content:

    CONFIG_TEXT: [Service]
    LimitNOFILE=4096

  5. Save the changes and close the file.

  6. Restart the MySQL/MariaDB server to apply the changes:

    # systemctl restart mysql mysqld mariadb 2>/dev/null

    If the same error appears after these changes, increase the value.

 

 

On System V/Upstart systems (Ubuntu 14.04, RHEL/CentOS/CloudLinux 6)

 

For Debian-based distributions:
  1. Connect to the server via SSH.

  2. Add the following lines in /etc/security/limits.conf:

    CONFIG_TEXT: mysql soft nofile 4096
    mysql hard nofile 4096

  3. Add the following to the end of file into /etc/pam.d/common-session :

    CONFIG_TEXT: session required pam_limits.so

  4. Add the following to the end of file into /etc/pam.d/common-session-noninteractive:

    CONFIG_TEXT: session required pam_limits.so

  5. Add the following line in /etc/mysql/my.cnf and under the [mysqld] section:

    CONFIG_TEXT: open_files_limit = 4096

  6. Restart the MySQL service:

    # service mysql restart

 

For RHEL-based distributions:
  1. Connect to the server via SSH.

  2. Add the following line in /etc/sysctl.conf:

    CONFIG_TEXT: fs.file-max = 65536

  3. Edit the file /etc/security/limits.conf and add lines:

    CONFIG_TEXT: * soft nproc 40960
    * hard nproc 40960
    * soft nofile 40960
    * hard nofile 40960

  4. Edit the file /etc/security/limits.d/90-nproc.conf and add lines:

    CONFIG_TEXT: * soft nproc 40960
    * hard nproc 40960
    * soft nofile 40960
    * hard nofile 40960

  5. Add the following line in /etc/my.cnf and under the [mysqld] section:

    CONFIG_TEXT: open_files_limit = 4096

  6. Restart the MySQL service:

    # service mariadb restart

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.