Guide

Postgres connection limits, PgBouncer and replicas: where hosted Postgres breaks first

Connections are where hosted Postgres tends to run out first, before CPU or storage. This guide sets out the limit and the error, why each connection costs so much, what PgBouncer's modes break, and how RDS, Supabase, Neon, Azure and Cloud SQL differ.

45 minutes with an engineer: we review your workload and sketch the design.

  • Docs read 19 Nov 2026
  • PgBouncer in the OSStend design

Postgres connection limits come from max_connections, which defaults to 100 and is reserved in part for superusers. Each connection is a separate server process, so raising the limit costs memory, and a pooler such as PgBouncer is the usual fix. Hosted services set their own defaults and poolers. Facts read from vendor documentation, 19 Nov 2026.

Customers

  • Microsoft logo
  • Henry Schein logo
  • Enbridge logo
  • Gojek logo

Partners

  • Broadcom logo
  • Redis logo
  • VMware Tanzu logo
  • OSSeva logo

What are the Postgres connection limits?

The limit is max_connections, which the manual says defaults to typically 100. Some slots are held back for reserved use, and a standby must be set to the same value or higher than its primary, so the number your application can use is lower than the headline.

SettingDefaultWhat it does
max_connectionsTypically 100Total connection slots; changing it needs a restart. A standby must have the same value or higher, or queries are refused there.
superuser_reserved_connections3Final emergency reserve for superusers, after reserved_connections is used up.
reserved_connections0Slots for roles with the pg_use_reserved_connections privilege. Added in PostgreSQL 16.

Source: the connection settings of the PostgreSQL manual and the PostgreSQL 16 release notes, checked 19 Nov 2026.

When the slots run out, clients see FATAL: sorry, too many clients already, the message Azure documents for exceeding the limit (Azure limits, checked 19 Nov 2026). When only the reserved slots are left, ordinary roles see a message that begins remaining connection slots are reserved, and only roles allowed to use them can still log in.

Why does each Postgres connection cost so much?

Every connection is a separate server process, so idle connections still hold memory and slots, and active ones can each use several multiples of work_mem. Raising max_connections is cheap to type and expensive to run.

work_mem is per operation.
It defaults to 4MB and applies to each sort or hash table in a query, so one complex query can use it several times, and many sessions can do so at once; the manual says the total can be many times work_mem. hash_mem_multiplier defaults to 2.0, which lets hash operations use twice that (resource settings, checked 19 Nov 2026).
Idle is not free.
Azure's limits page says each connection, idle or active, consumes a significant amount of server resources, and that short-lived connections of under 60 seconds raise CPU through the cost of connecting and disconnecting (Azure limits, checked 19 Nov 2026).
The arithmetic.
An application with 20 instances and a pool of 10 each holds 200 connections before any batch job, migration or monitoring agent connects. Autoscaling makes that number move without anyone changing a setting.
45 minutes with an engineer: we review your workload and sketch the design, then price it.

PgBouncer pool modes, defaults and what breaks in transaction mode

PgBouncer pools server connections in three modes. Session mode holds a server connection for the whole client session, transaction mode only for the length of a transaction, and statement mode forbids multi-statement transactions. Transaction mode gives the most reuse and breaks session-level features.

SettingPgBouncer defaultMeaning
pool_modesessionWhen a server connection returns to the pool.
default_pool_size20Server connections per user and database pair.
max_client_conn100Client connections PgBouncer accepts; file descriptors can exceed it, so ulimit must cover the sum.
max_db_connections0 (unlimited)Cap on server connections to one database.
reserve_pool_size0 (off)Extra connections for waiting clients.
max_prepared_statements200Tracks protocol-level prepared statements in transaction and statement modes.
query_wait_timeout120 secondsHow long a query waits for a server connection before the client is disconnected.
server_idle_timeout600 secondsIdle server connections are closed after this.

