This presentation, delivered at the Postgres Bangalore (PGBLR) Meetup-2 on June 29th, 2024, dives deep into connection pooling for PostgreSQL databases. Aakash M, a PostgreSQL Tech Lead at Mydbops, explores the challenges of managing numerous connections and explains how connection pooling optimizes performance and resource utilization.
Key Takeaways:
* Understand why connection pooling is essential for high-traffic applications
* Explore various connection poolers available for PostgreSQL, including pgbouncer
* Learn the configuration options and functionalities of pgbouncer
* Discover best practices for monitoring and troubleshooting connection pooling setups
* Gain insights into real-world use cases and considerations for production environments
This presentation is ideal for:
* Database administrators (DBAs)
* Developers working with PostgreSQL
* DevOps engineers
* Anyone interested in optimizing PostgreSQL performance
Contact info@mydbops.com for PostgreSQL Managed, Consulting and Remote DBA Services
Report
Share
Report
Share
1 of 88
Download to read offline
More Related Content
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
1. Scaling Connections in PostgreSQL
Postgres Bangalore(PGBLR) Meetup-2, 29th June 2024
- Aakash M
2. About Me
• PostgreSQL Tech Lead at Mydbops
• Expertise in databases like MySQL, SQL Server
• Performance tuning / Cost Optimization
• Tech Speaker on Open Source Events
• Active Blogger
• 6+ years of Experience
7. Application
What is Connection Pooling
• A pool of database connections
• Reusing unused connections from the pool
• Once purpose completes, return back to the pool
Connections to the database
8. Application
Connection
Pooler
What is Connection Pooling
• A pool of database connections
• Reusing unused connections from the pool
• Once purpose completes, return back to the pool
Connections to the Pool Connections to the database
9. Advantages of Connection Pooling
• Limiting connections to the database
• Overhead of opening/closing connection is reduced
20. Connection Pooler Available Since Setup Complexity Github Repository
pgbouncer 2007 Simple
https://github.com/pgbo
uncer/pgbouncer
Pgpool-II 2003 Medium to High
https://github.com/pgpo
ol/pgpool2
PgCat 2020 Medium
https://github.com/postg
resml/pgcat
Odyssey 2017 Medium to High
https://github.com/yand
ex/odyssey
pgagroal 2020 Low to Medium
https://github.com/agroa
l/pgagroal
Available Connection Poolers
26. Session Pooling Mode
• Once the client disconnections, Connection will be
released back to the pool
• Client and Server Connection is paired
27. Application
Connection
Pooler
Session Pooling Mode
• Once the client disconnections, Connection will be
released back to the pool
• Client and Server Connection is paired
Connection 1 Connection 1
Connection 2
Connection 2
28. Tranaction Pooling Mode
• Server Connection is assigned to Client whenever a new
transaction is started
• Released back to the pool when transaction closes
• Server and client connection is not paired
• No support for session variables and prepared statements
30. Statement Pooling Mode
• Server connection returns to pool immediately after
statement completes
• Multi statement is not supported
• Autocommit is enabled
35. Auth User
• Load user/password directly from the server
• No maintenance overhead
36. Auth User
• auth_user=”low_priv_user”
• auth_query=”select usename, passwd FROM pg_shadow
WHERE usename=$1”
• auth_file = /etc/pgbouncer/userlist.txt
cat /etc/pgbouncer/userlist.txt
"low_priv_user" "md5e10adc3949ba59abbe56e057f20f883e"
37. Parameter Description Default
Max_client_conn
Maximum number of client
connections allowed
100
Default_Pool_Size
How many server
connections to allow
20
min_pool_size
Minimum number of server
connections to maintain
0(Disabled)
Configuration
38. Parameter Description Default
Reserve_pool_size
Additional connections
allowed to the pool
0(Disabled)
Reserve_pool_timeout
If timeout, use additional
connections in the pool
0(Disabled)
Listen_port Port to listen 6432
Configuration
85. pgcat vs pgbouncer
Ref: https://tembo.io/blog/postgres-connection-
poolers
Ref: https://tembo.io/blog/postgres-connection-
poolers
86. Summary
• pgbouncer works well for simpler setups
• pgpool/pgcat has features and complex settings
• Ensure to test load balancing
• OS tuning is mandatory
• Do not forget HA
• Good for OLTP workload