mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
repmgr: consolidate error messages during replication slot generation
Return error messages to the called so they can be logged as events; prevent log message duplication in one case.
This commit is contained in:
21
dbutils.c
21
dbutils.c
@@ -945,7 +945,7 @@ get_repmgr_schema_quoted(PGconn *conn)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
create_replication_slot(PGconn *conn, char *slot_name, int server_version_num)
|
create_replication_slot(PGconn *conn, char *slot_name, int server_version_num, PQExpBufferData *error_msg)
|
||||||
{
|
{
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
int query_res;
|
int query_res;
|
||||||
@@ -964,8 +964,9 @@ create_replication_slot(PGconn *conn, char *slot_name, int server_version_num)
|
|||||||
{
|
{
|
||||||
if (strcmp(slot_info.slot_type, "physical") != 0)
|
if (strcmp(slot_info.slot_type, "physical") != 0)
|
||||||
{
|
{
|
||||||
log_err(_("Slot '%s' exists and is not a physical slot\n"),
|
appendPQExpBuffer(error_msg,
|
||||||
slot_name);
|
_("Slot '%s' exists and is not a physical slot\n"),
|
||||||
|
slot_name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -977,8 +978,9 @@ create_replication_slot(PGconn *conn, char *slot_name, int server_version_num)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_err(_("Slot '%s' already exists as an active slot\n"),
|
appendPQExpBuffer(error_msg,
|
||||||
slot_name);
|
_("Slot '%s' already exists as an active slot\n"),
|
||||||
|
slot_name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,15 +998,16 @@ create_replication_slot(PGconn *conn, char *slot_name, int server_version_num)
|
|||||||
slot_name);
|
slot_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug(_("create_replication_slot(): Creating slot '%s' on primary\n"), slot_name);
|
log_debug(_("create_replication_slot(): Creating slot '%s' on master\n"), slot_name);
|
||||||
log_verbose(LOG_DEBUG, "create_replication_slot():\n%s\n", sqlquery);
|
log_verbose(LOG_DEBUG, "create_replication_slot():\n%s\n", sqlquery);
|
||||||
|
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
log_err(_("unable to create slot '%s' on the primary node: %s\n"),
|
appendPQExpBuffer(error_msg,
|
||||||
slot_name,
|
_("unable to create slot '%s' on the master node: %s\n"),
|
||||||
PQerrorMessage(conn));
|
slot_name,
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define _REPMGR_DBUTILS_H_
|
#define _REPMGR_DBUTILS_H_
|
||||||
|
|
||||||
#include "access/xlogdefs.h"
|
#include "access/xlogdefs.h"
|
||||||
|
#include "pqexpbuffer.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
@@ -118,7 +119,7 @@ int wait_connection_availability(PGconn *conn, long long timeout);
|
|||||||
bool cancel_query(PGconn *conn, int timeout);
|
bool cancel_query(PGconn *conn, int timeout);
|
||||||
char *get_repmgr_schema(void);
|
char *get_repmgr_schema(void);
|
||||||
char *get_repmgr_schema_quoted(PGconn *conn);
|
char *get_repmgr_schema_quoted(PGconn *conn);
|
||||||
bool create_replication_slot(PGconn *conn, char *slot_name, int server_version_num);
|
bool create_replication_slot(PGconn *conn, char *slot_name, int server_version_num, PQExpBufferData *error_msg);
|
||||||
int get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record);
|
int get_slot_record(PGconn *conn, char *slot_name, t_replication_slot *record);
|
||||||
bool drop_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 start_backup(PGconn *conn, char *first_wal_segment, bool fast_checkpoint);
|
||||||
|
|||||||
31
repmgr.c
31
repmgr.c
@@ -2309,11 +2309,25 @@ do_standby_clone(void)
|
|||||||
*/
|
*/
|
||||||
if (mode != barman && options.use_replication_slots)
|
if (mode != barman && options.use_replication_slots)
|
||||||
{
|
{
|
||||||
if (create_replication_slot(source_conn, repmgr_slot_name, server_version_num) == false)
|
PQExpBufferData event_details;
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
if (create_replication_slot(source_conn, repmgr_slot_name, server_version_num, &event_details) == false)
|
||||||
{
|
{
|
||||||
|
log_err("%s\n", event_details.data);
|
||||||
|
|
||||||
|
create_event_record(primary_conn,
|
||||||
|
&options,
|
||||||
|
options.node,
|
||||||
|
"standby_clone",
|
||||||
|
false,
|
||||||
|
event_details.data);
|
||||||
|
|
||||||
PQfinish(source_conn);
|
PQfinish(source_conn);
|
||||||
exit(ERR_DB_QUERY);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == rsync)
|
if (mode == rsync)
|
||||||
@@ -3576,16 +3590,11 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
int server_version_num = get_server_version(master_conn, NULL);
|
int server_version_num = get_server_version(master_conn, NULL);
|
||||||
|
|
||||||
if (create_replication_slot(master_conn, repmgr_slot_name, server_version_num) == false)
|
PQExpBufferData event_details;
|
||||||
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
|
if (create_replication_slot(master_conn, repmgr_slot_name, server_version_num, &event_details) == false)
|
||||||
{
|
{
|
||||||
PQExpBufferData event_details;
|
|
||||||
initPQExpBuffer(&event_details);
|
|
||||||
|
|
||||||
appendPQExpBuffer(&event_details,
|
|
||||||
_("Unable to create slot '%s' on the master node: %s"),
|
|
||||||
repmgr_slot_name,
|
|
||||||
PQerrorMessage(master_conn));
|
|
||||||
|
|
||||||
log_err("%s\n", event_details.data);
|
log_err("%s\n", event_details.data);
|
||||||
|
|
||||||
create_event_record(master_conn,
|
create_event_record(master_conn,
|
||||||
@@ -3598,6 +3607,8 @@ do_standby_follow(void)
|
|||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
exit(ERR_DB_QUERY);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
termPQExpBuffer(&event_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX add more detail! */
|
/* XXX add more detail! */
|
||||||
|
|||||||
Reference in New Issue
Block a user