pgvector
by cagriekin
PostgreSQL with the pgvector extension for vector search, plus streaming replication, agent failover (Kubernetes Lease or etcd-quorum DCS), optional PgPool-II, S3 backups, TLS, and metrics
About this chart
PostgreSQL with pgvector
PostgreSQL Helm chart with pgvector extension for vector similarity search, native streaming replication with a lease-based Go failover agent, optional PGPool-II for connection pooling and read/write splitting.
This chart shares all templates with the pg chart via symlinks. The only differences are the default image (pgvector/pgvector) and automatic CREATE EXTENSION IF NOT EXISTS vector on startup.
Features
- PostgreSQL 18 with pgvector extension for vector similarity search
- Lease-based HA agent (
pg-ha-agent, PID 1 in the postgresql container) for automatic failover, replication management, and primary Service selector updates — no HA sidecars (therepmgrdandservice-updatersidecars were removed in 2.0.0; the pgBackRest and metrics-exporter sidecars are unaffected) - Stale-primary protection: a crashed primary that restarts after a standby was promoted rejoins as a standby (via pg_rewind) instead of resuming read-write on a divergent timeline
- Read-only
<fullname>-readonlyservice targeting standby pods for read scaling (HA mode) - Optional PGPool-II for connection pooling and read/write splitting
- Support for existing secrets or auto-generated passwords
- StatefulSet-based deployment with persistent storage
- PostgreSQL configuration injection via ConfigMap (postgresql.conf overrides, pg_hba.conf entries)
- PostStart lifecycle hooks with primary-aware execution in HA setups
- Pod disruption budgets for safe node drains
- Configurable update strategy, resource limits, probes, and affinity
- Prometheus exporters for PostgreSQL and PGPool-II metrics with ServiceMonitor support
- Automated S3 backups via CronJob with retention management
- pgBackRest for WAL-based incremental backups and point-in-time recovery
Installation
helm repo add cagriekin https://cagriekin.github.io/charts
helm install my-pgvector cagriekin/pgvector
With Read Replicas
helm install my-pgvector cagriekin/pgvector --set postgresql.replicaCount=3
With PGPool-II Enabled
helm install my-pgvector cagriekin/pgvector \
--set postgresql.replicaCount=3 \
--set pgpool.enabled=true
With Existing Secret
kubectl create secret generic pg-secret \
--from-literal=username=myuser \
--from-literal=password=mypassword \
--from-literal=database=mydb \
--from-literal=repmgr-password=myrepmgrpassword
helm install my-pgvector cagriekin/pgvector \
--set postgresql.existingSecret.enabled=true \
--set postgresql.existingSecret.name=pg-secret
Or with custom key names:
kubectl create secret generic pg-secret \
--from-literal=user=myuser \
--from-literal=pass=mypassword \
--from-literal=db=mydb \
--from-literal=repmgr-pass=myrepmgrpassword
helm install my-pgvector cagriekin/pgvector \
--set postgresql.existingSecret.enabled=true \
--set postgresql.existingSecret.name=pg-secret \
--set postgresql.existingSecret.usernameKey=user \
--set postgresql.existingSecret.passwordKey=pass \
--set postgresql.existingSecret.databaseKey=db \
--set postgresql.existingSecret.repmgrPasswordKey=repmgr-pass
Using pgvector
After installation, the vector extension is automatically created. You can start using vector types immediately:
-- Create a table with vector column
CREATE TABLE items (
id SERIAL PRIMARY KEY,
embedding vector(1536)
);
-- Insert vectors
INSERT INTO items (embedding) VALUES ('[1,2,3,...]');
-- Find similar vectors
SELECT * FROM items ORDER BY embedding <-> '[1,2,3,...]' LIMIT 5;
Configuration
Common Parameters
| Parameter | Description | Default |
|---|---|---|
imagePullSecrets | Pull secrets applied to every pod template (StatefulSet, pgpool and exporter Deployments, backup and pgBackRest CronJobs) | [] |
busyboxImage.repository | Image for the helper init containers (permission fixups, config copy/templating) across the StatefulSet, pgpool, and exporter pods; override for air-gapped/private registries | busybox |
busyboxImage.tag | Helper init image tag | 1.37 |
busyboxImage.pullPolicy | Helper init image pull policy | IfNotPresent |
busyboxImage.digest | Optional digest pin (sha256:...), appended as repository:tag@digest | "" |
Pinning images by digest (#26). Every image block —
postgresql.image,ha.image,pgpool.image,pgpool.metrics.image,prometheusExporter.image,busyboxImage,backup.rclone.image, andpgbackrest.cronjob.image— accepts an optionaldigest(e.g.sha256:…). When set, the image is rendered asrepository:tag@digestso a mutable-tag repush cannot silently change what runs. Empty (default) pulls by tag.
PostgreSQL Parameters
| Parameter | Description | Default |
|---|---|---|
postgresql.image.repository | PostgreSQL image repository | pgvector/pgvector |
postgresql.image.tag | PostgreSQL image tag. Must bundle the same PostgreSQL point release as ha.image.tag (#302) — copy-ext's no-clobber copy keeps a drifted image from corrupting the running server, but CREATE EXTENSION vector still needs a matching point release to load safely. Bump only in lockstep with ha.image. | 0.8.5-pg18-trixie |
postgresql.image.pullPolicy | Image pull policy | IfNotPresent |
postgresql.majorVersion | PostgreSQL major version in image.tag; builds the extension paths (/usr/lib/postgresql/<major>/lib, /usr/share/postgresql/<major>/extension) when extensions.enabled=true. With ha.enabled the server runs from the HA image and follows ha.image.majorVersion regardless of postgresql.image; the chart fails to render if the two majors differ. Set both to "17" (with a -pg17 repmgr tag) to run PostgreSQL 17 — see Choosing the PostgreSQL major. | "18" |
postgresql.replicaCount | Number of PostgreSQL replicas (total instances = replicaCount + 1); values > 0 require ha.enabled=true | 1 |
postgresql.database | Database name | postgres |
postgresql.username | Database username (a superuser; the chart's own tooling logs in as it) | postgres |
postgresql.app.username | Non-superuser application role, owns postgresql.database except postgres (see the pg chart README, "Application role and connection reserves") | app_user |
postgresql.resources.requests.cpu | CPU request | 100m |
postgresql.resources.requests.memory | Memory request | 256Mi |
postgresql.resources.limits.cpu | CPU limit | 1000m |
postgresql.resources.limits.memory | Memory limit | 1Gi |
postgresql.persistence.enabled | Enable persistence | true |
postgresql.persistence.size | Storage size | 10Gi |
postgresql.persistence.emptyDir.sizeLimit | sizeLimit for the non-persistent (persistence.enabled=false) PGDATA emptyDir; empty = unbounded | "" |
postgresql.persistence.storageClass | Storage class | "" |
postgresql.updateStrategy.type | StatefulSet update strategy | RollingUpdate |
postgresql.updateStrategy.rollingUpdate.partition | Partition for rolling update | 0 |
postgresql.podAnnotations | Annotations for PostgreSQL pods | {} |
postgresql.priorityClassName | priorityClassName for PostgreSQL pods | "" |
postgresql.affinity | Affinity rules for PostgreSQL pods | {} |
postgresql.annotations | Additional annotations | {} |
postgresql.podSecurityContext | Pod-level securityContext for StatefulSet | {fsGroup: 103, runAsNonRoot: true, seccompProfile.type: RuntimeDefault} |
postgresql.containerSecurityContext | Container-level securityContext for all PostgreSQL containers | {runAsUser: 101, runAsGroup: 103, allowPrivilegeEscalation: false, capabilities.drop: [ALL]} |
Liveness and Readiness Probes
| Parameter | Description | Default |
|---|---|---|
postgresql.livenessProbe.enabled | Enable liveness probe | true |
postgresql.livenessProbe.initialDelaySeconds | Initial delay | 30 |
postgresql.livenessProbe.periodSeconds | Check interval | 10 |
postgresql.livenessProbe.timeoutSeconds | Timeout | 5 |
postgresql.livenessProbe.failureThreshold | Failure threshold | 10 |
postgresql.readinessProbe.enabled | Enable readiness probe | true |
postgresql.readinessProbe.initialDelaySeconds | Initial delay | 5 |
postgresql.readinessProbe.periodSeconds | Check interval | 10 |
postgresql.readinessProbe.timeoutSeconds | Timeout | 5 |
postgresql.readinessProbe.failureThreshold | Failure threshold | 6 |
postgresql.startupProbe.enabled | Enable startup probe (suspends liveness/readiness until PostgreSQL first accepts connections over loopback TCP — the bootstrap's socket-only transient postmaster no longer counts, #350 — so first-boot recovery and WAL replay cannot be killed by the liveness probe) | true |
postgresql.startupProbe.periodSeconds | Check interval | 10 |
postgresql.startupProbe.timeoutSeconds | Timeout | 5 |
postgresql.startupProbe.failureThreshold | Failure threshold (periodSeconds x this = total startup budget, 1800s; it also bounds a standby's first clone, #288, and in standalone mode the postStart hook's wait for the real server, floor 300s, #370) | 180 |
The startup probe, and the readiness probe in standalone mode, ask pg_isready over
127.0.0.1 (#350), the one address the bootstrap's transient postmaster and the stock image's
init-time server never open, so Ready means the real postmaster. listen_addresses must therefore keep IPv4 loopback: a
postgresql.configuration.listen_addresses without *, 0.0.0.0, localhost or 127.0.0.1
fails the render. An IPv6-only ::/::1 does not count (PostgreSQL binds it IPV6_V6ONLY).
In agent mode the readiness probe is the agent's httpGet /readyz (#395), answered from what
its reconcile loop already observes, with no psql or pg_isready per probe. It needs the
pg-ha image at 2.6.0 or later. See the pg chart README for the states it reports NotReady.
Pod Disruption Budgets
| Parameter | Description | Default |
|---|---|---|
postgresql.podDisruptionBudget.enabled | Enable PDB for PostgreSQL | true |
postgresql.podDisruptionBudget.maxUnavailable | Max pods unavailable during a voluntary disruption | 1 |
postgresql.podDisruptionBudget.unhealthyPodEvictionPolicy | Allow evicting not-yet-Ready pods so a stuck pod cannot wedge a drain (k8s >=1.27) | AlwaysAllow |
pgpool.podDisruptionBudget.enabled | Enable PDB for PGPool-II | true |
pgpool.podDisruptionBudget.minAvailable | Minimum available pods | 1 |
PostgreSQL Configuration
Runtime configuration can be injected without rebuilding images. Settings are written to a ConfigMap, mounted into the pod, and loaded via include_dir.
| Parameter | Description | Default |
|---|---|---|
postgresql.configuration | Map of postgresql.conf parameters | {} |
postgresql.pgHba | List of pg_hba.conf entries, written by the agent (HA) or by the postStart hook once the real server answers (standalone, #370) | [] |
postgresql.extraVolumes | Extra pod-level volumes — mount a file identically on every replica (e.g. a pgsodium key); see the pg chart README | [] |
postgresql.extraVolumeMounts | Extra mounts for the postgresql container; each must reference a postgresql.extraVolumes entry | [] |
postgresql.extraEnv | Extra env vars for the postgresql container (supports value and valueFrom); may not reuse a chart-set name | [] |
postgresql.extensions.enabled | Enable extensions support | true |
postgresql.extensions.packages | Debian/PGDG packages to apt-get install before the copy step, for additional extensions beyond vector (pg_cron, …); {major} substitutes postgresql.majorVersion; see the pg chart README | [] |
postgresql.extensions.aptSources | Non-PGDG apt sources (e.g. Pigsty) to add before installing packages; see the pg chart README. A pgdg entry is refused at render time (#320) — both images already configure PGDG under their own keyring, and a second entry makes apt reject the whole source list | [] |
postgresql.extensions.image.repository | Prebuilt extension image — packages resolved once at build time, so pods do a plain cp with no apt and no egress at pod start, and the copy container stays unprivileged (the apt path needs root, which PSA-restricted rejects); see the pg chart README | "" |
postgresql.extensions.image.tag / .digest / .pullPolicy | Tag ({major} substitutes postgresql.majorVersion), digest pin, and pull policy for the above. A tag or digest is required | "" / "" / IfNotPresent |
postgresql.extensions.env | core-v1 EnvVar list for the two extension init containers — chiefly http_proxy, so the install goes through your own apt mirror and no external host needs opening; see the pg chart README | [] |
postgresql.extensions.envFrom | Same as env, as core-v1 EnvFromSource; see the pg chart README | [] |
postgresql.extensions.extraVolumes | core-v1 Volume list for the extension init containers, for what env can't express (an apt.conf.d snippet, a mirror sources.list); see the pg chart README | [] |
postgresql.extensions.extraVolumeMounts | Where extraVolumes land inside both extension in |
Deploy pgvector with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has pgvector on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartpgvector is pinned at v2.8.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply