Skip to content

Commit 4f451a4

Browse files
andrewlecuyerJonathan S. Katz
authored andcommitted
Delete WAL PVC for Replica Only on Scale Down
When scaling down a replica within a PostgreSQL cluster that utilizes external PVC's for write-ahead-logs (WAL), only the WAL PVC for replica being removed is deleted, and the WAL PVC's for all other PostgreSQL instances within the cluster remain in place. Issue: [ch9338] Issue: #1915
1 parent cf1ff08 commit 4f451a4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pgo-rmdata/rmdata/process.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const (
4040
tablespacePathFormat = "/tablespaces/%s/%s"
4141
// the tablespace on a replcia follows the pattern "<replicaName-tablespace-.."
4242
tablespaceReplicaPVCPattern = "%s-tablespace-"
43-
// the WAL PVC has the following suffix
44-
walPVCSuffix = "-wal"
43+
// the WAL PVC on a replcia follows the pattern "<replicaName-wal>"
44+
walReplicaPVCPattern = "%s-wal"
4545

4646
// the following constants define the suffixes for the various configMaps created by Patroni
4747
configConfigMapSuffix = "config"
@@ -525,13 +525,16 @@ func getReplicaPVC(request Request) ([]string, error) {
525525

526526
// ...and where the fun begins
527527
tablespaceReplicaPVCPrefix := fmt.Sprintf(tablespaceReplicaPVCPattern, request.ReplicaName)
528+
walReplicaPVCName := fmt.Sprintf(walReplicaPVCPattern, request.ReplicaName)
528529

529530
// iterate over the PVC list and append the tablespace PVCs
530531
for _, pvc := range pvcs.Items {
531532
pvcName := pvc.ObjectMeta.Name
532533

533-
// it does not start with the tablespace replica PVC pattern, continue
534-
if !(strings.HasPrefix(pvcName, tablespaceReplicaPVCPrefix) || strings.HasSuffix(pvcName, walPVCSuffix)) {
534+
// if it does not start with the tablespace replica PVC pattern and does not equal the WAL
535+
// PVC pattern then continue
536+
if !(strings.HasPrefix(pvcName, tablespaceReplicaPVCPrefix) ||
537+
pvcName == walReplicaPVCName) {
535538
continue
536539
}
537540

0 commit comments

Comments
 (0)