Stop your database from choking on file descriptors

Performance Tuning & Kernel Parameters (Sysctl)

Stop your database from choking on file descriptors

🧩 The Challenge

Dealing with a production app that randomly crashes with “too many open files” errors is a nightmare when you’re already at max limits. I spent a whole weekend debugging a Postgres instance that just refused to open any more connections even though it had plenty of RAM.

💡 The Fix

Increase the system-wide file descriptor limit via sysctl and make sure your init system is actually letting the process use those slots. You’ll stop those “connection refused” panic attacks once the kernel stops capping you at the default 1024.

sysctl -w fs.file-max=2097152
echo "fs.file-max=2097152" >> /etc/sysctl.conf
sysctl -p

⚙️ Why It Works

By cranking up the kernel’s global limit for open file handles, you provide enough breathing room for high-concurrency apps that treat every network socket and file segment as an open handle. Most default setups are stuck in the mid-90s, which just doesn’t cut it for modern workloads.

🚀 Pro-Tip: Check /proc/sys/fs/file-nr if you want to see exactly how many handles your system is currently burning through.

Linux Tips & Tricks | © ngelinux.com | 11/24/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted