Open WebUI PostgreSQL connection pool tuning

Size DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW across Open WebUI replicas so the total stays under PostgreSQL max_connections, and learn to read QueuePool timeout errors.

On this page

Why Open WebUI PostgreSQL connection pool tuning matters once you run several replicas

If your team runs Open WebUI on PostgreSQL across several replicas and sees intermittent errors under load, the first thing to check is connection arithmetic. Each replica holds its own connection pool, so the pool size per replica multiplied by the replica count must fit within PostgreSQL's max_connections, with headroom left for administration and background work. Every replica opens connections independently, so adding a replica raises the total demand on the database even when user traffic stays the same. A deployment that fit comfortably with two replicas can exhaust the server after a scale-out, and the symptoms often appear as sporadic failures rather than a clear outage.

The Open WebUI scaling guide requires PostgreSQL instead of SQLite for multi-instance deployments, because SQLite does not handle concurrent writes from multiple processes well. SQLite is a file-based database with no server process brokering connections, so several replicas writing to one file over a network share is the setup the guide warns against. The scaling guide's requirement is the starting point for this topic: once the database is a shared PostgreSQL server, connection capacity becomes a design input rather than a default you can ignore.

Confirm the current default values for DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW in the release you deploy, since they can change between versions, and do not assume the defaults fit your replica count. Also confirm the max_connections value on your PostgreSQL server, the number of replicas you expect at peak, and whether any other applications share the same database. Record these four numbers together before you change any setting, because the right pool size follows from them rather than from a general rule.

Pool settings and when each fits

This table compares the four settings that decide how many database connections Open WebUI can open and how many PostgreSQL will accept. Read each row as a separate limit: the application pool per replica, the overflow allowance, the server ceiling, and an external pooler in front of the database. The main takeaway is that the total across all replicas must fit under PostgreSQL's ceiling with room left for administration and background work.

SettingWhat it controlsFailure it preventsTrade-off when raising or lowering
DATABASE_POOL_SIZESteady number of connections each Open WebUI process keeps open to PostgreSQL. Confirm the exact variable name and default in your release.Opening a new connection for every request, which adds latency and churn under load.Higher values reduce waiting but multiply across replicas and consume PostgreSQL connection slots. Lower values cause queueing under bursts.
DATABASE_POOL_MAX_OVERFLOWExtra temporary connections a process may open above the pool size during peaks. Confirm the variable name and default in your release.Short spikes producing QueuePool timeout errors when the steady pool is fully checked out.Absorbs bursts but raises the worst-case connection count. Overflow connections are closed after use, so they add connection setup cost.
PostgreSQL max_connectionsServer-wide ceiling on client connections, shared by every application, replica, admin session and maintenance task.The server refusing new connections once the limit is reached, which appears as connection errors rather than pool timeouts.Raising it increases memory use per connection and can slow the server. Lowering it forces the application to queue, which is usually safer than overloading the database.
Replica count multiplierTotal application connections equal replicas multiplied by pool size plus overflow. Ask your team to calculate this from the deployed replica count.Replica scale-out quietly exhausting max_connections, especially after a rolling restart briefly doubles the count.More replicas increase capacity but also the connection total. Sizing must be rechecked whenever replicas change.
External pooler such as PgBouncerMultiplexes many client connections onto a smaller set of server connections in a pool mode you configure.Client connection storms exhausting the server while keeping application-side pools intact.Adds a component to deploy, monitor and secure. Some session-level features behave differently under transaction pooling, so confirm compatibility with your Open WebUI release before use.
Idle and long-held connectionsConnections kept open by idle processes, long migrations or stuck sessions. Review server-side activity during testing.Pool slots held by work that is not serving requests, reducing capacity for active users.Stricter timeouts free slots sooner but can interrupt legitimate long operations such as large uploads or migrations.

How to size the pool and verify it before go-live

