Skip to content

Commit 49dec7e

Browse files
committed
List replication slots
1 parent 4e9284f commit 49dec7e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/flypg/admin/admin.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ func DeleteDatabase(ctx context.Context, pg *pgx.Conn, name string) error {
7575
return nil
7676
}
7777

78+
func ListReplicationSlots(ctx context.Context, pg *pgx.Conn) ([]ReplicationSlot, error) {
79+
sql := fmt.Sprintf("SELECT slot_name, slot_type, active, wal_status from pg_replication_slots;")
80+
rows, err := pg.Query(ctx, sql)
81+
defer rows.Close()
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
var slots []ReplicationSlot
87+
88+
for rows.Next() {
89+
var slot ReplicationSlot
90+
if err := rows.Scan(&slot.Name, &slot.Type, &slot.Active, &slot.WalStatus); err != nil {
91+
return nil, err
92+
}
93+
94+
slots = append(slots, slot)
95+
}
96+
97+
return slots, nil
98+
}
99+
78100
func DropReplicationSlot(ctx context.Context, pg *pgx.Conn, name string) error {
79101
sql := fmt.Sprintf("SELECT pg_drop_replication_slot('%s');", name)
80102

@@ -152,6 +174,13 @@ type DbInfo struct {
152174
Users []string `json:"users"`
153175
}
154176

177+
type ReplicationSlot struct {
178+
Name string
179+
Type string
180+
Active bool
181+
WalStatus string
182+
}
183+
155184
func ListUsers(ctx context.Context, pg *pgx.Conn) ([]UserInfo, error) {
156185
sql := `
157186
select u.usename,

0 commit comments

Comments
 (0)