Skip to content

Commit 8124838

Browse files
authored
postgres setup enhancements (#1599)
- 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. Signed-off-by: Danny Zaken <dannyzaken@gmail.com>
1 parent 1a17057 commit 8124838

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
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
@@ -58,10 +58,15 @@ spec:
5858
mountPath: /var/lib/pgsql
5959
- name: noobaa-postgres-config-volume
6060
mountPath: /opt/app-root/src/postgresql-cfg
61+
- name: shm
62+
mountPath: /dev/shm
6163
volumes:
6264
- name: noobaa-postgres-config-volume
6365
configMap:
6466
name: noobaa-postgres-config
67+
- name: shm
68+
emptyDir:
69+
medium: Memory
6570
securityContext:
6671
runAsUser: 10001
6772
runAsGroup: 0

pkg/bundle/deploy.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,7 +3834,7 @@ metadata:
38343834
data: {}
38353835
`
38363836

3837-
const Sha256_deploy_internal_configmap_postgres_db_yaml = "afe8a865abf2b033229df9dcea392abc1cb27df965d5ff0181f6d931504dce4e"
3837+
const Sha256_deploy_internal_configmap_postgres_db_yaml = "9e522258577e9b24d289e005e74c8125cffcd56652533fe30ee109c7fb4b95e0"
38383838

38393839
const File_deploy_internal_configmap_postgres_db_yaml = `apiVersion: v1
38403840
kind: ConfigMap
@@ -3862,6 +3862,7 @@ data:
38623862
min_wal_size = 2GB
38633863
max_wal_size = 8GB
38643864
shared_preload_libraries = 'pg_stat_statements'
3865+
pg_stat_statements.track = all
38653866
`
38663867

38673868
const Sha256_deploy_internal_deployment_endpoint_yaml = "21b206c9119e37c4ebba84d5c1e2b1d45b06c716b4def69db9ba9268ef75e1e1"
@@ -5114,7 +5115,7 @@ spec:
51145115
resource: limits.memory
51155116
`
51165117

5117-
const Sha256_deploy_internal_statefulset_postgres_db_yaml = "37a6c36928ba426ca04fd89e1eb2685e10d1a5f65c63ebb40c68a4f5c37645de"
5118+
const Sha256_deploy_internal_statefulset_postgres_db_yaml = "d0242805c8719ef45290746b42706fb69805cfd40be6258986454d256112fa7c"
51185119

51195120
const File_deploy_internal_statefulset_postgres_db_yaml = `apiVersion: apps/v1
51205121
kind: StatefulSet
@@ -5176,10 +5177,15 @@ spec:
51765177
mountPath: /var/lib/pgsql
51775178
- name: noobaa-postgres-config-volume
51785179
mountPath: /opt/app-root/src/postgresql-cfg
5180+
- name: shm
5181+
mountPath: /dev/shm
51795182
volumes:
51805183
- name: noobaa-postgres-config-volume
51815184
configMap:
51825185
name: noobaa-postgres-config
5186+
- name: shm
5187+
emptyDir:
5188+
medium: Memory
51835189
securityContext:
51845190
runAsUser: 10001
51855191
runAsGroup: 0

pkg/system/phase2_creating.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ func (r *Reconciler) ReconcilePhaseCreatingForMainClusters() error {
145145

146146
// create notification log pvc if bucket notifications is enabled and pvc was not set explicitly
147147
if r.NooBaa.Spec.BucketNotifications.Enabled {
148-
if err := r.ReconcileODFPersistentLoggingPVC(
149-
"bucketNotifications.pvc",
150-
"InvalidBucketNotificationConfiguration",
151-
"Bucket notifications requires a Persistent Volume Claim (PVC) with ReadWriteMany (RWX) access mode. Please specify the 'bucketNotifications.pvc'.",
152-
r.NooBaa.Spec.BucketNotifications.PVC,
153-
r.BucketNotificationsPVC); err != nil {
154-
return err
148+
if err := r.ReconcileODFPersistentLoggingPVC(
149+
"bucketNotifications.pvc",
150+
"InvalidBucketNotificationConfiguration",
151+
"Bucket notifications requires a Persistent Volume Claim (PVC) with ReadWriteMany (RWX) access mode. Please specify the 'bucketNotifications.pvc'.",
152+
r.NooBaa.Spec.BucketNotifications.PVC,
153+
r.BucketNotificationsPVC); err != nil {
154+
return err
155155
}
156156
}
157157

@@ -287,10 +287,15 @@ func (r *Reconciler) SetDesiredNooBaaDB() error {
287287
},
288288
},
289289
}
290-
291290
}
292291
}
293292

293+
// set terminationGracePeriodSeconds to 70 seconds to allow for graceful shutdown
294+
// we set 70 to account for the 60 seconds timeout of the fast shutdow in preStop, plus some slack
295+
// see here: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-handler-execution
296+
gracePeriod := int64(70)
297+
podSpec.TerminationGracePeriodSeconds = &gracePeriod
298+
294299
if r.NooBaa.Spec.ImagePullSecret == nil {
295300
podSpec.ImagePullSecrets =
296301
[]corev1.LocalObjectReference{}
@@ -472,10 +477,10 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) {
472477

473478
if r.NooBaa.Spec.BucketNotifications.Enabled {
474479
envVar := corev1.EnvVar{
475-
Name: "NOTIFICATION_LOG_DIR",
480+
Name: "NOTIFICATION_LOG_DIR",
476481
Value: "/var/logs/notifications",
477482
}
478-
util.MergeEnvArrays(&c.Env, &[]corev1.EnvVar{envVar});
483+
util.MergeEnvArrays(&c.Env, &[]corev1.EnvVar{envVar})
479484
}
480485

481486
}
@@ -555,10 +560,10 @@ func (r *Reconciler) SetDesiredCoreApp() error {
555560
}}
556561
util.MergeVolumeMountList(&c.VolumeMounts, &notificationVolumeMounts)
557562

558-
notificationVolumes := []corev1.Volume {{
563+
notificationVolumes := []corev1.Volume{{
559564
Name: notificationsVolume,
560-
VolumeSource: corev1.VolumeSource {
561-
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource {
565+
VolumeSource: corev1.VolumeSource{
566+
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
562567
ClaimName: r.BucketNotificationsPVC.Name,
563568
},
564569
},
@@ -1230,8 +1235,8 @@ func (r *Reconciler) ReconcileDBConfigMap(cm *corev1.ConfigMap, desiredFunc func
12301235
return r.isObjectUpdated(result), nil
12311236
}
12321237

1233-
//ReconcileODFPersistentLoggingPVC ensures a persistent logging pvc (either for bucket logging or bucket notificatoins)
1234-
//is properly configured. If needed and possible, allocate one from CephFS
1238+
// ReconcileODFPersistentLoggingPVC ensures a persistent logging pvc (either for bucket logging or bucket notificatoins)
1239+
// is properly configured. If needed and possible, allocate one from CephFS
12351240
func (r *Reconciler) ReconcileODFPersistentLoggingPVC(
12361241
fieldName string,
12371242
errorName string,
@@ -1243,7 +1248,7 @@ func (r *Reconciler) ReconcileODFPersistentLoggingPVC(
12431248

12441249
// Return if persistent logging PVC already exists
12451250
if pvcName != nil {
1246-
pvc.Name = *pvcName;
1251+
pvc.Name = *pvcName
12471252
log.Infof("PersistentLoggingPVC %s already exists and supports RWX access mode. Skipping ReconcileODFPersistentLoggingPVC.", *pvcName)
12481253
return nil
12491254
}
@@ -1257,7 +1262,7 @@ func (r *Reconciler) ReconcileODFPersistentLoggingPVC(
12571262
if !r.preparePersistentLoggingPVC(pvc, fieldName) {
12581263
return util.NewPersistentError(errorName, errorText)
12591264
}
1260-
r.Own(pvc);
1265+
r.Own(pvc)
12611266

12621267
log.Infof("Persistent logging PVC %s does not exist. Creating...", pvc.Name)
12631268
err := r.Client.Create(r.Ctx, pvc)
@@ -1269,7 +1274,7 @@ func (r *Reconciler) ReconcileODFPersistentLoggingPVC(
12691274

12701275
}
12711276

1272-
//prepare persistent logging pvc
1277+
// prepare persistent logging pvc
12731278
func (r *Reconciler) preparePersistentLoggingPVC(pvc *corev1.PersistentVolumeClaim, fieldName string) bool {
12741279
pvc.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany}
12751280

@@ -1282,9 +1287,9 @@ func (r *Reconciler) preparePersistentLoggingPVC(pvc *corev1.PersistentVolumeCla
12821287
if util.KubeCheck(sc) {
12831288
r.Logger.Infof("%s not provided, defaulting to 'cephfs' storage class %s to create persistent logging pvc", fieldName, sc.Name)
12841289
pvc.Spec.StorageClassName = &sc.Name
1285-
return true;
1290+
return true
12861291
} else {
1287-
return false;
1292+
return false
12881293
}
12891294
}
12901295

0 commit comments

Comments
 (0)