This sequence turns a guess about connection counts into a pool setting that fits the PostgreSQL server's limit, with a load test that confirms the number holds before users arrive.

  1. Inventory replicas, workers and pool settings

    The platform team lists every Open WebUI container that connects to the same PostgreSQL database, the Uvicorn worker count in each, and the current DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW values. Include background jobs, migration containers and any staging copy that points at production. Done when the team has one table with a row per running process and its configured pool values, checked against the deployment manifests rather than memory.

  2. Read max_connections and reserved slots

    A DBA or the platform owner runs SHOW max_connections; on the PostgreSQL server and records the value together with superuser_reserved_connections, which PostgreSQL holds back for administrators. Confirm the value against the server's configuration file, since a managed service may set it differently from the default. Done when the usable connection ceiling is written down and the owner has confirmed who can change it.

  3. Count connections from other clients

    Run a query against pg_stat_activity grouped by application_name, user and client address during normal business hours. Record backup agents, reporting tools, monitoring exporters, other applications and admin sessions. Done when the team knows the steady non-Open WebUI connection count and the peak, because those connections come out of the same ceiling as the Open WebUI pools.

  4. Compute the per-process budget with headroom

    Subtract the reserved slots and the non-Open WebUI peak from the ceiling, then leave a margin for maintenance sessions and failover. Divide what remains by the number of processes from step one, since each process can open up to pool size plus overflow connections. Treat the result as a ceiling for the planned process count, not a target to fill. Done when the team has a written calculation showing the sum of all process maximums stays below the usable limit, and a second person has reviewed the arithmetic.

  5. Set pool size and overflow, then restart

    Apply the chosen DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW values to the deployment configuration, keeping the same values across replicas so the budget holds. Roll the change out one replica at a time with the restart procedure your team already uses. Done when every process reports the new values in its startup configuration and the pods are healthy.

  6. Verify active connections under a load test

    Run a load test that reproduces expected concurrent chats and document uploads against a staging copy with the same replica count and pool settings. Sample pg_stat_activity during the peak, grouping by application_name and state, and compare the observed Open WebUI connection total with the calculated budget. Done when the observed peak stays below the budget with the planned headroom and no QueuePool timeout errors appear in the application logs.

  7. Document the rollback path before go-live

    Record the previous pool values, the exact configuration change needed to restore them, and the owner who can apply it. Include the signal that triggers rollback, such as recurring QueuePool timeout messages or PostgreSQL refusing new connections with a too-many-clients error. Done when the rollback steps have been rehearsed on staging and the on-call team has the runbook.

Reading QueuePool timeout errors in Open WebUI logs

A QueuePool timeout means a request waited for a database connection and none came free within the pool timeout. The causes below range from simple undersizing to leaks and host problems, and they look alike in the logs. Work through them in order, starting with the replica count and connection budget, because those are the cheapest to confirm.

Pool too small for concurrency

Each replica holds its own pool, so a pool that is fine for a handful of chats can exhaust under a busy hour. Look for QueuePool timeout entries that cluster at peak times and appear on one replica while others stay quiet. First check the effective DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW values in each container's environment, then compare the number of simultaneous requests you see in the access logs during the failure window.

Scaling Open WebUI docs

Long-held connections from slow requests

A request that holds a connection while it waits on a model, an embedding job or an external tool keeps that connection checked out for the whole wait. The pool then runs dry even though the database is idle. Look for timeouts that coincide with long streamed responses or document processing, and check whether those requests open a session before the slow external call rather than after it. Confirm with the team that owns the application code how sessions are scoped in your release.

Too many replicas for max_connections

The total connection demand is the pool ceiling multiplied by the replica count, plus any workers, migrations, admin sessions and monitoring. When that sum exceeds PostgreSQL max_connections, new connections fail at the server, and the application may report pool exhaustion instead. Compare the replica count against max_connections and against the current count from pg_stat_activity. Confirm the server-side limit with your DBA, since your managed or packaged setup may reserve some slots.

PostgreSQL high availability docs

Connection leaks from tools or extensions

Custom Python tools, functions or extensions that open database sessions without closing them reduce the free pool slowly, so timeouts appear hours after a deployment and grow over time. Look for an active connection count that rises steadily and does not fall after load drops, along with idle-in-transaction sessions in pg_stat_activity. Review any custom code that imports the database layer, and confirm that each session is released on every code path, including errors.

Slow database host

When the database is slow to answer, each query holds its connection longer, so the pool drains even at normal request volume. Look for query latency rising at the same time as timeouts, disk or CPU saturation on the database host, or lock waits in pg_stat_activity. Check host metrics and slow query logs before changing any pool setting, because a larger pool on a slow host only moves the queue into the database.

Pooler misconfiguration

A connection pooler such as PgBouncer placed between Open WebUI and PostgreSQL can have its own client and server pool limits, and a pool mode that does not match the session behavior of the application. Timeouts that appear only after a pooler was added, or that mention the pooler rather than PostgreSQL, point here. Confirm the pooler's client and server limits, its pool mode, and whether it queues clients when the server pool is full, using the PgBouncer documentation as the reference for your version.

PgBouncer documentation

How replicas, pool and PostgreSQL connections fit together

