kubernetes
PostgreSQL Kubernetes Sizing Calculator
Calculate the right CPU and memory for your PostgreSQL pods on Kubernetes. Based on database size, connection count, and workload type — with postgresql.conf recommendations.
Sizing PostgreSQL on Kubernetes
PostgreSQL memory sizing involves two distinct concerns: caching enough data to avoid disk I/O, and handling the per-connection overhead.
Key PostgreSQL Memory Parameters
| Parameter | Rule of Thumb | Purpose |
|---|---|---|
| shared_buffers | 25% of RAM | PostgreSQL's own cache |
| effective_cache_size | 75% of RAM | Query planner hint (OS cache estimate) |
| work_mem | RAM × 0.25 ÷ (max_connections × 4) | Per sort/hash operation |
| maintenance_work_mem | 256 MB – 2 GB | VACUUM, CREATE INDEX |
Connection Overhead
Each PostgreSQL backend process uses:
- ›~5 MB base memory
- ›Additional memory proportional to query complexity
With 200 connections: 200 × 5 MB = 1 GB just for connection overhead.
PgBouncer in Kubernetes
# Add PgBouncer as a sidecar or separate Deployment
# Transaction pooling: reduces actual Postgres connections by 10-20×
env:
- name: POOL_MODE
value: transaction
- name: MAX_CLIENT_CONN
value: "500"
- name: DEFAULT_POOL_SIZE
value: "25"Storage Requirements
Use a dedicated PVC for PostgreSQL data:
# Size PVC at 2-3× current DB size for growth headroom
storage: 150Gi # for a 50 GB databaseUse Longhorn with 3 replicas for HA storage, or a cloud-managed SSD for managed K8s.
Key Terms
Full glossary →kubeadm
A tool for bootstrapping Kubernetes clusters. It automates the setup of control plane components and joining worker nodes, following Kubernetes best practices.
etcd
A distributed key-value store used by Kubernetes to store all cluster state and configuration. etcd is the single source of truth for the entire cluster.
cert-manager
A Kubernetes controller for automating TLS certificate management. cert-manager can issue certificates from Let's Encrypt, Vault, or internal CAs, and automatically renews them.
Helm
A package manager for Kubernetes. Helm charts bundle Kubernetes manifests into reusable packages with configurable values, versioned and published to chart repositories.
Frequently Asked Questions
How much RAM does PostgreSQL need?
As a baseline, PostgreSQL needs enough RAM for shared_buffers (25% of RAM) to cache your working dataset. For a database that fits in RAM, target: RAM ≥ database_size / 0.75. For write-heavy workloads, this is less critical since the working set is smaller. The calculator combines both the cache requirement and the per-connection overhead (roughly 4–10 MB per connection).
Should I run PostgreSQL directly in Kubernetes?
Yes, with a proper operator. CloudNativePG (CNPG) is the recommended approach — it handles HA, streaming replication, automated backups, and point-in-time recovery. Running Postgres in K8s without an operator is risky. Use a PVC backed by Longhorn or a cloud SSD for the data volume.
What is PgBouncer and should I use it?
PgBouncer is a connection pooler that sits between your app and PostgreSQL. Each PostgreSQL connection consumes ~5–10 MB of RAM and a backend process. With 500 app connections routing through PgBouncer in transaction mode, PostgreSQL only sees 20–50 actual connections — dramatically reducing RAM and CPU usage. Always use PgBouncer in Kubernetes where many app pods connect to the DB.
How do shared_buffers and effective_cache_size differ?
shared_buffers is actual RAM PostgreSQL allocates for its own cache — set to 25% of total RAM. effective_cache_size is just a hint to the query planner about how much OS page cache is available — set to 75% of RAM. Setting effective_cache_size correctly helps the planner choose index scans over sequential scans for large tables.
Related Tools
K8s Node Sizing
Calculate the right number and size of Kubernetes worker nodes for your workloads. Supports Hetzner Cloud and Vultr with verified pricing.
Longhorn Storage
Calculate the total storage required for Longhorn distributed block storage, including replica overhead, snapshot retention, and S3 backup sizing on Hetzner Object Storage.
Redis Memory
Calculate how much memory your Redis deployment needs on Kubernetes. Accounts for dataset size, replication, overhead, and Redis Cluster mode.
Related Guides
kubernetes
CI/CD for Kubernetes with GitHub Actions: A Complete Guide (2026)
A practical walkthrough of building a full GitHub Actions pipeline that builds a container image, pushes it to a registry, and deploys to Kubernetes — with secrets handling, rollback, and Helm support.
kubernetes
ArgoCD vs Flux: Choosing a GitOps Tool for Kubernetes in 2026
A no-fluff comparison of ArgoCD and Flux for GitOps on Kubernetes — covering architecture, UI, Helm support, multi-tenancy, and when to pick each one.
kubernetes
Hetzner vs DigitalOcean for Kubernetes in 2026: An Honest Comparison
Hetzner is 3–5× cheaper than DigitalOcean for equivalent Kubernetes compute. But DO has managed K8s, better global coverage, and a larger app marketplace. Here's when each is the right choice.