Skip to content

Commit

Permalink
Use Patroni SetPostgresParameters() to change log_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
rafia sabih committed Aug 7, 2024
1 parent 4bc1d9c commit aef3851
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ func (c *Cluster) Create() (err error) {
}
}

if c.Spec.WalPvc != nil {
log_dir := map[string]string{
"log_directory": constants.PostgresPVCWalMount,
}
pods, _ := c.listPodsOfType(TYPE_POSTGRESQL)
for _, p := range pods {
err := c.patroni.SetPostgresParameters(&p, log_dir)
if err != nil {
return fmt.Errorf("log_directory with pvc could not be set: %v", err)
}
}

}

// remember slots to detect deletion from manifest
for slotName, desiredSlot := range c.Spec.Patroni.Slots {
c.replicationSlots[slotName] = desiredSlot
Expand Down
16 changes: 14 additions & 2 deletions pkg/cluster/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1766,9 +1766,21 @@ func (c *Cluster) syncWalPvc(oldSpec, newSpec *cpov1.Postgresql) error {

if newSpec.Spec.WalPvc == nil && oldSpec.Spec.WalPvc != nil {
// if the wal_pvc is removed, then
// 1. Change env-vars
// 1. Change log_directory
// 2. Remove the PVC
// 3. Remember the old dir name
// 3. Change env vars

log_dir := map[string]string{
"log_directory": constants.PostgresWalMount,
}
pods, _ := c.listPodsOfType(TYPE_POSTGRESQL)
for _, p := range pods {
err := c.patroni.SetPostgresParameters(&p, log_dir)
if err != nil {
return fmt.Errorf("log_directory with pvc could not be set: %v", err)
}
}

pvcs, err := c.listPersistentVolumeClaims()
if err != nil {
return fmt.Errorf("Could not list PVCs")
Expand Down

0 comments on commit aef3851

Please sign in to comment.