The diagram starts with users reaching a load balancer, which spreads requests across several Open WebUI replicas. Each replica holds its own SQLAlchemy pool sized by DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW, and those connections either go straight to PostgreSQL or pass through PgBouncer. Every path ends at one PostgreSQL primary, where max_connections is the shared ceiling for all replicas together. Redis and shared file storage sit beside the database as separate dependencies that do not draw from the pool, so check the pool arithmetic against the database limit, not against the number of replicas alone.

Replica pools converge on one PostgreSQL primary, with Redis and file storage outside the pool.

Security and operational considerations for database connections

Pool sizing only matters if the database behind it is locked down and watched. The cards below cover the credentials, transport, roles, network paths and connection telemetry that sit around the pool settings on every replica. Several Open WebUI specifics are noted for confirmation against your release rather than assumed.

Scoped credentials for the Open WebUI user

Give Open WebUI its own PostgreSQL login rather than a shared administrative account, and keep the password in a secret store, not in a plain environment file checked into version control. Every replica uses the same database URL, so one rotated credential must reach all of them at once. Confirm in your deployment how the connection string is supplied and whether a rotation requires a rolling restart of replicas.

Encrypted client connections

Require TLS between each Open WebUI replica and PostgreSQL so queries and credentials do not cross the network in clear text, especially when replicas and the database sit in different subnets or clusters. Confirm how your Open WebUI version passes SSL parameters in the database URL, and test that a connection without TLS is refused on the server side.

SCRAM password authentication

PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM, so set password_encryption to scram-sha-256 and confirm the Open WebUI login role was created with a SCRAM hash. Check pg_hba.conf for any md5 entries left over from an older cluster, since they will keep working until removed. Confirm that your PostgreSQL client libraries negotiate SCRAM with the server version you run.

PostgreSQL 18 release notes

Least-privilege database roles

Grant the Open WebUI role access only to the database it uses, and avoid superuser, CREATEROLE and database-creation rights. Confirm during testing whether the application needs to create extensions such as pgvector, since that step may need a separate, short-lived migration role. Review grants again after each Open WebUI upgrade, because schema changes in a new release can require different privileges.

Network restriction of port access

Allow the PostgreSQL port only from the subnets or security groups where Open WebUI replicas run, and from your administrative bastion. Keep the database off public addresses and, where your platform supports it, restrict listen_addresses to the interfaces it needs. Pool sizing does not protect the database if any host on the wider network can open connections.

Connection count monitoring and alerts

Track the total number of client connections against max_connections, along with how many are idle and how many sit in a waiting state. Alert well before the limit is reached, because a rising count after a scale-out often signals that the pool sizes multiplied across replicas exceed what the server allows. Confirm which Open WebUI log lines report QueuePool timeouts in your version so you can correlate them with database-side counts.

Support per major version
5 years

Questions buyers ask about pool tuning and outside help

Can our own team tune the Open WebUI PostgreSQL connection pool without outside help?

Yes, if your engineers can read PostgreSQL connection statistics, run a load test against a staging copy and change environment variables in a controlled rollout. The settings themselves are simple, DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW, but the right values depend on how many replicas you run, how many connections PostgreSQL allows and how your workload behaves at peak. Teams that have not run this kind of exercise often spend the most time on the load test and on confirming that the database is not the real bottleneck. An outside team is useful when you want the sizing reasoned through against your environment and documented for the next operator.

What drives the effort of a pool tuning exercise?

Effort rises with the number of replicas, because each replica holds its own pool, and with how spiky your load is. Other drivers include whether you already run a connection pooler, how much visibility you have into PostgreSQL metrics, and how many other applications share the same database server. Each one changes how many test runs you need and how many findings must be checked against the database itself. Ask whether your metrics retain enough history to show peak connection counts, since missing history usually adds a round of testing.

How long does a pool tuning engagement take?

It depends on scope, and it cannot be estimated responsibly without seeing your environment. The main variables are the number of replicas and databases, the state of your monitoring, the availability of load test windows and how many change cycles your change process requires. A fixed-scope proposal sets the timeline in writing once those facts are known. Ask any provider for the list of environment facts they need before giving a duration.

What do we need to provide for a pool tuning engagement?

The work needs a few specific inputs from your side:

  • Read access to PostgreSQL statistics, including the current max_connections value and connection counts over time
  • Access to the Open WebUI deployment settings, the replica count and the orchestration configuration
  • Metrics from your monitoring system covering connections, latency and error rates for representative periods
  • Test windows in a staging environment that matches production in size and configuration, and a production window for the final change
  • A named owner who can approve configuration changes and confirm the application behavior afterward
Is PgBouncer required for Open WebUI connection pooling?

