mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Add function repmgr_get_primary_conninfo()
This commit is contained in:
15
repmgr.c
15
repmgr.c
@@ -2201,6 +2201,21 @@ create_schema(PGconn *conn)
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
sqlquery_snprintf(sqlquery,
|
||||
"CREATE OR REPLACE FUNCTION %s.repmgr_get_primary_conninfo() "
|
||||
" RETURNS text "
|
||||
" AS '$libdir/repmgr_funcs', 'repmgr_get_primary_conninfo' "
|
||||
" LANGUAGE C STRICT ",
|
||||
get_repmgr_schema_quoted(conn));
|
||||
|
||||
res = PQexec(conn, sqlquery);
|
||||
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
{
|
||||
fprintf(stderr, "Cannot create the function repmgr_get_primary_conninfo: %s\n",
|
||||
PQerrorMessage(conn));
|
||||
return false;
|
||||
}
|
||||
PQclear(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "fmgr.h"
|
||||
#include "access/xlog.h"
|
||||
#include "miscadmin.h"
|
||||
#include "replication/walreceiver.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/lwlock.h"
|
||||
#include "storage/procarray.h"
|
||||
@@ -57,6 +58,8 @@ Datum repmgr_get_last_updated(PG_FUNCTION_ARGS);
|
||||
PG_FUNCTION_INFO_V1(repmgr_update_last_updated);
|
||||
PG_FUNCTION_INFO_V1(repmgr_get_last_updated);
|
||||
|
||||
Datum repmgr_get_primary_conninfo(PG_FUNCTION_ARGS);
|
||||
PG_FUNCTION_INFO_V1(repmgr_get_primary_conninfo);
|
||||
|
||||
/*
|
||||
* Module load callback
|
||||
@@ -230,3 +233,20 @@ repmgr_get_last_updated(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_TIMESTAMPTZ(last_updated);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get the `primary_conninfo` string used by walreceiver,
|
||||
* which is the value parsed from recovery.conf at startup
|
||||
*
|
||||
* XXX is there a better way of doing this?
|
||||
*/
|
||||
Datum
|
||||
repmgr_get_primary_conninfo(PG_FUNCTION_ARGS)
|
||||
{
|
||||
/* use volatile pointer to prevent code rearrangement */
|
||||
volatile WalRcvData *walrcv = WalRcv;
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text((const char *)walrcv->conninfo));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,3 +21,7 @@ LANGUAGE C STRICT;
|
||||
CREATE FUNCTION repmgr_get_last_updated() RETURNS TIMESTAMP WITH TIME ZONE
|
||||
AS 'MODULE_PATHNAME', 'repmgr_get_last_updated'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
CREATE FUNCTION repmgr_get_primary_conninfo() RETURNS TEXT
|
||||
AS 'MODULE_PATHNAME', 'repmgr_get_primary_conninfo'
|
||||
LANGUAGE C STRICT;
|
||||
|
||||
Reference in New Issue
Block a user