Back to articles
PgBouncer: Database Connection Pooling That Actually Scales

PgBouncer: Database Connection Pooling That Actually Scales

via Dev.toAtlas Whoff

Why Your Database Runs Out of Connections PostgreSQL handles each connection with a dedicated OS process. At 100 connections, it's using 100 processes. At 500, memory is exhausted and queries slow to a crawl. Node.js apps compound this—each serverless function instance wants its own connection pool. PgBouncer sits between your app and PostgreSQL, multiplexing hundreds of app connections onto a small number of real database connections. App instances (500 connections) → PgBouncer → PostgreSQL (20 connections) PgBouncer Modes Session Mode One database connection per client connection. Same as no pooling. pool_mode = session Use only for compatibility. Provides no real benefit. Transaction Mode Database connection is released back to the pool after each transaction. pool_mode = transaction This is what you want. Each query or transaction gets a connection, then releases it. 500 app connections can share 20 database connections comfortably. Limitation: Prepared statements and SET variables

Continue reading on Dev.to

Opens in a new tab

Read Full Article
0 views

Related Articles