No. PgBouncer is one option for reducing the number of connections that reach PostgreSQL, and it becomes more useful as replica count grows. Open WebUI can work with its own pool settings alone if the total connections across all replicas stay within the limit PostgreSQL allows, with room for administrative sessions. Whether to add a pooler depends on your replica count, your connection limits and how your team wants to operate the extra component. Check the PgBouncer documentation and your PostgreSQL version before choosing a pooling mode, since transaction pooling can affect how some session features behave.

What does a fixed-scope quote for pool tuning cover?

A fixed-scope quote lists the environment reviewed, the questions the work will answer, the test runs and configuration changes included, and the documents delivered. It should also name what is excluded, such as database upgrades, replication changes or capacity purchases, and what you must provide. Deliverables usually include the sizing calculation, the final settings for each replica, a runbook for reading QueuePool timeout errors and a list of metrics to watch. Ask for the written scope and acceptance criteria before work starts, since they define what the price covers.

What cost components should we expect in an outside pool tuning project?

The main cost is the time of the engineers who review the environment, run the tests and write the documentation. Some costs are one-time, such as the initial sizing and the runbook. Others recur if you later add replicas, change the database or want retesting after upgrades. Costs also grow with the test environment you need, because a staging system that matches production adds infrastructure your team must pay for. Ask the provider to separate one-time work from optional retainers so you can compare options fairly.

Who owns the database and the final configuration after the engagement?

Your organization owns the PostgreSQL server, the Open WebUI deployment and the resulting configuration. The written scope should say who makes the production change, who keeps the runbook current and who responds when pool errors return. Agree on this before the work starts so the settings do not drift after the engagement ends.

How PostgreSQL upgrades and failover change the pool plan

Your pool settings are tied to the PostgreSQL cluster behind them, so any change to that cluster is a reason to recheck them. A minor PostgreSQL release never changes the internal storage format. Updating means replacing the executables and restarting the server, which drops every open connection. Each Open WebUI replica then has to reconnect through its pool, and the restart window is when a burst of new connections can hit max_connections at once. Confirm with your DBA how long a restart takes in your environment and whether your replicas recover cleanly without manual intervention.

A major upgrade is a different exercise. PostgreSQL documents three routes: dump and restore, pg_upgrade, and logical replication. Logical replication works between different major versions and can limit downtime to several seconds, which is the route most teams with strict availability needs will evaluate. The cutover moves the application to a new endpoint, so the pool plan for the new primary (host, port, connection counts per replica) must be confirmed before the switch. Check the PostgreSQL upgrading documentation for the steps that apply to your chosen method.

PostgreSQL does not detect a primary failure or promote a standby on its own, so automatic failover needs external tools. Whatever tool you choose, failover changes which server answers, and it can change the number of connections each server accepts. After any failover or major upgrade, rerun the arithmetic: replicas multiplied by DATABASE_POOL_SIZE plus DATABASE_POOL_MAX_OVERFLOW, compared with the new server's max_connections and the connections reserved for administration. Then watch for QueuePool timeouts during the first hour of traffic, since they are the first sign that the new layout does not fit.

How DeployOpen works on this

DeployOpen plans, implements, tests and documents Open WebUI database tuning inside your own infrastructure, so pool sizing, PostgreSQL limits and error handling are agreed in writing before any change reaches production. The work is delivered as a fixed-scope engagement with deliverables and timelines confirmed up front, and ongoing support is available as a retainer.

How we scope

  • Inventory the Open WebUI replicas, worker counts and PostgreSQL instances that will share connection capacity.
  • Confirm the current max_connections value, any connection pooler in front of PostgreSQL, and the PostgreSQL major version in use.
  • Agree in writing which pool settings, error signatures and load tests fall inside the fixed scope and which do not.

How we build

  • Calculate a starting DATABASE_POOL_SIZE and DATABASE_POOL_MAX_OVERFLOW for each replica against the agreed connection budget.
  • Set and test the environment configuration through the deployment method you run, such as Docker Compose, Kubernetes or a VM.
  • Run load tests that reproduce concurrent chat and upload traffic and record QueuePool timeout and connection error rates.

How we hand over

  • Deliver a documented connection budget that shows how replica count changes pool totals and the PostgreSQL limit.
  • Provide a runbook for reading QueuePool timeout errors, with the log lines to check and the first corrective steps.
  • Walk your platform and database teams through the configuration, test results and rollback steps before closing the engagement.

How we support

  • Retest pool settings after Open WebUI upgrades, replica changes or PostgreSQL major version upgrades.
  • Review connection usage trends with your team on a retainer schedule agreed in the contract.
  • Extend the connection budget when new replicas, workers or services that use the same PostgreSQL server are added.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.