Sizing PostgreSQL for LiteLLM starts with sustained requests per second
A platform team that runs LiteLLM needs PostgreSQL for more than storage. Virtual keys, per-key and per-team budgets, and spend logs all live there, so every request that passes through the gateway can cause a database write. Size the instance by sustained requests per second and the spend writes they generate, not by the amount of data you expect to keep. PostgreSQL is LiteLLM's primary supported database, and virtual keys cannot run without one. Once more than one proxy instance runs, add Redis 7.0 or newer for shared rate limits, router state and cache, because each pod would otherwise keep its own copy of that state.
This page covers four decisions: the instance tier for a given request rate, how much storage the spend logs consume, how many database connections your worker and pod layout can demand, and when a read replica is worth its cost. LiteLLM's database sizing guidance groups workloads into request-rate bands, and the connection and storage math below follows from those bands. Ask your LiteLLM contact or check the current sizing page for the table that matches your release, because the bands are guidance rather than guarantees for your traffic pattern.
The rest of the deployment is covered on sibling pages: Kubernetes or cloud module installation, Redis requirements, the read replica routing setup, and PostgreSQL operations such as high availability, backups and major upgrades. Read this page first to pick the instance class, then use those pages to build it. Confirm your expected peak and sustained request rates with the teams that own your model traffic before you request a database quote, since the tier you choose drives both the instance cost and the connection budget.
How requests, spend writes and connections reach PostgreSQL
The diagram starts with client applications calling LiteLLM proxy pods inside your own infrastructure. Each pod holds its own connection pool to the primary PostgreSQL instance, and spend records are batched every 60 seconds into LiteLLM_SpendLogs. Key and budget reads are the only path that could move to an optional read replica, while Redis is shared across pods for rate limits and router state. Check the pool size per pod and the total connections the autoscaler can reach, because that multiplication is the first limit most deployments hit.
Request, spend write and connection paths from client apps to PostgreSQL inside your boundary.
Picking a PostgreSQL tier by sustained requests per second
This table maps LiteLLM's published database sizing tiers to sustained request rates, with the point where each tier tends to stop fitting. Read the rows as starting points: measure your own spend-write rate and logging settings before committing, because the tier that fits depends on them as much as on requests per second.
| Sustained RPS tier | When it fits | What grows first | What to confirm before committing |
|---|---|---|---|
| Up to 1K RPS (4 vCPU, 16 GB RAM, 200 GB SSD, 3000+ IOPS) | Single team or department gateway with modest, steady traffic and prompts left out of spend logs | Storage for LiteLLM_SpendLogs, then connection count as proxy replicas are added | Actual peak RPS, IOPS headroom on the chosen storage class, and whether store_prompts_in_spend_logs is enabled |
| 1K to 5K RPS (8 vCPU, 32 GB RAM) | Shared gateway for several teams where spend writes and key lookups compete for CPU and memory | CPU and memory on the primary, plus spend log storage at roughly 1 to 2 KB per request without prompts | Load test results at your real request mix, write latency under peak, and the connection budget across all replicas |
| Above 5K RPS (16+ vCPU, 64 GB RAM, 1 TB+ storage, read replica) | Organization-wide gateway with high traffic and long spend history retention | Write load on the primary and storage growth, which can reach about 10 times the base rate if prompts are stored | Whether a read replica is needed for read-heavy queries, replica lag tolerance, and the storage growth rate from your log retention policy |
What fills the database: spend logs, prompts and retention
Most of the storage growth in a LiteLLM database comes from one table, and two settings decide how fast it grows: whether prompts are stored and how long rows are kept. Size the instance from these figures before you size the CPU, because storage and backup costs follow the logging choices.
LiteLLM_SpendLogs dominates storage
LiteLLM_SpendLogs holds one row per logged request and is the main consumer of database storage. Without prompts, each logged request takes roughly 1 to 2 KB. Multiply that by your sustained request rate and retention window to get the table's growth per day, then add headroom for indexes and vacuum activity. Confirm the actual row size in a test environment, because it depends on metadata you send.
Database sizing docsPrompt storage multiplies row size
Enabling store_prompts_in_spend_logs stores the prompt content with each spend log row. LiteLLM's sizing guidance puts this at about ten times the row size without prompts. Decide this per environment before go-live, since changing it later does not shrink rows already written. Ask the team whether prompts from production users need to be retained at all, or whether metadata is enough for chargeback and audit.
- Size with prompts
- About 10x
Retention and volume compound the total
Total storage is roughly request volume times row size times the number of days kept. An illustrative case: at 100 requests per second, about 8.6 million requests arrive per day. At 1.5 KB each without prompts, that is about 13 GB per day, or roughly 390 GB over a 30-day window. The same traffic with prompts stored could reach several terabytes per month. Run this calculation with your own rates and retention before you choose an instance size.
Prompts widen data protection and backup scope
Stored prompts can contain personal data, credentials pasted by users and confidential business content. That brings the database into the scope of your data protection, access and retention controls, and it enlarges every backup and point-in-time recovery copy. Confirm who can query the spend log table, how long backups are kept, and whether restored copies are subject to the same deletion requests as the live database.
Connection pool math per worker, pod and replica
Total connection demand on PostgreSQL is set by one formula: database_connection_pool_limit multiplied by workers per instance multiplied by instances. The instance count is the number that moves, so the autoscaler's maxReplicas is the ceiling you should size against, not the average replica count you see on a quiet day. LiteLLM's sizing guidance gives a worked case: maxReplicas of 100 at the default pool limit of 10 asks the database for 1000 connections. That number is the peak you must plan for, and it arrives during a traffic spike, which is exactly when the database has the least headroom.
On Kubernetes, LiteLLM recommends one Uvicorn worker per pod and scaling horizontally, which reduces the formula to pool limit times pods. Each pod then holds a fixed pool, and adding pods is the only way the connection count grows. If you raise the worker count inside a pod, you multiply the pool per pod as well, so the same autoscaling ceiling produces a larger demand without any visible change in the deployment manifest. Confirm the worker setting in your chart or container command before you run the arithmetic, and confirm the default pool limit in your version's documentation rather than relying on the example above.
To check whether the database can absorb the peak, compare the computed demand with the server's max_connections setting and with the connection budget left after administrative, migration and monitoring sessions. Run SHOW max_connections; on the primary, then count idle and active sessions under normal load. Managed services often set their own connection ceilings that differ from the engine default, so check the limit your provider documents. If the peak exceeds the usable budget, you can lower the pool limit, lower maxReplicas, or place a pooler such as PgBouncer between the pods and the database. Repeat this calculation after any change to autoscaling thresholds, pool settings, worker counts or replica count, and after adding a read replica, since the reader needs its own connection budget.
Handling connections: direct, PgBouncer or a managed proxy
With direct connections, each LiteLLM worker opens its own pool to the PostgreSQL writer, and no component sits between the pods and the database. The demand is the total described in the LiteLLM database sizing guidance: database_connection_pool_limit times workers per instance times instances, where instances follows the autoscaler's maxReplicas. The count rises every time the autoscaler adds a pod, so the database ceiling has to hold at your planned maximum, not at today's replica count.
- Simplest path: there is no extra component to deploy, patch, monitor or make highly available.
- Pool math is the ceiling: at the default pool limit of 10, a
maxReplicasof 100 asks for 1000 connections before admin tasks, migrations or any replica connections are counted. - Scaling is coupled to the database: changing the replica count or the pool limit changes the database load, so both settings need a shared owner and a review step.
- Failover depends on reconnection: pods recover after a writer change only if the endpoint resolves to the new primary and stale pooled connections are discarded. Test this in a failover drill.
Before you choose this path, compare the pool total at your planned maximum replica count with the connection limit you have confirmed for your PostgreSQL instance.
PgBouncer is a lightweight connection pooler placed between the LiteLLM pods and PostgreSQL. The pods open client connections to PgBouncer, which keeps a smaller set of server connections to the database and shares them across client traffic. The database then sees the pool size configured in PgBouncer, multiplied by the number of PgBouncer instances, while the pods still count against PgBouncer's own client connection limit. The PgBouncer documentation describes the pooling modes and their limits.
- Pooling mode: transaction pooling uses the fewest server connections but restricts session-level features such as session settings and some prepared statement behavior. Confirm which mode LiteLLM's database access and migrations work under before you choose it.
- Migrations need a plan: schema migrations and administrative tasks may need a direct connection that bypasses the pooler, so define that route in advance.
- The pooler is a new dependency: a single PgBouncer instance becomes a single point of failure unless you run more than one behind a load balancer. Your platform team owns its patching, configuration and alerts.
- Failover needs an update path: PgBouncer forwards traffic to the host it is configured for, so a primary change requires either updating its target or placing a failover layer in front of it. Confirm the process with your high availability tooling.
Before you rely on this path, run startup, migrations and a failover drill through PgBouncer in a staging environment.
Many managed PostgreSQL services provide their own connection proxy or enforce connection limits that depend on the instance tier. This path changes the pool math mainly by moving the ceiling: the provider caps connections for the tier, and the proxy may multiplex client connections onto fewer server connections. The limits differ by service and by tier, so take the figures from the provider's documentation or a written answer for the exact tier you plan to buy, and enter them into the pool formula yourself.
- Limits follow the tier: a larger or smaller instance can change the connection cap, so the sizing decision and the tier decision must be made together.
- Proxy compatibility needs testing: confirm whether the proxy supports the session behavior LiteLLM relies on, and whether it changes how token-based or IAM-based database authentication works.
- Failover behavior varies: ask how the proxy endpoint behaves during a managed failover, how long clients take to reconnect and whether pools discard stale connections automatically.
- Operations split with the provider: the provider runs and patches the proxy, while your team owns the pool settings, alerts, capacity reviews and the evidence for any audit.
Before you size the pool, get the connection limit, failover behavior and any charges tied to the proxy in writing from the provider.
Sizing and deploying PostgreSQL for LiteLLM, step by step
This sequence takes you from measured traffic to a sized PostgreSQL instance, a connection budget, and a written sizing decision that holds up under load testing and capacity review.
Estimate sustained requests per second
Start from traffic data your gateway or existing provider accounts already show, not from peak marketing forecasts. Your platform or FinOps team pulls request counts for a representative busy period, converts them to requests per second, and separates sustained load from short bursts. Count only requests that will reach the gateway, because callers that cache responses or use a separate path will not add spend writes. Record the figure as a sustained RPS range with the source and period named. The step is done when someone other than the author can reproduce the number from the logged source data.
Choose the database tier from spend writes
Map the sustained figure to LiteLLM's database sizing tiers, which are driven mainly by spend writes because every logged request updates spend records. The tiers in LiteLLM's database sizing guidance run from a 4 vCPU, 16 GB, 200 GB SSD instance with 3000+ IOPS up to 1K sustained RPS, through 8 vCPU and 32 GB from 1K to 5K RPS, to 16+ vCPU, 64 GB, 1 TB+ storage and a read replica above 5K RPS. If your figure sits near a boundary, size to the higher tier and confirm the choice in the load test. The output is a named tier with its vCPU, memory, storage and IOPS targets written next to the RPS figure.
Decide on prompt storage and retention
Decide whether prompts are stored in spend logs before you size storage, because this choice changes disk growth by roughly an order of magnitude. Without prompts, spend logs take about 1 to 2 KB per logged request according to LiteLLM's sizing guidance, and with store_prompts_in_spend_logs enabled that figure is about 10 times higher. Multiply your expected request volume by the per-request figure for each option, then set a retention period with your privacy and security owners. Confirm whether your compliance obligations allow prompts to be stored at all. The check is a written storage projection for 30, 90 and 365 days under each setting, with the chosen option and retention approved by the data owner.
Calculate peak connections from maxReplicas and pool limit
Compute the connection demand the database must accept at peak, not the connection count at steady state. The formula is the database connection pool limit multiplied by workers per instance multiplied by instances, where the instance count is the autoscaler's maxReplicas. LiteLLM's guidance gives an example: maxReplicas of 100 at the default pool limit of 10 asks for 1000 connections. Add headroom for migrations, administrative sessions, monitoring and any read replica pool. Compare the total with the connection limit of the instance class or managed service you are considering. The output is a single peak connection number and a note on whether the chosen instance supports it.
Pick a connection handling approach
Choose how connections reach PostgreSQL once the peak figure is known. If the calculated demand fits within the instance limit with headroom, direct connections from the proxy are simpler to operate. If it does not, put a connection pooler such as PgBouncer between the gateway and the database, and confirm that the pooling mode suits how LiteLLM uses prepared statements and sessions in your version. Also decide how the reader will handle connection limits on your managed service, since some services reserve connections for system use. The check is a short decision record naming the approach, the pooler mode if used, and a test that confirms the proxy starts and serves requests through it.
Configure database and Redis connection settings
Set the connection values on the gateway deployment so that the pool limit and worker count produce the peak figure you calculated. Confirm that the proxy runs one Uvicorn worker per pod on Kubernetes and scales horizontally, as LiteLLM's production guidance recommends, and that database credentials and the LITELLM_MASTER_KEY sit in a secret manager. Set the PostgreSQL connection string and any read replica endpoint, and confirm that Redis 7.0 or newer is configured once more than one proxy instance runs, because shared rate limits, router state and cache depend on it. Verify that spend updates are batched at the interval LiteLLM recommends for scale. The check is a rendered configuration that a reviewer can compare against the sizing record, with no value that differs from it.
Run a load test against the estimate
Run a load test that reproduces the sustained RPS figure and a burst above it, using traffic that matches your real mix of models, key types and prompt lengths. Your platform team runs it in a staging environment sized like production, with the same database tier, pool settings and Redis configuration. Watch connection counts, IOPS, query latency and write throughput on the database, and watch spend-log table growth over the test window. Compare each measured value with the sizing record and note where the instance approaches a limit. The step is done when the test report shows measured figures for each metric beside the original estimate.
Write the sizing decision for capacity reviews
Record the sizing decision in a document that capacity and security reviewers can read without the original engineers. Include the sustained RPS source and period, the chosen tier and its resource targets, the prompt storage setting and retention period, the peak connection calculation with the maxReplicas value used, the connection handling approach, the Redis requirement, the load test results and the date of the test. List the triggers that would prompt a resize or a read replica, such as sustained RPS crossing a tier boundary, spend-log growth beyond the projection, or connection counts approaching the instance limit. Assign an owner and set a review point for the document. The output is a sizing record that the team can update each time traffic or configuration changes.
When to add a read replica and what it does not solve
Add a read replica when reads start competing with writes on the primary, and treat LiteLLM's guidance of more than 5K sustained RPS as the point where the sizing table expects one. Key lookups on every request and spend queries from the admin UI and reporting are reads, but spend writes arrive on every logged request and dominate the load the primary must absorb. Before adding capacity, check the primary's CPU, IOPS and connection count during peak traffic, and confirm whether the slowdown comes from reads, from the spend log writes or from connection exhaustion. A replica helps only the first of these. Confirm the exact replica sizing with LiteLLM for your traffic pattern rather than assuming the table applies unchanged.
PostgreSQL hot standbys serve read-only queries, so a replica can take the read load while the primary keeps the writes. The replication mode is a decision you must make explicitly. With synchronous replication, a commit waits until a standby confirms it, which protects recent spend records at the cost of added write latency on every request. With asynchronous replication, commits do not wait, so writes stay fast but a failover can lose the most recent transactions that the standby had not yet received. For spend data that finance may reconcile, record which trade-off you accepted and who signed it off. The PostgreSQL high availability documentation describes both modes and is the right reference for your choice.
A replica does not make the database highly available on its own. PostgreSQL does not detect a primary failure or notify a standby, so promoting a replica after an outage requires external tooling and a tested runbook, and a managed service may handle this for you. Also confirm how the gateway reconnects after promotion, since stale connections and pool settings can keep sending traffic to the old primary. Routing read queries to the replica is a separate configuration topic, covered on the LiteLLM read replica page, and the failover and point-in-time recovery steps should be tested before you rely on either.
Security, upgrade and recovery risks to plan for, and limits to confirm
PostgreSQL carries LiteLLM's keys, budgets and spend history, so the database choice also sets your licensing position, your upgrade calendar, your authentication model and your recovery target. The cards below cover what to decide and what to verify in your own environment before the sizing becomes a purchase or a deployment.
PostgreSQL License terms
PostgreSQL is released under the PostgreSQL License, a permissive open source license similar to the BSD and MIT licenses. Your legal team still needs to review how it fits your procurement rules, but the license does not add a per-instance or per-user fee to the database itself. Managed services charge for their own service terms, which differ from the license, so compare the managed offering's terms separately.
PostgreSQL licenceSupported major versions and end dates
Version 18 is supported until November 14, 2030, 17 until November 8, 2029, 16 until November 9, 2028, 15 until November 11, 2027 and 14 until November 12, 2026. Versions 13 and earlier are no longer supported. Pick a major version whose support window covers your planned LiteLLM release line, and put the 14 end date on the calendar now if you are already running it.
Versioning policyMinor releases and major upgrades
Minor releases do not change the internal storage format, so applying them means replacing executables and restarting. Major upgrades need a planned path: pg_dumpall with restore, pg_upgrade, or logical replication. Logical replication works across major versions and can limit downtime to several seconds, but it needs careful cutover testing. Confirm which path your managed service supports and rehearse it against a copy of your spend logs.
Upgrading a PostgreSQL clusterAuthentication: SCRAM and MD5
PostgreSQL 18 deprecated MD5 password authentication in favor of SCRAM. Set password_encryption to scram-sha-256 for new roles and confirm that the LiteLLM database user, your connection poolers and any admin tools all authenticate with SCRAM. Where your identity model allows it, consider the OAuth, certificate or IAM-based methods that your managed service offers, and record which method each client uses.
Point-in-time recovery with continuous archiving
Replicas protect against hardware loss but not against a bad migration or an accidental delete of key or budget rows. Continuous archiving with a base backup and WAL segments allows restore to a chosen point in time. Decide your recovery point objective, keep archives in storage separate from the primary, and test a restore on a schedule. Untested archives are not a recovery plan.
Continuous archivingWhat to confirm in your environment
Measure restore time from your archive for a database sized by your spend log growth, not for an empty test database. Check the sustained IOPS your storage class delivers, since the LiteLLM sizing guidance assumes 3000 or more IOPS at the smallest tier. Compare your managed service's maximum connections with the pool math across maxReplicas. Ask the provider for the failover behavior and the time it takes, because PostgreSQL does not detect primary failure on its own.
- Smallest tier guidance
- 3000+ IOPS
Questions buyers ask before sizing PostgreSQL for LiteLLM
What drives the cost of sizing PostgreSQL for LiteLLM?
The cost follows the amount of analysis and design work, which depends mainly on how many LiteLLM workers and proxy instances you run, whether prompts are stored in spend logs, and whether you are choosing a managed or self-managed database. Each added worker and instance multiplies connection demand, so the connection pool design takes more care as the fleet grows. Replica and failover design add scope because they require decisions about read routing, backups and who responds when the primary fails. Ask any quote to list these items separately, along with the environments covered and the deliverables, such as a sizing document, configuration changes and a verification test. DeployOpen does not publish a price list, and a quote follows from the written scope.
How long does a PostgreSQL sizing exercise take?
The duration depends on how quickly the client can provide usable traffic data, how many environments need review, and whether the database is already provisioned. Sizing starts from sustained requests per second, so the work moves faster when that figure, the expected peak and the autoscaling limits are already documented. Delays usually come from missing access to the database metrics, unclear ownership of backups, or a decision about prompt storage that has not been made. Ask for the expected timeline in the written scope, and confirm which items the client must supply before the clock starts.
What does DeployOpen need from our team to size the database?
Expect to provide sustained request volume by time of day, expected peaks, the autoscaling settings that set the maximum number of replicas, and the worker count per pod. The team also needs read access to current database metrics, network paths from the LiteLLM pods to the database, and a named owner for backups and restores. Confirm whether store_model_in_db and prompt logging are enabled, because prompt storage changes storage needs by a large multiple. If a managed service is in use, provide the instance class, connection limits and the authentication method in use.
Can our own team size PostgreSQL for LiteLLM without a partner?
Yes, if your team already runs PostgreSQL in production and understands connection pooling. The core math is simple: total connections equal the pool limit multiplied by workers per instance and by the maximum number of instances. The harder parts are validating storage growth from spend logs, choosing between managed and self-managed options, and designing failover, which PostgreSQL does not perform on its own. Teams without that experience often underestimate the connection math at high replica counts. A partner can add value by reviewing the design against your traffic and testing the result, while your team keeps ownership of the platform.
Should we size PostgreSQL before or after a load test?
Size first from your expected sustained requests per second, then confirm the choice with a load test. A load test on an undersized database can fail for reasons that are not about the application, such as connection exhaustion, so it is useful to start from a documented baseline. Once the test runs, compare observed write latency, connection counts and storage growth per logged request against the sizing assumptions. Repeat the test after major configuration changes, such as turning on prompt storage or adding workers. Ask the team that runs the test to report these measurements, not only the pass or fail result.
When do we need a read replica or failover tooling?
Add a read replica when sustained load and reporting queries start to compete with spend writes on the primary, or when your capacity model reaches the upper sizing tiers. PostgreSQL supports hot standby servers for read-only queries, but it does not detect a failed primary or promote a standby by itself, so automatic failover needs external tooling. If an outage that waits for a manual promotion is not acceptable for your gateway, plan that tooling and test it before go-live. Confirm which systems read from the replica, because replica lag can make recent spend or key data appear late. Document the recovery steps, including who makes the promotion decision.
How does prompt storage change the database size we need?
Prompt storage has the largest effect on storage. LiteLLM's spend log table uses roughly 1 to 2 KB per logged request without prompts, and about ten times that when prompts are stored in spend logs. Multiply the expected request count by retention days to estimate growth, then add headroom for backups and indexes. Decide with your security and privacy teams whether prompts should be stored at all, and for how long, before choosing disk size. Storing prompts also affects backup duration and restore time, so the choice belongs in the sizing decision rather than after deployment.
How DeployOpen works on this
DeployOpen starts from the sustained request rate, logging choice and autoscaling ceiling for your LiteLLM gateway, then writes the PostgreSQL sizing, connection budget and replica decision into a fixed-scope plan. We build, test and document the database layer inside infrastructure you control, so your team can review and operate it.
How we scope
- Confirm sustained requests per second, peak load and the autoscaler maxReplicas that sets connection demand
- Decide whether store_prompts_in_spend_logs is enabled, since it changes storage per logged request by roughly tenfold
- Agree in writing the instance class, storage, replica decision and retention period covered by the fixed scope
How we build
- Size the PostgreSQL instance and storage, then calculate the pool limit across workers, pods and replicas
- Check managed database connection limits and set pooling, such as PgBouncer, where the math requires it
- Load test writes against the planned spend update cadence and record results before go-live
How we hand over
- Deliver a written sizing record with formulas, assumptions, storage growth estimates and the replica trigger points
- Document the connection budget, monitoring thresholds and the runbook for adding storage or a read replica
- Walk your database, platform and security teams through the configuration so they can review and operate it
How we support
- Offer ongoing support and upgrades as a retainer after handover, including PostgreSQL minor and major upgrade planning
- Re-run the sizing review when request volume, autoscaling limits or logging settings change
- Retest connection and storage behavior after material changes, as agreed in the support scope

