diff --git a/dbutils.c b/dbutils.c index 6353f433..5aa190f4 100644 --- a/dbutils.c +++ b/dbutils.c @@ -888,6 +888,33 @@ create_replication_slot(PGconn *conn, char *slot_name) return true; } +bool +drop_replication_slot(PGconn *conn, char *slot_name) +{ + char sqlquery[QUERY_STR_LEN]; + PGresult *res; + sqlquery_snprintf(sqlquery, + "SELECT pg_drop_replication_slot('%s')", + slot_name); + + log_verbose(LOG_DEBUG, "drop_replication_slot():\n%s\n", sqlquery); + + res = PQexec(conn, sqlquery); + if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) + { + log_err(_("unable to drop replication slot \"%s\":\n %s\n"), + slot_name, + PQerrorMessage(conn)); + PQclear(res); + return false; + } + + log_verbose(LOG_DEBUG, "replication slot \"%s\" successfully dropped\n", + slot_name); + + return true; +} + bool start_backup(PGconn *conn, char *first_wal_segment, bool fast_checkpoint) diff --git a/dbutils.h b/dbutils.h index 88d70dac..3d9d8565 100644 --- a/dbutils.h +++ b/dbutils.h @@ -99,6 +99,7 @@ bool cancel_query(PGconn *conn, int timeout); char *get_repmgr_schema(void); char *get_repmgr_schema_quoted(PGconn *conn); bool create_replication_slot(PGconn *conn, char *slot_name); +bool drop_replication_slot(PGconn *conn, char *slot_name); bool start_backup(PGconn *conn, char *first_wal_segment, bool fast_checkpoint); bool stop_backup(PGconn *conn, char *last_wal_segment);