Skip to content

Commit

Permalink
Remove replication slot on member unregistration (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
davissp14 authored Aug 1, 2024
1 parent 92bc940 commit c6cd12c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/pg_unregister/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/fly-apps/postgres-flex/internal/flypg"
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
"github.com/fly-apps/postgres-flex/internal/utils"
)

Expand Down Expand Up @@ -48,5 +49,20 @@ func processUnregistration(ctx context.Context) error {
return fmt.Errorf("failed to unregister member: %v", err)
}

slots, err := admin.ListReplicationSlots(ctx, conn)
if err != nil {
return fmt.Errorf("failed to list replication slots: %v", err)
}

targetSlot := fmt.Sprintf("repmgr_slot_%d", member.ID)
for _, slot := range slots {
if slot.Name == targetSlot {
if err := admin.DropReplicationSlot(ctx, conn, targetSlot); err != nil {
return fmt.Errorf("failed to drop replication slot: %v", err)
}
break
}
}

return nil
}

0 comments on commit c6cd12c

Please sign in to comment.