Skip to content

Commit

Permalink
added preStop hook to DB statefulset
Browse files Browse the repository at this point in the history
The preStop hook will call pg_ctl with -m fast flag - this will rollback all active transactions and stop the server.
by default postgres will wait for all active connections to complete before exiting. the default grace period of kuberentes for pod shutdown is 30 seconds and after that it sends SIGKILL to the process. this can lead to DB failures

Signed-off-by: Danny Zaken <[email protected]>
  • Loading branch information
dannyzaken committed Dec 11, 2023
1 parent bbef9b2 commit 92e187c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ func (r *Reconciler) SetDesiredNooBaaDB() error {
if r.NooBaa.Spec.DBResources != nil {
c.Resources = *r.NooBaa.Spec.DBResources
}

c.Lifecycle = &corev1.Lifecycle{
PreStop: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{"/bin/sh", "-c", "pg_ctl -D /var/lib/pgsql/data/userdata/ -w -t 60 -m fast stop"},
},
},
}

}
}

Expand Down

0 comments on commit 92e187c

Please sign in to comment.