Skip to content

fix(migration): TCP keepalives + bigger memory limit#51

Merged
passcod merged 1 commit into
mainfrom
migration-memory-keepalives
Jun 4, 2026
Merged

fix(migration): TCP keepalives + bigger memory limit#51
passcod merged 1 commit into
mainfrom
migration-memory-keepalives

Conversation

@passcod

@passcod passcod commented Jun 4, 2026

Copy link
Copy Markdown
Member

Two related issues observed for the schema-migration Job on non-trivial persistent_schemas (dbt-shaped):

1. Stuck on dead connections. The pg_dump | psql pipe held libpq connections without TCP keepalives. When the pod-to-pod TCP connection was silently dropped (network policy change, node disruption, etc.) neither end detected it: pg_dump sat blocked on read, postgres marked the session idle in transaction with wait_event=ClientRead, and the Job stayed Running indefinitely while the operator never recovered on its own.

Fix: switch to libpq connection URIs and add keepalives=1, keepalives_idle=60, keepalives_interval=10, keepalives_count=3. A dropped socket is now detected and torn down within ~90 seconds, the Job fails fast, the operator retries on the next reconcile.

Also tag the connection with application_name=pgro-schema-migration so the migration session is identifiable in pg_stat_activity for diagnosis.

2. OOMKilled. The 512Mi memory limit on the migration container was too small for dbt-scale schemas. The pg_dump | psql pipeline peaks well past that and the container was being OOMKilled in succession, with the operator recreating the Job each time.

Fix: bump to 256Mi request / 4Gi limit. The Job is short-lived and only runs during a switchover; a generous limit doesn't increase ongoing footprint.

Unit tests assert the keepalive params, application_name, and a ≥2Gi memory limit are present in the built Job spec.

Two related issues with the schema-migration Job for non-trivial
persistent_schemas:

1. Stuck on dead connections. The pg_dump | psql pipe held a libpq
   connection without TCP keepalives. When the pod-to-pod TCP
   connection was silently dropped (network policy change, node
   disruption, etc.) neither end detected it: pg_dump sat blocked on
   read, postgres marked the session "idle in transaction" with
   wait_event=ClientRead, and the Job stayed Running indefinitely.
   Observed: a migration sat stuck for 39 hours after the connection
   died, with the operator never recovering on its own.

   Fix: switch to libpq connection URIs and add
   keepalives=1, keepalives_idle=60, keepalives_interval=10,
   keepalives_count=3. A dropped socket is now detected and torn down
   within ~90 seconds, the Job fails fast, the operator retries.

   Also tag the connection with application_name=pgro-schema-migration
   so the migration session is identifiable in pg_stat_activity.

2. OOMKilled. The 512Mi memory limit on the migration container was
   too small for a dbt-scale schema with many tables and indexes. The
   pg_dump | psql pipeline peaks well past that and the container was
   being OOMKilled dozens of times in succession.

   Fix: bump to 256Mi request / 4Gi limit. The Job is short-lived and
   only runs during a switchover; a generous limit doesn't increase
   ongoing footprint.
@passcod passcod merged commit 86ba399 into main Jun 4, 2026
18 checks passed
@passcod passcod deleted the migration-memory-keepalives branch June 4, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant