Loading...
Loading...
When running PgBouncer and PostgreSQL on Windows, especially under high-load scenarios with frequent connect/disconnect cycles, you may encounter exhaustion of available TCP ports. This is due to many connections ending up in the TIME_WAIT state, preventing immediate reuse of those ports and potentially leading to connection failures. PgBouncer helps reduce the frequency of backend (PostgreSQL) connections, but VBO Controller Proxies opens and closes connections rapidly to PgBouncer itself, what can lead to the Windows ports exhaustion.
Available Ephemeral Port Exhaustion — By default, Windows allows for assigning 16,384 ports (49152-65535) for outgoing connections, known as the Dynamic Port Range. In heavy load environments with multiple connections, the available ephemeral ports may be exhausted. Ports Stuck in TIME_WAIT State — When a TCP connection is closed, the port assigned to that connection enters the TIME_WAIT state for 240 seconds (Windows default value). While in this state, the port cannot be reassigned to another connection. Therefore, when there is a high connection churn, this 4-minute delay in unused port reassignment can cause all available ephemeral ports to be used up.
This situation can be resolved by reducing the port wait timeout, increasing the number of ephemeral ports, or combining them. Considerations It is advisable first to modify the TIME_WAIT timeout period, and then, only if issues persist, consider expanding the Dynamic Port Range (quantity of available ephemeral ports). The Windows default Dynamic Port Range of 49152-65535 aligns with RFC6335.6, and most operating systems and firewalls will expect that port range to be used by ephemeral ports for communication. Considering the maximum port number is 65535, the only way to expand the Dynamic Port Range is to change the Dynamic Port Range's starting port. That means selecting a port number in the range prescribed for registered ports, which are more commonly used for persistent service communication. When changing the Dynamic Port Range, we suggest initially using a starting port far higher than most services will utilize, such as port 15,000, to prevent port conflicts. The change from a Dynamic Port Range of 49152-65535 to 15000-65535 is an increase from 16,384 ports to 50,535, or a 208% increase in available ephemeral ports.
Related Articles How to Install and Configure PgBouncer for Veeam Backup for Microsoft 365 PostgreSQL and PgBouncer Sizing and Configuration Guide Overcoming TCP/IP Connection Limits with PgBouncer and PostgreSQL on Windows
Veeam Integration
Learn more about where this data comes from
BugZero Plan
Streamline upgrades with automated vendor bug scrubs
BugZero Prevent
Wish you caught this bug sooner? Get proactive today.