Skip to content
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN DE
Let's talk

Connection Pooling

27. 04. 2024 Updated: 24. 03. 2026 1 min read intermediate

Each DB connection costs ~10MB RAM. Without pooling, you create hundreds of connections and the DB crashes.

Why Pooling

  • TCP handshake + TLS = ~100ms per connection
  • PostgreSQL fork per connection = ~10MB RAM
  • Max connections limit (default 100)
  • Connection reuse = dramatically lower latency

SQLAlchemy Pool

from sqlalchemy import create_engine engine = create_engine( “postgresql://user:pass@localhost/db”, pool_size=20, max_overflow=10, pool_timeout=30, pool_recycle=1800, # Recycle after 30 min )

PgBouncer

pgbouncer.ini

[databases] mydb = host=localhost port=5432 dbname=mydb [pgbouncer] pool_mode = transaction # Recommended max_client_conn = 1000 default_pool_size = 25

Key Takeaway

Always pool. SQLAlchemy pool_size=20, PgBouncer for sharing the pool across applications.

databaseconnection poolpostgresqlperformance
Share:

CORE SYSTEMS team

We build core systems and AI agents that keep operations running. 15 years of experience with enterprise IT.