File descriptor exhaustion is a common but misdiagnosed cause of PostgreSQL outages. The kernel enforces both a system-wide FD ceiling (fs.file-max) and a per-process limit (RLIMIT_NOFILE). PostgreSQL's process-per-connection model means high connection counts — especially without a pooler — can exhaust these limits fast, particularly when lock contention extends how long backends hold FDs open. The post walks through the exact log sequence during an outage, OS and PostgreSQL-level diagnostic commands, and the proper fix: deploying PgBouncer to multiplex thousands of app connections down to a small backend pool. Raising fs.file-max is covered as a temporary measure, including how to apply it on Kubernetes (AKS) via kubectl debug or a privileged DaemonSet. Monitoring recommendations focus on alerting before file-nr approaches fs.file-max rather than reacting after errors appear.

7m read timeFrom postgr.es
Post cover image
Table of contents
What are file descriptors and why PostgreSQL burns through themHow exhaustion happensThe error sequence in the logsDiagnosing the problemThe fix: PgBouncerIncreasing OS file descriptor limits (temp measure)Monitoring
819 Impressions