QuorumWiki
Jugar

Pooler de conexiones

Muchas conexiones de la aplicación comparten 20 conexiones a la base de datos. Agrupa contra un único host.

Esta página aún no está traducida al español.

The Connection Pooler stands for PgBouncer: a proxy that lets many app connections share a few database connections.

When to place it#

  • Place it when the Database refuses connections: errors show refused while its CPU is not full. This happens when you add App Servers, or when a runtime opens a large pool per process.

The Connection Limit Sandbox shows it.

SandboxLímite de conexionesAtiende todas las peticiones durante 90 segundos.

How it works#

Place it between your App Servers or Workers and the Database. It carries the point reads, writes, and transactions that use a database connection, and passes them on with almost no added latency. It does not carry search, object storage, or scans. It has a throughput limit of 10,000 queries a second at its first size, and each size step doubles it.

It takes one link out. A real PgBouncer reads no SQL and sends every connection to one host, so it cannot send reads to a replica and writes to the primary. To reach a Read Replica as well, link the pooler into an L4 Load Balancer (an L7 one reads HTTP and refuses queries), and the Load Balancer into the Database and each replica. The Load Balancer then splits reads by its algorithm, while writes go to the Database only.

Both pooled modes break session state the same way: prepared statements and SET at session level belong to a connection the client no longer holds. See connection pooling.

Options#

ControlValoresCuándo
ModoSesión / Transacción / SentenciaSiempre

Its mode sets how many Database connections it opens:

  • Transaction (the default): every client shares a small set of server connections. Code that keeps session state breaks, and a share of requests crash until your team finishes the "Drop session state" task on the Team page.

  • Statement: one server connection per statement. It shares the same small set, so it packs no tighter here. A transaction that spans several statements cannot run through it, so every checkout fails. Choose it only in a Design whose writes are single statements.

  • Session: one server connection per client. Nothing breaks, and it barely helps.

How it fails#

  • Without one, Connection exhaustion is much more likely. A deploy doubles every pool, and Postgres refuses the excess.

  • In transaction mode, crashes continue until the session-state task is done.

  • Overloaded, it drops queries before they reach the Database.

Instance failure#

  • Signs: The Connection Pooler's card goes grey, its Inspector reads "The host under this VM died. It still bills.", and the requests sent to it are stranded.

  • Do now: Press Replace in its Inspector and pay the price. It comes back cold.

  • Prevent: Run a second copy: Load balancing puts the copies behind a Load Balancer, and Health checks skip the dead host. A Standby (Zone section, needs Multiple zones) takes over by itself, with no click.

Zone outage#

  • Signs: Every Node in one zone goes grey at once.

  • Do now: Press Fail over on the banner, or on the Node's card. It needs Multiple zones and promotes the Node's Standby at once; the Node then keeps no standby until you give it one. A Node with no standby stays down until the incident ends, at most 120 sim seconds, and one with a standby also fails over by itself after a share of that time.

  • Prevent: Research Multiple zones, then put copies in different zones with the Zone setting. Give it a Standby.

Region outage#

  • Signs: Every Node in one region goes grey at once, and that region's board goes grey with them.

  • Do now: Press Fail over on the banner. It needs Multiple zones and a second open region, and starts the Node again in the nearest other region, cold, for the price of a replacement. Otherwise it comes back when the incident ends: 180 sim seconds in the catalog, 60 once the error budget counts.

  • Prevent: Research Multiple regions and GeoDNS, then run a copy of it in a second region.

Tips#

  • Queue the "Drop session state" task as soon as you place a Pooler in transaction mode.

  • Link a Cache to the Pooler, not straight to the Database.

Reglas#

  • Cada copia adicional cuesta un 25% más que la anterior.
  • Al venderlo se devuelve el 50% de lo que costó su última copia.
  • Tiene 4 tamaños. Cada paso duplica su capacidad y su Gasto.

Funciona con#

Servidor de aplicaciones, Base de datos, Balanceador de carga, Caché, Réplica de lectura, Almacén de documentos, Worker, Función serverless

Términos de ingeniería#