How to increase file descriptors max limit on Linux

Today my DBA reported that the server she was working on was spitting out “too many open files” errors and no new processes could be started.

This is a common problem with DB servers with heavy transactions. In my environment there are 6 DB instances running on the server. No quite the optimized setup I would say.

The fix was to increase the total file descriptors kernel parameter count in the /etc/sysctl.conf file. I doubled my limit from 8192 to 16384.

The walk through,

1. Find out what the current open file descriptor limit is.

~# more /proc/sys/fs/file-max

~# 8192

or

~# sysctl -a | grep fs.file-max

~# fs.file-max = 8192

2. View how many open file descriptors are currently being used.

~# more /proc/sys/fs/file-nr

~# 8191

3. View how many files are open. The number returned might defer as 1 file descriptor can have multiple open files attached to it.

~# lsof | wc -l

~# 10325

4. Edit the kernel paramneter file /etc/sysctl.conf and add line “fs.file-max=[new value]” to it.

~# vi /etc/sysctl.conf

fs.file-max = 331287

5. Apply the changes.

~# sysctl -p
~# fs.file-max = 331287

Problem fixed.

  • E.Marcus

    For SuSe (10.3) boxes you can do the same with the ulimit command
    ulimit -Hn
    -H to set hardlimit
    -n to set number of open file descriptors

    or you can manually do it in
    /etc/security/limits.conf

  • http://thedaneshproject.com Danny

    Thanks Marcus

  • E.Marcus

    After researching a lil further, i found that the limits.conf only places the limits on the graphical login.

    if you want to put it on services. put the ulimit command in the boot script.

    One limitation i see of setting the FD limit in sysctl.conf is that it applies to every application. Unless you want every process to get that many FD’s. I would go for the boot script way of setting FD limits.

    Thoughts?

  • http://thedaneshproject.com Danny

    Yup, ulimit will be user specific and sysctl method system wide. Since my box is for DB only it does not worry me too much.

    Thanks for the highlight man :)

  • cucu

    hi malaysians…,vote wisely

  • http://www.year26.org Jake

    I’m having issue with a cups print server throwing the same error. I’ve increased the max file system wide as well as in limits.conf…cups still thinks 1024 is the default so it only allows 1/3 (341) connections…Thoughts?

  • Pingback: Delicious Bookmarks for December 9th through December 11th « Lâmôlabs

  • Pingback: Schwerer Fehler eventuell Grafikkarte - Linux: Linux-Forum

  • Hermann

    How do we decide the max FD number for the machine? Is there anything bad if I change the the limit to a huge number like 999999?

    • http://thedaneshproject.com Danesh

      why would you want to do that?

    • Burak Say

      Solr In Action book suggests setting the limit to 100,000 or something higher depending on your merge policy and number of cores running simultaneously.

© 2008-2012 The Danesh Project
Powered by Wordpress and made by Guerrilla. Hosted at ServerFreak