Migrate the `postgres` database from the old StatefulSet (local-storage, image `pgvector/pgvector:pg18-trixie`) to a new Deployment `postgres-hetzner` on `hcloud-volumes` (Hetzner CSI), using the public image `pgvector/pgvector:pg18-trixie` (Postgres 18 + pgvector 0.8.2).
**Strategy:** logical dump/restore via `pg_dumpall`, Option A service repoint (external IP `10.2.0.122` and internal DNS `postgres.database.svc.cluster.local` both unchanged → outside dependency and in-cluster consumers need no reconfiguration).
**Downtime:** required (writers stopped during dump/restore). Estimated window: ~20–40 min depending on 18 GB transfer speed.
---
## Current state (verified in cluster)
### Old DB
- **StatefulSet** `postgres` in namespace `database` (120 days old).
- **Pod** `postgres-0` on node `woker-1-8gb-hel1-1`, IP `10.0.2.116`.
- **Credentials:** hardcoded `POSTGRES_USER=admin`, `POSTGRES_PASSWORD=jd@wXseh9z7vM@9`. Also stored in Secret `postgres-secret` (namespace `database`) with the same values.
- **The outside dependency connects via the old pod IP `10.0.2.116` (NOT the LB `10.2.0.122`).** This was incorrect — pod IPs are ephemeral and disappear when the pod is deleted.
- After migration, the old pod IP `10.0.2.116` is gone. The outside dependency **must be reconfigured to use `10.2.0.122:5432`** (the stable LB IP, which routes to the new `postgres-hetzner` pod).
- The LB `postgres-service` keeps IP `10.2.0.122` via the Cilium annotation `lbipam.cilium.io/ips: 10.2.0.122` (pool `postgres-pool`) — this IP is stable across pod restarts/replacements.
- **Action required:** update the outside dependency's DB host from `10.0.2.116` → `10.2.0.122` before/after cutover.
---
## Repo manifest changes (already applied)
-`PostgreSQL/postgress_deplay.yaml` — synced to live STS (rollback reference).
-`PostgreSQL/hetzner/postgres_hetzner_deployment.yaml` — uses `postgres-secret` (secretKeyRef), public image `pgvector/pgvector:pg18-trixie` (custom image `10.0.2.119:5000/custom-postgres:latest` not reachable — old node IP gone; nodes now on 10.1.0.x and cluster DNS not resolvable from node containerd), `strategy: Recreate`.
- Removed stale `postgres_pvc.yaml` and `postgres_static_endpoint.yaml`.
---
## Execution
### Phase 0 — Pre-flight (re-run on migration day to confirm no drift)
```bash
kubectl get pvc -n database
kubectl get sts,deploy,svc,pod,endpointslice -n database
> **IMPORTANT:** Do NOT use `pg_dumpall | psql` over a `kubectl exec` pipe. The kubectl websocket times out on large transfers (~18 GB) and the text format corrupts `vector` data (long embedding strings get truncated, breaking `smart_search` and other pgvector tables). Use binary `pg_dump -Fc` with `pg_restore`, running `pg_dump` from inside the new pod pointing at the old DB via the `postgres` Service.
```bash
OLD=$(kubectl get pod -n database -l app=postgres -o jsonpath='{.items[0].metadata.name}')
NEW=$(kubectl get pod -n database -l app=postgres-hetzner -o jsonpath='{.items[0].metadata.name}')
echo"OLD=$OLD NEW=$NEW"
# Step 1: pg_dumpall for roles + small DBs (admin, backup, postgres, gitea, grafana) via text pipe
# — these have no vector data and are small (<15 MB each), safe over kubectl pipe.
**Why dump from the new pod:** the new pod can reach the old DB via `postgres.database.svc.cluster.local` (still pointing at old pods until cutover), and writes the binary dump file directly to its own PVC — no kubectl pipe, no truncation, no websocket timeout.
### Phase 4 — Cutover (repoint both Services to new pods)
## Rollback (if Phase 4/5 fails — recovers OLD DB)
> **Caveat:** rollback loses any writes made to the new DB after cutover (old PVC was not updated by dump/restore). This is inherent to logical dump/restore migration. If you need zero-data-loss rollback, the migration must use logical replication instead — request that redesign separately.
# >>> restart the outside dependency (pointed at 10.2.0.122) <<<
```
If rollback happens **before** Phase 6 cleanup, the old STS + PVC `postgres-data-postgres-0` are intact and the old DB serves immediately. If rollback happens **after**`kubectl delete sts postgres --cascade=orphan`, recreate the STS from `PostgreSQL/postgress_deplay.yaml` (the orphan pod + PVC are reused because the STS name + selector match).
---
## Pre-migration checklist (outside dependency)
Before starting Phase 1, ensure:
- [ ]**Outside dependency DB host updated from `10.0.2.116` → `10.2.0.122`** (the old pod IP is gone; the LB IP `10.2.0.122` is stable and routes to the new DB).
- [ ] Outside dependency that writes to `homeassistant` DB via `10.2.0.122` can be stopped for the maintenance window.
- [ ] Backup of any critical external state taken.
- [ ] Maintenance window scheduled.
## Pre-migration checklist (cluster)
- [ ]`kubectl get pvc -n database` shows `postgres-data-postgres-0` Bound on `local-storage`.
- [ ]`postgres-service` LB external IP is `10.2.0.122`.
- [ ] All consumer Deployments exist and are Ready (immich-server, immich-machine-learning, gitea, grafana).
- [ ] No `postgres-hetzner` Deployment/PVC exist yet.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.