mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
A few changes from repmgrd and improve the SQL of the repl_status
view in order to actually show something useful
This commit is contained in:
22
repmgr.sql
22
repmgr.sql
@@ -26,11 +26,23 @@ CREATE TABLE repl_monitor (
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A useful view
|
* This view shows the latest monitor info about every node.
|
||||||
|
* Interesting thing to see:
|
||||||
|
* replication_lag: in bytes (this is how far the latest xlog record
|
||||||
|
* we have received is from master)
|
||||||
|
* apply_lag: in bytes (this is how far the latest xlog record
|
||||||
|
* we have applied is from the latest record we
|
||||||
|
* have received)
|
||||||
|
* time-lag: how many seconds are we from being up-to-date with master
|
||||||
*/
|
*/
|
||||||
drop view if exists repl_status;
|
drop view if exists repl_status;
|
||||||
CREATE VIEW repl_status AS
|
CREATE VIEW repl_status AS
|
||||||
SELECT *, now() - (select max(last_monitor_time) from repl_monitor b
|
WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node
|
||||||
where b.primary_node = a.primary_node
|
ORDER BY last_monitor_time desc)
|
||||||
and b.standby_node = a.standby_node)
|
FROM repl_monitor)
|
||||||
FROM repl_monitor a;
|
SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location,
|
||||||
|
last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag,
|
||||||
|
pg_size_pretty(apply_lag) apply_lag,
|
||||||
|
age(now(), last_monitor_time) AS time_lag
|
||||||
|
FROM monitor_info a
|
||||||
|
WHERE row_number = 1;
|
||||||
|
|||||||
34
repmgrd.c
34
repmgrd.c
@@ -33,14 +33,14 @@ bool verbose = false;
|
|||||||
|
|
||||||
|
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
void checkClusterConfiguration(void);
|
static void checkClusterConfiguration(void);
|
||||||
void checkNodeConfiguration(char *conninfo);
|
static void checkNodeConfiguration(char *conninfo);
|
||||||
void getPrimaryConnection(void);
|
static void getPrimaryConnection(void);
|
||||||
|
|
||||||
void MonitorCheck(void);
|
static void MonitorCheck(void);
|
||||||
void MonitorExecute(void);
|
static void MonitorExecute(void);
|
||||||
|
|
||||||
unsigned long long int walLocationToBytes(char *wal_location);
|
static unsigned long long int walLocationToBytes(char *wal_location);
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -111,6 +111,13 @@ main(int argc, char **argv)
|
|||||||
* and start monitor
|
* and start monitor
|
||||||
*/
|
*/
|
||||||
myLocalMode = is_standby(myLocalConn) ? STANDBY_MODE : PRIMARY_MODE;
|
myLocalMode = is_standby(myLocalConn) ? STANDBY_MODE : PRIMARY_MODE;
|
||||||
|
if (myLocalMode == PRIMARY_MODE)
|
||||||
|
{
|
||||||
|
primaryId = myLocalId;
|
||||||
|
strcpy(primaryConninfo, conninfo);
|
||||||
|
primaryConn = myLocalConn;
|
||||||
|
}
|
||||||
|
|
||||||
checkClusterConfiguration();
|
checkClusterConfiguration();
|
||||||
checkNodeConfiguration(conninfo);
|
checkNodeConfiguration(conninfo);
|
||||||
if (myLocalMode == STANDBY_MODE)
|
if (myLocalMode == STANDBY_MODE)
|
||||||
@@ -132,9 +139,7 @@ main(int argc, char **argv)
|
|||||||
* This function ask if we are in recovery, if false we are the primary else
|
* This function ask if we are in recovery, if false we are the primary else
|
||||||
* we are a standby
|
* we are a standby
|
||||||
*/
|
*/
|
||||||
|
static void
|
||||||
|
|
||||||
void
|
|
||||||
getPrimaryConnection(void)
|
getPrimaryConnection(void)
|
||||||
{
|
{
|
||||||
PGresult *res1;
|
PGresult *res1;
|
||||||
@@ -199,7 +204,7 @@ getPrimaryConnection(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
MonitorCheck(void) {
|
MonitorCheck(void) {
|
||||||
/*
|
/*
|
||||||
* Every 3 seconds, insert monitor info
|
* Every 3 seconds, insert monitor info
|
||||||
@@ -215,8 +220,7 @@ MonitorCheck(void) {
|
|||||||
/*
|
/*
|
||||||
* Check if its time for next monitor call and if so, do it.
|
* Check if its time for next monitor call and if so, do it.
|
||||||
*/
|
*/
|
||||||
|
static void
|
||||||
void
|
|
||||||
MonitorExecute(void)
|
MonitorExecute(void)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
@@ -291,7 +295,7 @@ MonitorExecute(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
checkClusterConfiguration(void)
|
checkClusterConfiguration(void)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
@@ -324,7 +328,7 @@ checkClusterConfiguration(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
checkNodeConfiguration(char *conninfo)
|
checkNodeConfiguration(char *conninfo)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
@@ -372,7 +376,7 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long long int
|
static unsigned long long int
|
||||||
walLocationToBytes(char *wal_location)
|
walLocationToBytes(char *wal_location)
|
||||||
{
|
{
|
||||||
unsigned int xlogid;
|
unsigned int xlogid;
|
||||||
|
|||||||
Reference in New Issue
Block a user