Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Why PostgreSQL Connection Pooling Gets Harder in Kubernetes

A routine deployment can exhaust PostgreSQL connections without any increase in traffic. New pods open their pools while terminating pods still hold database sessions. Add several worker processes per pod, and connection demand can grow much faster than the replica count suggests. Connection pooling is supposed to absorb that churn. The post Why PostgreSQL Connection Pooling Gets Harder in…

Why PostgreSQL Connection Pooling Gets Harder in Kubernetes

PostgreSQL connection pooling can become challenging in Kubernetes environments. When pods are created or terminated, their pool sizes and terminated sessions can lead to unexpected connection demands. Connection pooling is designed to handle this, but in Kubernetes, pool sizing, autoscaling, and termination are separate processes. Each component may operate independently, causing the database to run out of capacity.

Consider an API with 12 pods, each having four worker processes and a maximum of five database connections per worker. Directly connecting to PostgreSQL allows for 240 sessions. Adding more pods increases the potential connection count. Kubernetes advises factoring in pods that are about to be terminated, as they still hold database sessions.

The max_connections parameter in PostgreSQL determines the ceiling for connections. After accounting for reserved connections and an operational buffer, the remaining connections are distributed among workloads. An increase in max_connections means more shared memory allocations in PostgreSQL. The number of available connection slots does not dictate the efficiency of database queries.

To optimize connection usage, consider reducing the number of per-worker pools or using transaction poolers like PgBouncer. Each application pod can have its own pooler, connected nearby. A shared PgBouncer deployment allows application replicas to use a limited number of backends, but each PgBouncer replica has its own limits.

PgBouncer allocates pools based on database/user pairs. With reserve pools disabled and no aggregate connection limits, three PgBouncer instances with four database/user pairs can handle 240 backends. The max_client_conn parameter controls incoming client connections but does not set a limit for backends.

Configure max_db_connections and max_user_connections individually for each PgBouncer instance. Consider the total capacity, taking into account database aliases referring to the same PostgreSQL database and replicas sharing poolers during updates. If one pooler fails, other poolers should handle reconnecting clients within the current limits.

Uneven capacity distribution can occur. When using a single PostgreSQL database from multiple instances limited to 60 server connections each, the total available connections become 180 with four instances. PostgreSQL's statement_timeout cannot account for waiting time outside the transaction, so consider application compatibility checks and setting idle_in_transaction_session_timeout for better management.

Rewritten by urgent.news; may contain errors — check the original.

Source: cloudnativenow.com

Read the original at cloudnativenow.com →

Report a problem with this story

More in Tech

Our framework can mail paper letters. Most of the code decides when not to

On November 22 and 23 we merged a feature into Kumiko, our open source TypeScript framework, that lets an app send a real paper letter.

  • Kumiko framework adds feature to send paper letters
  • Letters printed via LetterXpress, delivered by Deutsche Post
  • Veridom app first to use functionality for statements and rent increases

ISACA AAISM (2026) Exam Study Guide for CISMs & CISSPs: Management-First Decision Rules + 5 CISM-Style Scenarios

The ISACA Advanced in AI Security Management (AAISM) credential is explicitly designed for experienced security leaders—holding an active CISM or CISSP is a mandatory prerequisite, and the live PSI…

  • Exam targets security leaders with CISM or CISSP, 90 MCQs in 150 minutes
  • 3 domains: Governance, Risk Management, Technologies & Controls
  • Management-first mindset emphasized over technical details

More from Monday 23 November →