Skip to content

Commit db4f3a6

Browse files
Merge pull request #4297 from varun-dhawan/varund-sep
[PostgreSQL] updates the outdated details
2 parents bf70c0f + 7d08908 commit db4f3a6

3 files changed

Lines changed: 262 additions & 267 deletions

File tree

articles/postgresql/connectivity/concepts-pgbouncer.md

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ description: This article provides an overview of the built-in PgBouncer feature
44
author: varun-dhawan
55
ms.author: varundhawan
66
ms.reviewer: maghan
7-
ms.date: 1/22/2026
7+
ms.date: 02/03/2026
88
ms.service: azure-database-postgresql
99
ms.subservice: connectivity
1010
ms.topic: concept-article
1111
---
1212

13-
# PgBouncer in Azure Database for PostgreSQL
13+
# PgBouncer in Azure Database for PostgreSQL
1414

15-
Azure Database for PostgreSQL flexible server instances offers [PgBouncer](https://github.com/pgbouncer/pgbouncer) as a built-in connection pooling solution. PgBouncer is an optional feature that you can enable on a per-database-server basis. It's supported on General Purpose and Memory Optimized compute tiers in both public access and private access networks.
15+
Azure Database for PostgreSQL flexible server instances offer [PgBouncer](https://github.com/pgbouncer/pgbouncer) as a built-in connection pooling solution. PgBouncer is an optional feature that you can enable on a per-database-server basis. It's supported on General Purpose and Memory Optimized compute tiers in both public access and private access networks.
1616

1717
PgBouncer runs on the same virtual machine (VM) as the database server for your Azure Database for PostgreSQL flexible server instance. Postgres uses a process-based model for connections, so maintaining many idle connections is expensive. Postgres runs into resource constraints when the server runs more than a few thousand connections. The primary benefit of PgBouncer is to improve idle connections and short-lived connections at the database server.
1818

19-
PgBouncer uses a lightweight model that utilizes asynchronous I/O. It uses Postgres connections only when needed--that is, when inside an open transaction or when a query is active. This model allows scaling to up to 10,000 connections with low overhead.
19+
PgBouncer uses a lightweight model that utilizes asynchronous I/O. It uses Postgres connections only when needed - that is, when inside an open transaction or when a query is active. This model allows scaling to up to 10,000 connections with low overhead.
2020

2121
The version of PgBouncer deployed on all supported major versions of the engine, in Azure Database for PostgreSQL, is **[!INCLUDE [pgbouncer-table](includes/pgbouncer-table.md)]**. PgBouncer runs on port 6432 on your database server. You can change your application's database connection configuration to use the same host name, but change the port to 6432 to start using PgBouncer and benefit from improved scaling of idle connections.
2222

2323
PgBouncer in Azure Database for PostgreSQL supports [Microsoft Entra authentication](../security/security-entra-concepts.md) (Azure AD).
2424

2525
## Enable and configure PgBouncer
2626

27-
PgBouncer is especially useful in transactional applications where frequent connection churn can degrade performance. It is enabled by default on port 6432, and you can connect to it using the same host name as your PostgreSQL server, but with port 6432 instead of the default port 5432.
27+
PgBouncer is especially useful in transactional applications where frequent connection churn can degrade performance. It's enabled by default on port 6432, and you can connect to it by using the same host name as your PostgreSQL server, but with port 6432 instead of the default port 5432.
2828

2929
To enable PgBouncer, go to the **Server parameters** pane in the Azure portal, search for **PgBouncer**, and change the `pgbouncer.enabled` setting to `true`. There's no need to restart the server.
3030

@@ -39,9 +39,9 @@ For more information about PgBouncer configurations, see the [pgbouncer.ini docu
3939

4040
## Benefits
4141

42-
By using the built-in PgBouncer feature with your Azure Database for PostgreSQL flexible server instance, you can get these benefits:
42+
By using the built-in PgBouncer feature with your Azure Database for PostgreSQL flexible server instance, you get these benefits:
4343

44-
- **Convenience of simplified configuration**: Because PgBouncer is integrated with your Azure Database for PostgreSQL flexible server instance, there's no need for a separate installation or complex setup. You can configure it directly from the server parameters.
44+
- **Convenience of simplified configuration**: Because PgBouncer is integrated with your Azure Database for PostgreSQL flexible server instance, you don't need a separate installation or complex setup. You can configure it directly from the server parameters.
4545

4646
- **Reliability of a managed service**: PgBouncer offers the advantages of Azure managed services. For example, Azure manages updates of PgBouncer. Automatic updates eliminate the need for manual maintenance and ensure that PgBouncer stays up to date with the latest features and security patches.
4747

@@ -55,27 +55,28 @@ By using the built-in PgBouncer feature with your Azure Database for PostgreSQL
5555

5656
[!INCLUDE [PgBouncer Metrics](includes/pgbouncer-metrics.md)]
5757

58-
To learn more, see [PgBouncer metrics](../monitor/concepts-monitoring.md#pgbouncer-metrics).
58+
For more information, see [PgBouncer metrics](../monitor/concepts-monitoring.md#pgbouncer-metrics).
5959

6060
### Logs
6161

62-
PgBouncer logs are available in Azure Database for PostgreSQL Flexible Server to help audit connection pooling activity and troubleshoot issues such as connection drops, authentication failures, or pool exhaustion. PgBouncer logs include details such as authentication failures, connection lifecycle events, errors, and server state changes — all useful for identifying connection bottlenecks and behavioral anomalies.
62+
Azure Database for PostgreSQL Flexible Server provides PgBouncer logs to help you audit connection pooling activity and troubleshoot problems such as connection drops, authentication failures, or pool exhaustion. PgBouncer logs include details such as authentication failures, connection lifecycle events, errors, and server state changes. These details are useful for identifying connection bottlenecks and behavioral anomalies.
6363

64-
#### Enabling Logs
64+
#### Enabling logs
6565

66-
PgBouncer logs are automatically emitted when Logs Diagnostic Settings are enabled. Two schema types are supported in Log Analytics **Azure diagnostics** and **Resource-Specific**. For more information, see [Common and service-specific schemas for Azure resource logs](/azure/azure-monitor/platform/resource-logs?tabs=log-analytics#select-the-collection-mode).
66+
Enable Logs Diagnostic Settings to automatically emit PgBouncer logs. Log Analytics supports two schema types: **Azure diagnostics** and **Resource-Specific**. For more information, see [Common and service-specific schemas for Azure resource logs](/azure/azure-monitor/platform/resource-logs?tabs=log-analytics#select-the-collection-mode).
6767

68-
- **Azure diagnostics Schema**
69-
- Logs appear in the `AzureDiagnostics` table
70-
- Filter using: `Category == "PostgreSQLFlexPGBouncer"`
68+
- **Azure diagnostics Schema**
69+
- Logs appear in the `AzureDiagnostics` table.
70+
- Filter using: `Category == "PostgreSQLFlexPGBouncer"`.
7171

72-
- **Resource-Specific Schema**
73-
- Logs appear in the `PGSQLPgBouncer` table
74-
- Easier to query, structured format
72+
- **Resource-Specific Schema**
73+
- Logs appear in the `PGSQLPgBouncer` table.
74+
- Easier to query, structured format.
7575

76-
#### Sample KQL Queries
76+
#### Sample KQL queries
7777

7878
**Azure diagnostics Schema:**
79+
7980
```kusto
8081
AzureDiagnostics
8182
| where Category == "PostgreSQLFlexPGBouncer"
@@ -84,13 +85,14 @@ AzureDiagnostics
8485
```
8586

8687
**Resource-Specific Schema:**
88+
8789
```kusto
8890
PGSQLPgBouncer
8991
| where _ResourceId =~ "your-server-name"
9092
| order by TimeGenerated desc
9193
```
9294
> [!NOTE]
93-
> The field names and schema format may vary slightly depending on the schema used (Consolidated vs Resource-Specific).
95+
> The field names and schema format might vary slightly depending on the schema used (Consolidated vs Resource-Specific).
9496
9597
### Admin console
9698

@@ -105,7 +107,7 @@ To connect to the `pgbouncer` database:
105107
psql "host=myPgServer.postgres.database.azure.com port=6432 dbname=pgbouncer user=myUser password=<password> sslmode=require"
106108
```
107109

108-
After you're connected to the database, use `SHOW` commands to view PgBouncer statistics:
110+
After you connect to the database, use `SHOW` commands to view PgBouncer statistics:
109111

110112
- `SHOW HELP`: List all the available `SHOW` commands.
111113
- `SHOW POOLS`: Show the number of connections in each state for each pool.
@@ -129,34 +131,27 @@ To start using PgBouncer, follow these steps:
129131

130132
## PgBouncer in zone-redundant high availability
131133

132-
In zone-redundant, high-availability (HA) servers, the primary server runs PgBouncer. You can connect to PgBouncer on the primary server over port 6432. After a failover, PgBouncer is restarted on the newly promoted standby, which is now the primary server. So your application connection string remains the same after failover.
134+
In zone-redundant, high-availability (HA) servers, the primary server runs PgBouncer. You can connect to PgBouncer on the primary server over port 6432. After a failover, the system restarts PgBouncer on the newly promoted standby, which is now the primary server. So your application connection string remains the same after failover.
133135

134136
## PgBouncer with elastic clusters
135137

136-
PgBouncer is also available for elastic clusters. Each node in an elastic cluster has its own instance of PgBouncer. After being enabled, port 6432 will route to PgBouncer on the elastic cluster coordinator node. Additionally, port 8432 will route to the PgBouncer instances running on the worker nodes in the cluster.
137-
138-
## Using PgBouncer with other connection pools
139-
140-
In some cases, you might already have an application-side connection pool or have PgBouncer set up on your application side (for example, an Azure Kubernetes Service sidecar). In these cases, the built-in PgBouncer feature can still be useful because it provides the benefits of idle connection scaling.
141-
142-
Using an application-side pool together with PgBouncer on the database server can be beneficial. Here, the application-side pool brings the benefit of reduced initial connection latency (because the roundtrip to initialize the connection is much faster), and the database-side PgBouncer provides idle connection scaling.
138+
PgBouncer is also available for elastic clusters. Each node in an elastic cluster has its own instance of PgBouncer. After you enable it, port 6432 routes to PgBouncer on the elastic cluster coordinator node. Additionally, port 8432 routes to the PgBouncer instances running on the worker nodes in the cluster.
143139

144140
## Limitations
145141

146-
- The PgBouncer feature is currently not supported with the Burstable server compute tier. If you change the compute tier from General Purpose or Memory Optimized to Burstable, you lose the built-in PgBouncer capability.
147-
- Whenever the server is restarted during scale operations, HA failover, or a restart, PgBouncer and the VM are also restarted. You then have to re-establish the existing connections.
148-
- The portal doesn't show all PgBouncer parameters. After you enable PgBouncer and save the parameters, you have to close the **Server parameters** pane (for example, select **Overview**) and then go back to the **Server parameters** pane.
149-
- You can't use statement pool modes along with prepared statements. Current version of PgBouncer added support for prepared statements inside of transaction mode. This support can be enabled and configured via [max_prepared_statements parameter](../server-parameters/concepts-server-parameters.md). Setting this parameter above default value of 0 will turn on support for prepared statements. This support only applies to protocol-level prepared statements. For most programming languages, this means that we are using the *[libpq](https://www.postgresql.org/docs/current/libpq.html)* function *PQprepare* on the client, sending protocol level commands that PgBouncer can intercept, rather than issuing a dynamic SQL command similar to *PREPARE proc AS*, which is sending text that PgBouncer will not interpret correctly. To check other limitations of your chosen pool mode, refer to the [PgBouncer documentation](https://www.pgbouncer.org/features.html).
150-
- If PgBouncer is deployed as a feature, it becomes a potential single point of failure. If the PgBouncer feature is down, it can disrupt the entire database connection pool and cause downtime for the application. To mitigate the single point of failure, you can set up multiple PgBouncer instances behind a load balancer for high availability on Azure VMs.
151-
- Token Size Restriction with Azure AD Authentication - Users with a large number of group memberships won't be able to connect through PgBouncer due to a token size restriction. Applications, services, and users with a small number of groups work.
152-
- PgBouncer is a lightweight application that uses a single-threaded architecture. This design is great for most application workloads. But in applications that create a large number of short-lived connections, this design might affect pgBouncer performance and limit your ability to scale your application. You might need to try one of these approaches:
153-
- Distribute the connection load across multiple PgBouncer instances on Azure VMs.
154-
- Consider alternative solutions, including multithreaded solutions like [PgCat](https://github.com/postgresml/pgcat), on Azure VMs.
155-
142+
- The PgBouncer feature currently doesn't support the Burstable server compute tier. If you change the compute tier from General Purpose or Memory Optimized to Burstable, you lose the built-in PgBouncer capability.
143+
- Whenever the server restarts during scale operations, HA failover, or a restart, the system also restarts PgBouncer and the VM. You then need to re-establish the existing connections.
144+
- The portal doesn't show all PgBouncer parameters. After you enable PgBouncer and save the parameters, you need to close the **Server parameters** pane (for example, select **Overview**) and then go back to the **Server parameters** pane to see all parameters.
145+
- You can't use statement pool modes along with prepared statements. The current version of PgBouncer adds support for prepared statements inside of transaction mode. This support can be enabled and configured via the [max_prepared_statements parameter](../server-parameters/concepts-server-parameters.md). Setting this parameter above the default value of 0 turns on support for prepared statements. This support only applies to protocol-level prepared statements. For most programming languages, this support means that the application uses the *[libpq](https://www.postgresql.org/docs/current/libpq.html)* function *PQprepare* on the client, sending protocol level commands that PgBouncer can intercept, rather than issuing a dynamic SQL command similar to *PREPARE proc AS*, which is sending text that PgBouncer won't interpret correctly. To check other limitations of your chosen pool mode, refer to the [PgBouncer documentation](https://www.pgbouncer.org/features.html).
146+
- If you deploy PgBouncer as a feature, it becomes a potential single point of failure. If the PgBouncer feature is down, it can disrupt the entire database connection pool and cause downtime for the application. To mitigate the single point of failure, you can set up multiple PgBouncer instances behind a load balancer for high availability on Azure VMs.
147+
- PgBouncer is a lightweight application that uses a single-threaded architecture. This design is great for most application workloads. But in applications that create a large number of short-lived connections, this design might affect PgBouncer performance and limit your ability to scale your application. You might need to try one of these approaches:
148+
- Distribute the connection load across multiple PgBouncer instances on Azure VMs.
149+
- Consider alternative solutions, including multithreaded solutions like [PgCat](https://github.com/postgresml/pgcat), on Azure VMs.
150+
156151
> [!IMPORTANT]
157-
> The parameter `pgbouncer.client_tls_sslmode` for the built-in PgBouncer feature has been deprecated in Azure Database for PostgreSQL.
158-
>
159-
> When TLS/SSL for connections to an Azure Database for PostgreSQL flexible server instance is enforced via setting the `require_secure_transport` server parameter to `ON`, TLS/SSL is automatically enforced for connections to the built-in PgBouncer feature. This setting is on by default when you create a new Azure Database for PostgreSQL flexible server instance and enable the built-in PgBouncer feature. For more information, see [Secure connectivity with TLS in Azure Database for PostgreSQL](../security/security-tls.md).
152+
> The parameter `pgbouncer.client_tls_sslmode` for the built-in PgBouncer feature is deprecated in Azure Database for PostgreSQL.
153+
>
154+
> When you enforce TLS/SSL for connections to an Azure Database for PostgreSQL flexible server instance by setting the `require_secure_transport` server parameter to `ON`, TLS/SSL is automatically enforced for connections to the built-in PgBouncer feature. This setting is on by default when you create a new Azure Database for PostgreSQL flexible server instance and enable the built-in PgBouncer feature. For more information, see [Secure connectivity with TLS in Azure Database for PostgreSQL](../security/security-tls.md).
160155
161156
For customers who want simplified management, built-in high availability, easy connectivity with containerized applications, and the ability to use the most popular configuration parameters, the built-in PgBouncer feature is a good choice. For customers who want multithreaded scalability, full control of all parameters, and a debugging experience, setting up PgBouncer on Azure VMs might be an alternative.
162157

0 commit comments

Comments
 (0)