Skip to content

Commit c6cd12c

Browse files
authored
Remove replication slot on member unregistration (#252)
1 parent 92bc940 commit c6cd12c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/pg_unregister/main.go

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
"github.com/fly-apps/postgres-flex/internal/flypg"
10+
"github.com/fly-apps/postgres-flex/internal/flypg/admin"
1011
"github.com/fly-apps/postgres-flex/internal/utils"
1112
)
1213

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

52+
slots, err := admin.ListReplicationSlots(ctx, conn)
53+
if err != nil {
54+
return fmt.Errorf("failed to list replication slots: %v", err)
55+
}
56+
57+
targetSlot := fmt.Sprintf("repmgr_slot_%d", member.ID)
58+
for _, slot := range slots {
59+
if slot.Name == targetSlot {
60+
if err := admin.DropReplicationSlot(ctx, conn, targetSlot); err != nil {
61+
return fmt.Errorf("failed to drop replication slot: %v", err)
62+
}
63+
break
64+
}
65+
}
66+
5167
return nil
5268
}

0 commit comments

Comments
 (0)