mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Add SQL functions to monitor the directory contents of replication slots
This commit adds a set of functions able to look at the contents of various paths related to replication slots: - pg_ls_logicalsnapdir, for pg_logical/snapshots/ - pg_ls_logicalmapdir, for pg_logical/mappings/ - pg_ls_replslotdir, for pg_replslot/<slot_name>/ These are intended to be used by monitoring tools. Unlike pg_ls_dir(), execution permission can be granted to non-superusers. Roles members of pg_monitor gain have access to those functions. Bump catalog version. Author: Bharath Rupireddy Reviewed-by: Nathan Bossart, Justin Pryzby Discussion: https://postgr.es/m/CALj2ACWsfizZjMN6bzzdxOk1ADQQeSw8HhEjhmVXn_Pu+7VzLw@mail.gmail.com
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
#include "mb/pg_wchar.h"
|
||||
#include "miscadmin.h"
|
||||
#include "postmaster/syslogger.h"
|
||||
#include "replication/slot.h"
|
||||
#include "storage/fd.h"
|
||||
#include "utils/acl.h"
|
||||
#include "utils/builtins.h"
|
||||
@ -720,3 +721,46 @@ pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return pg_ls_dir_files(fcinfo, XLOGDIR "/archive_status", true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to return the list of files in the pg_logical/snapshots directory.
|
||||
*/
|
||||
Datum
|
||||
pg_ls_logicalsnapdir(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return pg_ls_dir_files(fcinfo, "pg_logical/snapshots", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to return the list of files in the pg_logical/mappings directory.
|
||||
*/
|
||||
Datum
|
||||
pg_ls_logicalmapdir(PG_FUNCTION_ARGS)
|
||||
{
|
||||
return pg_ls_dir_files(fcinfo, "pg_logical/mappings", false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to return the list of files in the pg_replslot/<replication_slot>
|
||||
* directory.
|
||||
*/
|
||||
Datum
|
||||
pg_ls_replslotdir(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *slotname_t;
|
||||
char path[MAXPGPATH];
|
||||
char *slotname;
|
||||
|
||||
slotname_t = PG_GETARG_TEXT_PP(0);
|
||||
|
||||
slotname = text_to_cstring(slotname_t);
|
||||
|
||||
if (!SearchNamedReplicationSlot(slotname, true))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("replication slot \"%s\" does not exist",
|
||||
slotname)));
|
||||
|
||||
snprintf(path, sizeof(path), "pg_replslot/%s", slotname);
|
||||
return pg_ls_dir_files(fcinfo, path, false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user