Source: the PgBouncer configuration page, checked 19 Nov 2026. Hosted services often change these defaults; the provider table below shows how.

  • Never works in transaction mode: SET and RESET, LISTEN, WITH HOLD cursors, PREPARE and DEALLOCATE, temporary tables with PRESERVE or DELETE ROWS, LOAD, and session-level advisory locks (PgBouncer features, checked 19 Nov 2026).
  • What that means in code. ORMs that set search_path or timezone per connection, apps that use LISTEN for cache invalidation, and migration tools that take session advisory locks all need a direct connection or session mode.
  • Prepared statements. Protocol-level named statements work in transaction mode only when max_prepared_statements is above zero. Drivers that send SQL-level PREPARE do not.

Postgres connection limits by provider

Every hosted service sets its own default for max_connections and ships its own pooler, and the pooler's catch is usually where applications fail. The table lists what each provider's documentation says today.

ProviderDefault limit or formulaPoolerCatch
Amazon RDS for PostgreSQLLEAST({DBInstanceClassMemory/9531392}, 5000), changeable through the parameter groupRDS Proxy, a separate resourceSame VPC as the database and never publicly accessible; for replicas, attach it only to the writer. Pinning, below.
SupabaseNot stated on the page we readSupavisor shared pooler: session mode on port 5432, transaction mode on 6543; dedicated PgBouncer on 6543 for Pro and aboveThe shared pooler in transaction mode does not support prepared statements, so drivers need settings such as prepare: false. Direct connections use IPv6 unless the IPv4 add-on is bought.
Neon112 at 0.25 CU, 450 at 1 CU, 901 at 2 CU, 1802 at 4 CU, capped at 4000 from 9 CU; 7 reserved for the superuserPgBouncer in transaction mode through the -pooler host name; max_client_conn 10,000, default_pool_size 0.9 x max_connectionsPool size is set per user and database pair, so several roles multiply server connections. Use a direct connection for migrations, pg_dump and logical replication.
Azure flexible serverFor example 859 on a D2 (8 GiB), 1,718 on a D4 (16 GiB), 5,000 from D16; 15 reservedBuilt-in PgBouncer on port 6432: default_pool_size 50, max_client_conn 5000, transaction modeNot available on Burstable. It restarts with the server on a failover or scale, so existing connections are dropped. Azure advises against raising max_connections above the default.
Google Cloud SQLBy memory: 100 at 3.75 to under 6 GB, 400 at 7.5 to under 15 GB, 600 at 30 to under 60 GB, 1,000 from 120 GBManaged pooling on port 6432, transaction mode by defaultEnterprise Plus edition only, and turning it on for an existing instance restarts the database. Cloud Run is limited to 100 connections per database on the built-in connection.

Read from each provider's documentation, checked 19 Nov 2026. Plans change; check the linked page before relying on a number. Neon's cells cover the sizes on its page, Azure's cover General Purpose rows, and Cloud SQL's defaults depend on the largest instance in the primary chain (Cloud SQL quotas).

What is RDS Proxy pinning, and why does it end pooling?

Pinning is when RDS Proxy ties a client connection to one database connection until the session ends, because the session changed state that other clients must not inherit. A pinned connection is no longer shared, so pooling gains disappear if most connections are pinned.

What pins on PostgreSQL.
SET commands, PREPARE, DISCARD, DEALLOCATE and EXECUTE for prepared statements, temporary sequences, tables or views, cursors, LISTEN, loading a library module such as auto_explain, nextval and setval, session advisory locks, and a pooling library's DISCARD ALL reset query (RDS Proxy pinning, checked 19 Nov 2026).
What does not.
SET LOCAL inside a BEGIN and COMMIT block, and transaction-level advisory locks such as pg_advisory_xact_lock. set_config(name, value, true) does pin.
Other rules.
Any statement over 16 KB pins the session, PostgreSQL proxies do not support session pinning filters or CancelRequest (Ctrl+C in psql), and every proxy listens on port 5432 for PostgreSQL.
How to see it.
The CloudWatch metric DatabaseConnectionsCurrentlySessionPinned shows how many connections are pinned, and a proxy initialization query can hold SET statements every client runs.

