#1 Global Leader in Data Resilience

Overcoming TCP/IP Connection Limits with PgBouncer and PostgreSQL on Windows

KB ID: 4760
Product: Veeam Backup for Microsoft 365 | 8.1 | 8.2
Published: 2025-08-29
Last Modified: 2025-08-29
mailbox
Get weekly article updates
By subscribing, you are agreeing to have your personal information managed in accordance with the terms of Veeam's Privacy Notice.

Cheers for trusting us with the spot in your mailbox!

Now you’re less likely to miss what’s been brewing in our knowledge base with this weekly digest

error icon

Oops! Something went wrong.

Please, try again later.

Challenge

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.

Cause

  • 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.

Solution

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.

Reducing the TIME_WAIT Timeout Period (Recommended)

Create the following registry value to modify the length of time that a connection will stay in the TIME_WAIT state before being closed. The default is 240 seconds, which, with the default Dynamic Port Range, will lead to a limit of 68 connections per second. Changing this to 30 seconds will increase that to 546( # of ports / time out in seconds = connections per second || 16384/30= ~546) connections per second.

Key Location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Value Name: TcpTimedWaitDelay
Value Type: DWORD (32-Bit) Value
Value Data: 30

 Note: Restart required to take effect.

PowerShell Command:

New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters' -Name 'TcpTimedWaitDelay' -Value "30" -PropertyType DWORD -Force

Increasing the Number of Available Ephemeral Ports (Conditional)

Before you change the Dynamic Port Range, please review all notes in the Considerations section above.

If issues persist after reducing the TCP Timed Wait Delay to 30 seconds. The following command will change the starting port of Dynamic Port Range from 49152 to 15000, resulting in just over triple the number of ports and raising the theoretical connections per second limit from 546( # of ports / time out in seconds = connections per second || 16384/30= ~546) to 1,684.

 Note: Restart required to take effect.

netsh int ipv4 set dynamicport tcp start=15000 num=50535
If problems persist, you can change the values to start=1025 and num=64511. Keep in mind that lowering the starting port of the dynamic range into the registered section could cause port conflicts if a service or application tries to use a fixed port number that is already assigned for ephemeral port use.

If this KB article did not resolve your issue or you need further assistance with Veeam software, please create a Veeam Support Case.

To submit feedback regarding this article, please click this link: Send Article Feedback
To report a typo on this page, highlight the typo with your mouse and press CTRL + Enter.

Spelling error in text

Thank you!

Thank you!

Your feedback has been received and will be reviewed.

Oops! Something went wrong.

Please, try again later.

You have selected too large block!

Please try select less.

KB Feedback/Suggestion

This form is only for KB Feedback/Suggestions, if you need help with the software open a support case

By submitting, you are agreeing to have your personal information managed in accordance with the terms of Veeam's Privacy Notice.
Verify your email to continue your product download
We've sent a verification code to:
  • Incorrect verification code. Please try again.
An email with a verification code was just sent to
Didn't receive the code? Click to resend in sec
Didn't receive the code? Click to resend
Thank you!

Thank you!

Your feedback has been received and will be reviewed.

error icon

Oops! Something went wrong.

Please, try again later.