From 85cbd6f04b4429f245a19156fce7639321f3ec61 Mon Sep 17 00:00:00 2001 From: Apurva Gokani Date: Thu, 17 Sep 2020 14:38:14 -0500 Subject: [PATCH] adding archiving to postgres To safeguard postgres from clogging up wal files in pg_xlog directory, This change does the following: 1) adding postgres archiving to move the WAL file to different directory 2) Makes sure that archive is in different Persistent volume. Change-Id: I59bc76f27384d4f3836ef609855afcc33a7b99d0 --- postgresql/Chart.yaml | 2 +- postgresql/templates/statefulset.yaml | 29 ++++++++++++++++++++++----- postgresql/values.yaml | 9 ++++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/postgresql/Chart.yaml b/postgresql/Chart.yaml index c695d01fd..7771f7403 100644 --- a/postgresql/Chart.yaml +++ b/postgresql/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v9.6 description: OpenStack-Helm PostgreSQL name: postgresql -version: 0.1.1 +version: 0.1.2 home: https://www.postgresql.org sources: - https://github.com/postgres/postgres diff --git a/postgresql/templates/statefulset.yaml b/postgresql/templates/statefulset.yaml index 7456a88d8..17f75d982 100644 --- a/postgresql/templates/statefulset.yaml +++ b/postgresql/templates/statefulset.yaml @@ -204,17 +204,22 @@ spec: mountPath: /tmp/readiness.sh subPath: readiness.sh readOnly: true - - name: postgresql-etc - mountPath: /tmp/postgresql.conf - subPath: postgresql.conf - readOnly: true - name: postgresql-etc mountPath: /tmp/pg_hba.conf subPath: pg_hba.conf readOnly: true + - name: postgresql-etc + mountPath: /tmp/postgresql.conf + subPath: postgresql.conf + readOnly: true - name: postgresql-data mountPath: {{ .Values.storage.mount.path }} subPath: {{ .Values.storage.mount.subpath }} +{{- if eq .Values.conf.postgresql.archive_mode "on" }} + - name: postgresql-archive + mountPath: {{ .Values.storage.archive.mount_path }} + subPath: {{ .Values.storage.mount.subpath }} +{{- end }} volumes: - name: pod-tmp emptyDir: {} @@ -235,8 +240,10 @@ spec: - name: postgresql-data hostPath: path: {{ .Values.storage.host.host_path }} -{{- else }} +{{- end }} +{{- if or (eq .Values.conf.postgresql.archive_mode "on" ) (eq .Values.storage.pvc.enabled true) }} volumeClaimTemplates: +{{- if .Values.storage.pvc.enabled }} - metadata: name: postgresql-data annotations: @@ -247,4 +254,16 @@ spec: requests: storage: {{ .Values.storage.pvc.size }} {{- end }} +{{- if eq .Values.conf.postgresql.archive_mode "on" }} + - metadata: + name: postgresql-archive + annotations: + {{ .Values.storage.archive_pvc.class_path }}: {{ .Values.storage.archive_pvc.class_name }} + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: {{ .Values.storage.archive_pvc.size }} +{{- end }} +{{- end }} {{- end }} diff --git a/postgresql/values.yaml b/postgresql/values.yaml index 0cd221b57..adce95570 100644 --- a/postgresql/values.yaml +++ b/postgresql/values.yaml @@ -164,11 +164,17 @@ storage: size: 5Gi class_name: general class_path: volume.beta.kubernetes.io/storage-class + archive_pvc: + size: 5Gi + class_name: general + class_path: volume.beta.kubernetes.io/storage-class host: host_path: /data/openstack-helm/postgresql mount: path: /var/lib/postgresql subpath: . + archive: + mount_path: /var/lib/archive labels: server: @@ -263,7 +269,8 @@ conf: host all all 0.0.0.0/0 reject postgresql: - archive_mode: 'off' + archive_mode: 'on' + archive_command: 'test ! -f /var/lib/archive/%f && gzip < %p > /var/lib/archive/%f' cluster_name: 'postgresql' datestyle: 'iso, mdy' external_pid_file: '/tmp/postgres.pid'