From 6108c65b0cef7b375438a55d041ba4702b47cba5 Mon Sep 17 00:00:00 2001 From: wbsong111 Date: Mon, 6 Jan 2025 11:01:31 +0900 Subject: [PATCH] Fix issue with applying postgresql.conf to PostgreSQL --- .../postgresql-ha/templates/_configuration.tpl | 13 +++++++++++++ .../templates/postgresql/statefulset.yaml | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/charts/postgresql-ha/templates/_configuration.tpl b/charts/postgresql-ha/templates/_configuration.tpl index 16e1bdd..561c1b4 100644 --- a/charts/postgresql-ha/templates/_configuration.tpl +++ b/charts/postgresql-ha/templates/_configuration.tpl @@ -1,3 +1,14 @@ +{{/* +Enable the PostgreSQL configuration automatically +*/}} +{{- define "postgresql-ha.configuration.postgresql.enabled" -}} +{{- if and (or .Values.postgresql.repmgrConfiguration .Values.postgresql.configuration .Values.postgresql.pgHbaConfiguration) (not .Values.postgresql.configurationCM) }} + false +{{- else }} + true +{{- end }} +{{- end }} + {{/* Return Postgresql - memory */}} @@ -58,6 +69,8 @@ wal_buffers = -1 max_wal_size = 10GB min_wal_size = 1GB +shared_preload_libraries = '{{ .Values.postgresql.sharedPreloadLibraries }}' + shared_buffers = {{ div $memory 4 }}MB effective_cache_size = {{ mul (div $memory 4) 3 }}MB diff --git a/charts/postgresql-ha/templates/postgresql/statefulset.yaml b/charts/postgresql-ha/templates/postgresql/statefulset.yaml index 4af9522..1d170a2 100644 --- a/charts/postgresql-ha/templates/postgresql/statefulset.yaml +++ b/charts/postgresql-ha/templates/postgresql/statefulset.yaml @@ -122,6 +122,9 @@ spec: chown {{ .Values.postgresql.containerSecurityContext.runAsUser }}:{{ .Values.postgresql.podSecurityContext.fsGroup }} {{ .Values.persistence.mountPath }} find {{ .Values.persistence.mountPath }} -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | \ xargs -r chown -R {{ .Values.postgresql.containerSecurityContext.runAsUser }}:{{ .Values.postgresql.podSecurityContext.fsGroup }} + {{- if ( include "postgresql-ha.configuration.postgresql.enabled" . ) }} + chmod -R 777 /dev/shm + {{- end }} securityContext: {{- .Values.volumePermissions.podSecurityContext | toYaml | nindent 12 }} {{- if .Values.volumePermissions.resources }} resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }} @@ -129,6 +132,10 @@ spec: volumeMounts: - name: data mountPath: {{ .Values.persistence.mountPath }} + {{- if ( include "postgresql-ha.configuration.postgresql.enabled" . ) }} + - name: dshm + mountPath: /dev/shm + {{- end }} {{- end }} {{- if or .Values.postgresql.initContainers .Values.postgresql.extraInitContainers }} {{- include "common.tplvalues.render" ( dict "value" (coalesce .Values.postgresql.initContainers .Values.postgresql.extraInitContainers) "context" $ ) | nindent 8 }} @@ -458,7 +465,9 @@ spec: {{- if .Values.postgresql.extraVolumeMounts }} {{- include "common.tplvalues.render" (dict "value" .Values.postgresql.extraVolumeMounts "context" $) | nindent 12 }} {{- end }} - {{- if ( include "postgresql-ha.configuration.postgresql.sharedMemory" . ) }} + {{- if ( include "postgresql-ha.configuration.postgresql.enabled" . ) }} + - name: postgresql-config + mountPath: /bitnami/repmgr/conf - name: dshm mountPath: /dev/shm {{- end }} @@ -602,7 +611,10 @@ spec: - name: postgresql-certificates emptyDir: {} {{- end }} - {{- if ( include "postgresql-ha.configuration.postgresql.sharedMemory" . ) }} + {{- if ( include "postgresql-ha.configuration.postgresql.enabled" . ) }} + - name: postgresql-config + configMap: + name: {{ include "postgresql-ha.postgresqlConfigurationCM" . }} - name: dshm emptyDir: medium: Memory