Skip to content

Commit 5909292

Browse files
authored
postgres setup enhancements (#1603)
- mount a memory based volumen for `/dev/shm` - extend `terminationGracePeriodSeconds` to 70 seconds - configure `pg_stat_statements.track = all` to track all types of queries when enabled. (cherry picked from commit 1027ade) Signed-off-by: Danny Zaken <dannyzaken@gmail.com>
1 parent f24aba3 commit 5909292

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

deploy/internal/configmap-postgres-db.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ data:
2424
min_wal_size = 2GB
2525
max_wal_size = 8GB
2626
shared_preload_libraries = 'pg_stat_statements'
27+
pg_stat_statements.track = all

deploy/internal/statefulset-postgres-db.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ spec:
100100
mountPath: /opt/app-root/src/postgresql-cfg
101101
- name: noobaa-postgres-initdb-sh-volume
102102
mountPath: /init
103+
- name: shm
104+
mountPath: /dev/shm
103105
volumes:
104106
- name: noobaa-postgres-config-volume
105107
configMap:
106108
name: noobaa-postgres-config
107109
- name: noobaa-postgres-initdb-sh-volume
108110
configMap:
109111
name: noobaa-postgres-initdb-sh
112+
- name: shm
113+
emptyDir:
114+
medium: Memory
110115
securityContext:
111116
runAsUser: 10001
112117
runAsGroup: 0

pkg/bundle/deploy.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,7 +3568,7 @@ metadata:
35683568
data: {}
35693569
`
35703570

3571-
const Sha256_deploy_internal_configmap_postgres_db_yaml = "afe8a865abf2b033229df9dcea392abc1cb27df965d5ff0181f6d931504dce4e"
3571+
const Sha256_deploy_internal_configmap_postgres_db_yaml = "9e522258577e9b24d289e005e74c8125cffcd56652533fe30ee109c7fb4b95e0"
35723572

35733573
const File_deploy_internal_configmap_postgres_db_yaml = `apiVersion: v1
35743574
kind: ConfigMap
@@ -3596,6 +3596,7 @@ data:
35963596
min_wal_size = 2GB
35973597
max_wal_size = 8GB
35983598
shared_preload_libraries = 'pg_stat_statements'
3599+
pg_stat_statements.track = all
35993600
`
36003601

36013602
const Sha256_deploy_internal_configmap_postgres_initdb_yaml = "016881f9a5e0561dbf10e7034dead0ee636556c162439d4d54c974a65253357c"
@@ -4867,7 +4868,7 @@ spec:
48674868
storage: 50Gi
48684869
`
48694870

4870-
const Sha256_deploy_internal_statefulset_postgres_db_yaml = "612a1936d01fc7847cb583aaa1a011e76fae84387441d3eb48f20f5d4ea0dd69"
4871+
const Sha256_deploy_internal_statefulset_postgres_db_yaml = "ed43a30779f93d49fdacfa88362ec8290bd0502f2a1ef809cdee6110ce691941"
48714872

48724873
const File_deploy_internal_statefulset_postgres_db_yaml = `apiVersion: apps/v1
48734874
kind: StatefulSet
@@ -4971,13 +4972,18 @@ spec:
49714972
mountPath: /opt/app-root/src/postgresql-cfg
49724973
- name: noobaa-postgres-initdb-sh-volume
49734974
mountPath: /init
4975+
- name: shm
4976+
mountPath: /dev/shm
49744977
volumes:
49754978
- name: noobaa-postgres-config-volume
49764979
configMap:
49774980
name: noobaa-postgres-config
49784981
- name: noobaa-postgres-initdb-sh-volume
49794982
configMap:
49804983
name: noobaa-postgres-initdb-sh
4984+
- name: shm
4985+
emptyDir:
4986+
medium: Memory
49814987
securityContext:
49824988
runAsUser: 10001
49834989
runAsGroup: 0

pkg/system/phase2_creating.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,23 @@ func (r *Reconciler) SetDesiredNooBaaDB() error {
303303
if r.NooBaa.Spec.DBResources != nil {
304304
c.Resources = *r.NooBaa.Spec.DBResources
305305
}
306+
307+
c.Lifecycle = &corev1.Lifecycle{
308+
PreStop: &corev1.LifecycleHandler{
309+
Exec: &corev1.ExecAction{
310+
Command: []string{"/bin/sh", "-c", "pg_ctl -D /var/lib/pgsql/data/userdata/ -w -t 60 -m fast stop"},
311+
},
312+
},
313+
}
306314
}
307315
}
308316

317+
// set terminationGracePeriodSeconds to 70 seconds to allow for graceful shutdown
318+
// we set 70 to account for the 60 seconds timeout of the fast shutdow in preStop, plus some slack
319+
// see here: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-handler-execution
320+
gracePeriod := int64(70)
321+
podSpec.TerminationGracePeriodSeconds = &gracePeriod
322+
309323
if r.NooBaa.Spec.ImagePullSecret == nil {
310324
podSpec.ImagePullSecrets =
311325
[]corev1.LocalObjectReference{}

0 commit comments

Comments
 (0)