fix(migration): TCP keepalives + bigger memory limit#51
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 transactionwithwait_event=ClientRead, and the Job stayedRunningindefinitely 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-migrationso the migration session is identifiable inpg_stat_activityfor 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.