Do read replicas fix Postgres connection limits?

Read replicas add capacity for read queries and their own connection slots, but they do not raise the primary's limit, and each replica must be configured with at least the primary's max_connections. Pooling is still needed in front of the writer.

The standby rule.
On a standby, max_connections must be the same or higher than on the primary, otherwise queries are not allowed there (PostgreSQL manual, checked 19 Nov 2026). Cloud SQL states the same for replicas (flags).
Where the pooler sits.
RDS Proxy attaches to the writer of a replicated instance, not a read replica (RDS Proxy, checked 19 Nov 2026), so read traffic needs its own pool design.
Changing the limit.
On Azure, changing max_connections needs a restart, and the service sets its default when the instance is provisioned: a later change of compute size does not alter it.
Hot standby feedback.
Letting long standby queries run without cancellation can bloat the primary; see the replication settings in the PostgreSQL high availability guide.

From our on-call engineers: connection checks before launch

These checks restate the PostgreSQL, PgBouncer and provider documentation read on 19 Nov 2026 as a pre-launch list. They are documentation, not a record of incidents, and we quote no customer figure.

  • Add up the maximum connections every application instance, job runner and monitoring agent can hold at peak autoscaling, then compare with max_connections minus both reserved settings.
  • Search the codebase for SET, LISTEN, session advisory locks and SQL-level PREPARE before choosing transaction mode; each is on PgBouncer's never-works list.
  • Send migrations and pg_dump over a direct connection, not the pooler, as the Neon and Supabase pages both advise.
  • Set query_wait_timeout deliberately: when the pool is full, clients wait, then are disconnected, and applications need a retry policy for that case.
  • Rehearse a failover with the pooler in the path, and check that it comes back by itself; Azure's built-in PgBouncer restarts with the server.

In an OSStend design for managed PostgreSQL, PgBouncer is named as the pooler where the application opens more connections than the server should hold, and pool sizes and modes are agreed in the design review. Compare that with the limits of turnkey plans in where turnkey services stop.

FAQ

What is the default max_connections in Postgres?

The manual says typically 100, or less if kernel settings do not allow it. Three more slots are reserved for superusers through superuser_reserved_connections.

What does sorry, too many clients already mean?

All connection slots are in use. Fix it by closing idle connections, adding a pooler such as PgBouncer or RDS Proxy, or, carefully, raising max_connections.

Is raising max_connections a good fix?

Rarely. Each connection is a server process holding memory, and work_mem applies per sort or hash operation, so a higher limit can push the server into memory trouble when connections become active. Azure advises against going above its default.

Which PgBouncer pool mode should I use?

Transaction mode for most web applications, because it gives the most reuse, as long as the code avoids session-level features such as SET, LISTEN and session advisory locks. Use session mode when it cannot.

What is RDS Proxy pinning?

RDS Proxy ties a client to one database connection when the session changes state, such as a SET command or a prepared statement. Pinned connections are not shared.

Can I use PgBouncer with prepared statements?

Yes for protocol-level prepared statements when max_prepared_statements is above zero. SQL-level PREPARE does not work in transaction mode.

PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. PgBouncer is the name of its open-source project. Amazon RDS and AWS are trademarks of Amazon, Google Cloud SQL of Google, Azure of Microsoft, Supabase of Supabase, Inc. and Neon of its respective owner. OSStend is not affiliated with or endorsed by any of them, and the names are used only to say which services the guide describes.

Talk to an engineer

Bring your connection numbers to an engineer

45 minutes: your pool settings, application counts and failure behaviour are reviewed, and an engineer says where the limit will bite.

  • A design sketch for your workload, not a plan menu
  • A zero-downtime cutover path for what you run today
  • A price for that design, after the review
See pricing →

Your request goes to the OSStend team. No newsletter sign-up.

Get a quoteTalk to an engineer
2Engines Optional
3Where should it run?
4What do you need?

Your request goes to the OSStend team. No newsletter sign-up.