A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-pgbouncer below:

PgBouncer in Azure Database for PostgreSQL flexible server - Azure Database for PostgreSQL

APPLIES TO: Azure Database for PostgreSQL - Flexible Server

Azure Database for PostgreSQL flexible server offers 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.

PgBouncer runs on the same virtual machine (VM) as the database server for Azure Database for PostgreSQL flexible server. 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.

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.

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.

PgBouncer in Azure Database for PostgreSQL flexible server supports Microsoft Entra authentication (Azure AD).

PgBouncer with elastic clusters (preview)

PgBouncer is also available for elastic clusters. Each node in an elastic cluster has its own instance of PgBouncer. After being enabled, 6432 port leads to the PgBouncer running on the currently designated coordinator node. You can also use port 8432 to load balance your connections against PgBouncer instances running on all nodes in the cluster.

Enable and configure PgBouncer

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.

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.

You can configure PgBouncer settings by using these parameters.

Note

The following list of PgBouncer server parameters is visible on the Server parameters pane only if the pgbouncer.enabled server parameter is set to true. Otherwise, they're deliberately hidden.

Parameter name Description Default pgbouncer.default_pool_size Set this parameter value to the number of connections per user/database pair. 50 pgbouncer.ignore_startup_parameters Enter a comma-separated list of parameters that PgBouncer can ignore. For example, you can let PgBouncer ignore the extra_float_digits parameter. Some parameters are allowed; all others raise an error. This ability is needed to tolerate overenthusiastic Java Database Connectivity (JDBC) wanting to unconditionally set extra_float_digits=2 in startup packets. Use this option if the library that you use reports errors such as pq: unsupported startup parameter: extra_float_digits. pgbouncer.max_client_conn Set this parameter value to the maximum number of client connections to PgBouncer that you want to support. The default is 5000, with an allowable range from 1 to 50,000 5000 pgbouncer.max_prepared_statements When this is set to a non-zero value PgBouncer tracks protocol-level named prepared statements related commands sent by the client in transaction and statement pooling mode. 0 pgbouncer.min_pool_size Add more server connections to pool if below this number. 0 pgbouncer.pool_mode Set this parameter value to TRANSACTION for transaction pooling (which is the recommended setting for most workloads). transaction pgbouncer.query_wait_timeout Maximum time (in seconds) queries are allowed to spend waiting for execution. If the query is not assigned to a server during that time, the client is disconnected. 120 pgbouncer.server_idle_timeout If a server connection has been idle more than this many seconds it will be dropped. If 0 then timeout is disabled. 600 pgbouncer.stats_users Comma-separated list of database users that are allowed to connect and run read-only queries on the pgBouncer console.

For more information about PgBouncer configurations, see the pgbouncer.ini documentation.

Version of PgBouncer

Currently, the version of PgBouncer deployed on all supported major versions of the engine (17, 16, 15, 14, 13, 12, 11), in Azure Database for PostgreSQL flexible server, is 1.22.1.

Benefits

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

Monitoring PgBouncer Metrics

You can use PgBouncer metrics to monitor the performance of the PgBouncer process, including details for active connections, idle connections, total pooled connections, and the number of connection pools. Each metric is emitted at a 1-minute interval and has up to 93 days of history. Customers can configure alerts on the metrics and also access the new metrics dimensions to split and filter metrics data by database name.

How to enable PgBouncer metrics List of PgBouncer metrics Display name Metric ID Unit Description Dimension Default enabled Active client connections client_connections_active Count Connections from clients that are associated with an Azure Database for PostgreSQL flexible server connection. DatabaseName No Waiting client connections client_connections_waiting Count Connections from clients that are waiting for an Azure Database for PostgreSQL flexible server connection to service them. DatabaseName No Active server connections server_connections_active Count Connections to Azure Database for PostgreSQL flexible server that are in use by a client connection. DatabaseName No Idle server connections server_connections_idle Count Connections to Azure Database for PostgreSQL flexible server that are idle and ready to service a new client connection. DatabaseName No Total pooled connections total_pooled_connections Count Current number of pooled connections. DatabaseName No Number of connection pools num_pools Count Total number of connection pools. DatabaseName No Considerations for using the PgBouncer metrics

To learn more, see PgBouncer metrics.

Admin console

PgBouncer also provides an internal database called pgbouncer. When you connect to that database, you can run SHOW commands that provide information on the current state of PgBouncer.

To connect to the pgbouncer database:

  1. Set the pgBouncer.stats_users parameter to the name of an existing user (for example, myUser), and apply the changes.

  2. Connect to the pgbouncer database as this user and set the port as 6432:

    psql "host=myPgServer.postgres.database.azure.com port=6432 dbname=pgbouncer user=myUser password=<password> sslmode=require"
    

After you're connected to the database, use SHOW commands to view PgBouncer statistics:

For more information on the PgBouncer SHOW commands, see Admin console.

Switching your application to use PgBouncer

To start using PgBouncer, follow these steps:

  1. Connect to your database server, but use port 6432 instead of the regular port 5432. Verify that this connection works.

    psql "host=myPgServer.postgres.database.azure.com port=6432 dbname=postgres user=myUser password=<password> sslmode=require"
    
  2. Test your application in a QA environment against PgBouncer, to make sure you don't have any compatibility problems. The PgBouncer project provides a compatibility matrix, and we recommend transaction pooling for most users.

  3. Change your production application to connect to port 6432 instead of 5432. Monitor for any application-side errors that might point to compatibility issues.

PgBouncer in zone-redundant high availability

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.

Using PgBouncer with other connection pools

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.

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.

Limitations

Important

The parameter pgbouncer.client_tls_sslmode for the built-in PgBouncer feature has been deprecated in Azure Database for PostgreSQL flexible server.

When TLS/SSL for connections to Azure Database for PostgreSQL flexible server 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 and SSL in Azure Database for PostgreSQL flexible server.

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.

Limitations and considerations

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4