简体   繁体   中英

Too many open files error on Ubuntu 8.04

mysqldump: Couldn't execute 'show fields from `tablename`': Out of resources when opening file './databasename/tablename#P#p125.MYD' (Errcode: 24) (23)

on checking the error 24 on the shell it says

>>perror 24

OS error code  24:  Too many open files

how do I solve this?

At first, to identify the certain user or group limits you have to do the following:

root@ubuntu:~# sudo -u mysql bash
mysql@ubuntu:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 71680
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 71680
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
mysql@ubuntu:~$

The important line is:

open files (-n) 1024

As you can see, your operating system vendor ships this version with the basic Linux configuration - 1024 files per process.

This is obviously not enough for a busy MySQL installation.

Now, to fix this you have to modify the following file:

/etc/security/limits.conf

mysql             soft    nofile           24000
mysql             hard    nofile           32000

Some flavors of Linux also require additional configuration to get this to stick to daemon processes versus login sessions. In Ubuntu 10.04, for example, you need to also set the pam session limits by adding the following line to /etc/pam.d/common-session :

session required pam_limits.so

Quite an old question but here are my two cents.

The thing that you could be experiencing is that the mysql engine didn't set its variable "open-files-limit" right.

You can see how many files are you allowing mysql to open mysql> SHOW VARIABLES;

Probably is set to 1024 even if you already set the limits to higher values.

You can use the option --open-files-limit=XXXXX in the command line for mysqld.

Cheers

将--single_transaction添加到mysqldump命令中

There are no need to configure PAM, as I think. On my system (Debian 7.2 with Percona 5.5.31-rel30.3-520.squeeze ) I have:

Before my.cnf changes:

\#cat /proc/12345/limits |grep "open files"
Max open files            1186                 1186                 files

After adding "open_files_limit = 4096" into my.cnf and mysqld restart, I got:

\#cat /proc/23456/limits |grep "open files"
Max open files            4096                 4096                 files

12345 and 23456 is mysqld process PID, of course.

SHOW VARIABLES LIKE 'open_files_limit' show 4096 now.

All looks ok, while "ulimit" show no changes:

\# su - mysql -c bash
\# ulimit -n
1024

It could also be possible that by some code that accesses the tables dint close those properly and over a point of time, the number of open files could be reached.

Please refer to http://dev.mysql.com/doc/refman/5.0/en/table-cache.html for a possible reason as well.

Restarting mysql should cause this problem to go away (although it might happen again unless the underlying problem is fixed).

You can increase your OS limits by editing /etc/security/limits.conf.

You can also install " lsof " (LiSt Open Files) command to see Files <-> Processes relation.

There is no guarantee that "24" is an OS-level error number, so don't assume that this means that too many file handles are open. It could be some type of internal error code used within mysql itself. I'd suggest asking on the mysql mailing lists about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM