Configuring a Connection Pool
A connection pooler is a software component that manages database connections. This can help in multiple ways to improve resource utilization, help with load balancing or failover, and can greatly reduce transaction times. In this blog post, we’re going to see what a connection pooler is and how to configure it.

A connection pooler is a software component that manages database connections. This can help in multiple ways to improve resource utilization, help with load balancing or failover, and can greatly reduce transaction times. In this blog post, we’re going to see what a connection pooler is and how to configure it.
What a Connection Pooler Is and Why It’s Useful
Opening a connection to the database takes many steps. We need to connect to the server and perform the initial handshake, agree on the encryption and connection settings, and then keep the new connection resource across all the layers (network driver, OS layer, database layer, etc.). Each connection consumes memory which size depends on the database engine. For PostgreSQL, this can be even 1.3MB of memory for one connection. Opening a connection also takes time as we need to negotiate the settings of the new connection.
If we keep opening a new connection for each SQL query, we may cause multiple issues for the database server:
Opening connections takes time and resources, so our transactions are slower
We may exceed the limit of the active connections (which by default can be set to something like a hundred connections)
Database may consume more memory which may negatively affect cache hit ratio and free memory available for queries
Instead of opening a new connection for each SQL query, we can pool the connections. We can configure the connection pooler that keeps the amount of connections and reuses them for all the clients. This way our application connects to the pooler instead of the database directly, and then the pooler connects to the database. This brings multiple advantages:
The connection pooler keeps the connections open for much longer which reduces the overhead of opening and closing the connections on the database end and reduces latency.
We can get load balancing between the connections or even between databases which increases performance.
The pooler can maintain a stable number of connections, so we avoid the issue of too many active connections which reduces the resource usage.
The pooler can redirect the connections between the primary and the standby servers to provide a failover which increases stability and scalability.
The pooler can store the password to the database in a central place which increases the security.
The pooler can cache the results to improve the query performance.
The connection pooler also has some disadvantages:
It’s yet another component in our system that may become a point of failure.
Network latency may increase slightly due to another network hop between the application and the database.
An inefficient connection pooler may become a bottleneck.
We need to tune and maintain the connection pooler which increases the maintenance burden.
Different Types of Connection Pooling
There are many ways to implement connection pooling. In this section, we take a look at various implementation details.
External or Internal Connection Pooler
In a typical case, we connect from our application to the database. We can now put a connection pooler in one of two places: in the application itself or somewhere between the application and the database.
Putting the connection pool in the application (application-side connection pooler) can be very easy as many ORMs or database drivers support that out of the box. For instance, JDBC supports that with c3p0 and ODBC supports that out of the box. This brings many benefits. We don’t need to install and maintain any additional components as the pooler lives inside the application. We only need to deploy the new version of the application and we get the pooling ready. This also reduces the network latency, as we don’t have any additional network hops (everything lives inside our application).
Unfortunately, the application-side connection pooler has some drawbacks. The biggest one is that it’s configured for one application only. If we have many applications (especially in a distributed environment), then we need to configure the pooler in many places. Not to mention that we may still hit the connection count limit on the server side as the poolers don’t know about each other. Having many connection poolers also causes higher resource usage and is typically less performant.
We can also use an external connection pooler that sits somewhere between the application and the database. This can work with any number of applications and lets us precisely control the connection limit. A centralized connection pooler can also control resources better and let us achieve failover or load distribution.
An external connection pooler also has some drawbacks. First and foremost, it’s yet another component that we need to install, configure, tune, and maintain over time. We also need to reconfigure every application to use the connection pooler (which should be as simple as changing some connection strings and redeploying the application). The external pooler also adds some network latency as it is yet another network component between the application and the database.
The external connection pooler can also become a point of failure. If the pooler is down for whatever reason, applications cannot connect to the database anymore. If the pooler is slow or inefficient, then it affects all the applications using it. Therefore, the pooler must be of a high quality to not deteriorate the overall performance.
Types of Pooling
Each pooler needs to decide on how to assign connections to the clients. There are generally three approaches.
The first one is session pooling. In this approach, the connection is assigned to the client for the duration of the session (so until the client disconnects or a timeout is reached). This is the easiest approach, however, this effectively limits the number of clients as typically each client consumes one connection.
The next solution is transaction pooling. In this approach, the pooler assigns the connection for each transaction and only for the transaction duration. If a client wants to run another transaction, they need to get another connection (and may need to wait for some other connection to be available). This allows the pooler to handle more clients and is the recommended approach.
The last approach is to assign the connection for each SQL statement independently. In theory, this brings the highest flexibility and connection utilization. However, this causes one transaction to span across many connections. Since many transaction settings are tied to the connection, this may become a technical limitation.
Connection Pooling Solutions
Depending on the database type you use, there may be some built-in solutions, or you may need to configure them manually. Let’s see some examples.
Built-in Solutions
Depending on your infrastructure provider, you may be able to use built-in or nearly-built-in solutions:
Neon PostgreSQL database has a built-in PgBouncer
Supabase has a built-in Supavisor
Azure database for PostgreSQL supports built-in PgBouncer
DigitalOcean’s PostgreSQL includes PgBouncer
Azure database can be used with ProxySql
Azure database can be used with Heimdall Database Proxy
ADO.NET supports a built-in connection pool
Oracle supports Universal Connection pool for JDBC
Oracle Autonomous Database supports Database Resident Connection Pool
External Solutions
There are many external solutions that you can use:
Amazon RDS Proxy
Pgpool
PgBouncer
odyssey
Heimdall Database Proxy
ProxySQL
pgcat
Case Study: Configuring PgBouncer
In this example, we’re going to examine PgBouncer.
We start by installing it as in the documentation.
We then need to configure it. The most important settings are:
pool_mode: How to handle connections; we can use transaction
max_client_conn: This configures how many clients can connect to the connection pooler
default_pool_size: Configures how many server connections are allowed for each user database
min_pool_size: How many standby connections to keep
After configuring the pooler, we can verify its performance with pgbench:
pgbench -c 10 -p -j 2 -t 1000 database_name
PgBouncer can easily increase the number of transactions per second by 60%, as shown in benchmarks:
Benchmarking PostgreSQL connection poolers: PgBouncer, PgCat and Supavisor
Improve database performance with connection pooling
Supercharging PostgreSQL with PgBouncer
Summary
Connection poolers can improve performance and reduce resource consumption. There are many built-in solutions that we can easily use with our databases, no matter where we host them and what database engine we’re working with. We need to keep in mind that the connection pooler is yet another point of failure and needs to be handled with care. Well-configured connection pooler can nearly double the number of transactions per second which greatly improves the performance.
The above is the detailed content of Configuring a Connection Pool. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
What is inflation
Jun 26, 2025 pm 06:37 PM
Inflation is a phenomenon of general price increases, including demand-driven, cost-driven and currency super-engineering; its impacts include shrinking deposits, unable to catch up with prices, and loans becoming "favorable"; response methods include appropriate investment, increasing income sources, controlling consumption rhythms and paying attention to policy trends.
What is AI
Jun 26, 2025 pm 09:01 PM
The core of artificial intelligence is algorithms, especially models that can learn laws from data, such as deep learning. It trains the system through a large amount of data, allowing it to make judgments on new situations, such as face recognition and chatbots. AI is not really intelligent, but statistical methods that mimic human behavior. Common applications include voice recognition (such as Siri), image recognition (such as Alipay face-scanning payment), recommendation systems (such as TikTok and Taobao recommendations), and autonomous driving. AI's capabilities have boundaries, it can only work within the scope of training data, has no real awareness, and relies on a large number of computing resources. When looking at AI, it should be rational. It is an efficient tool but not perfect. It can be used to improve efficiency, but it also needs to be wary of its limitations.
What is my IP address
Jun 26, 2025 pm 05:49 PM
YourIPaddressisessentialforinternetconnectivityandnetworkmanagement.TocheckyourpublicIPaddress,search“WhatismyIP?”onGoogle,useasmartphonebrowser,orvisitdedicatedwebsiteslikewhatismyipaddress.com.ForyourlocalIPaddress,followthesesteps:1)OnWindows,open
How to take a screenshot
Jun 26, 2025 pm 09:13 PM
Screenshot methods vary depending on the device. Common operations are as follows: 1. Windows: PrtScn full screen, Alt PrtScn screenshots the current window, Win Shift S free selection screenshots, Win PrtScn automatically saves; 2. Mac: Shift Cmd 3 full screen screenshots, Shift Cmd 4 selection or click window screenshots; 3. iPhone: Press the power home button model with Home button, and press the power volume plus key for the full screen model with Power Volume; 4. Android: Generally, the power volume down key, and some brands support gesture screenshots; 5. Special needs can be used to scroll screenshots, screen recording functions or third-party tools such as Snagit and Lightshot. Master the commonly used shortcut keys to be familiar
How to write a resume
Jun 27, 2025 am 02:16 AM
The key to writing a good resume is to clarify the goals, concise structure, and focus the content. First, the resume should be tailored for specific positions, adjust the content according to the position requirements, highlighting the matching skills and experience; second, the structure should be clear, including contact information, personal profile, experience and other modules, and distinguish them with titles and boldness to avoid large paragraphs of text; third, the experience description should be spoken with facts and data, and the verbs should be started with digital quantization and achievement-oriented methods to show actual value; finally, pay attention to the details of the layout, unify the font and spacing, use PDF format, and standardize the name of the file to improve professionalism. Repeated modifications or asking others to check will help improve the quality of your resume.
How to convert PDF to Word
Jun 27, 2025 am 02:18 AM
The key to converting PDF to Word is to select the right tool and pay attention to the format preservation. ① Use Adobe Acrobat to directly export to .docx, which is suitable for text-type PDF and is not easy to mess with. The operation steps include opening the file, clicking "Export PDF", selecting the format and downloading and checking; ② Online tools such as Smallpdf and iLovePDF are suitable for daily simple conversion, but you need to pay attention to privacy risks and possible format confusion; ③ New version of Word supports direct import of PDF, which is suitable for situations where only small edits are required. The operation is to insert files and automatically identify content by Word; ④ Scanned files must first use OCR tools to identify text, and pay attention to details such as font changes and misalignment of column tables. It is recommended to manually adjust after conversion to ensure that
How to check my graphics card driver version
Jun 30, 2025 am 12:29 AM
If you want to view the graphics card driver version on your computer, you can do it by: 1. Use Device Manager to view: Win X to open the Device Manager, expand the display adapter, right-click the graphics card to select properties, and view the version and date in the driver tab; 2. View through DirectX diagnostic tool: Win R enter dxdiag to view the driver version and related graphics information in the display tab; 3. Use the official software of the graphics card manufacturer to query: such as NVIDIA's GeForceExperience, AMD's Radeon Software or Intel's Driver&Support Assistant, the main interface will display the current driver status and support updates; 4.
How to build a website
Jun 26, 2025 pm 10:56 PM
The key to building a website is to select the right tools and follow a clear process. 1. First, clarify the website goals and types, such as blogs, official websites, e-commerce, etc., and select adapter tools, such as WordPress, Shopify or Wix. 2. Register the domain name (recommended.com) and select a hosting platform, such as hosting, Vercel or Netlify. 3. Design the page structure, including homepage, about us, product pages, etc., to ensure that the layout is clear and easy to use. 4. After going online, continue to optimize content, check links, adapt to mobile terminals, and improve visibility through SEO. Follow the steps and the website construction can be completed within a few days.


