use appendPQExpBufferStr/-Char() consistently

This commit is contained in:
Ian Barwick
2018-10-04 08:42:42 +09:00
parent 15a5d2ee9d
commit 3e38759c02
6 changed files with 257 additions and 262 deletions

View File

@@ -88,8 +88,7 @@ load_config(const char *config_file, bool verbose, bool terse, t_configuration_o
if (pwd != NULL) if (pwd != NULL)
{ {
appendPQExpBuffer(&fullpath, appendPQExpBufferStr(&fullpath, pwd);
"%s", pwd);
} }
else else
{ {
@@ -105,9 +104,7 @@ load_config(const char *config_file, bool verbose, bool terse, t_configuration_o
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
appendPQExpBuffer(&fullpath, appendPQExpBufferStr(&fullpath, cwd);
"%s",
cwd);
} }
appendPQExpBuffer(&fullpath, appendPQExpBuffer(&fullpath,
@@ -1111,8 +1108,8 @@ reload_config(t_configuration_options *orig_options, t_server_type server_type)
initPQExpBuffer(&errors); initPQExpBuffer(&errors);
appendPQExpBuffer(&errors, appendPQExpBufferStr(&errors,
"following errors were detected:\n"); "following errors were detected:\n");
for (cell = config_errors.head; cell; cell = cell->next) for (cell = config_errors.head; cell; cell = cell->next)
{ {

432
dbutils.c
View File

@@ -115,20 +115,20 @@ wrap_ddl_query(PQExpBufferData *query_buf, int replication_type, const char *fmt
if (replication_type == REPLICATION_TYPE_BDR) if (replication_type == REPLICATION_TYPE_BDR)
{ {
if (bdr_version_num < 3) if (bdr_version_num < 3)
appendPQExpBuffer(query_buf, "SELECT bdr.bdr_replicate_ddl_command($repmgr$"); appendPQExpBufferStr(query_buf, "SELECT bdr.bdr_replicate_ddl_command($repmgr$");
else else
appendPQExpBuffer(query_buf, "SELECT bdr.replicate_ddl_command($repmgr$"); appendPQExpBufferStr(query_buf, "SELECT bdr.replicate_ddl_command($repmgr$");
} }
va_start(arglist, fmt); va_start(arglist, fmt);
vsnprintf(buf, MAXLEN, fmt, arglist); vsnprintf(buf, MAXLEN, fmt, arglist);
va_end(arglist); va_end(arglist);
appendPQExpBuffer(query_buf, "%s", buf); appendPQExpBufferStr(query_buf, buf);
if (replication_type == REPLICATION_TYPE_BDR) if (replication_type == REPLICATION_TYPE_BDR)
{ {
appendPQExpBuffer(query_buf, "$repmgr$)"); appendPQExpBufferStr(query_buf, "$repmgr$)");
} }
} }
@@ -1070,9 +1070,9 @@ get_cluster_size(PGconn *conn, char *size)
bool success = true; bool success = true;
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT pg_catalog.pg_size_pretty(pg_catalog.sum(pg_catalog.pg_database_size(oid))::bigint) " "SELECT pg_catalog.pg_size_pretty(pg_catalog.sum(pg_catalog.pg_database_size(oid))::bigint) "
" FROM pg_catalog.pg_database "); " FROM pg_catalog.pg_database ");
log_verbose(LOG_DEBUG, "get_cluster_size():\n%s", query.data); log_verbose(LOG_DEBUG, "get_cluster_size():\n%s", query.data);
@@ -1228,13 +1228,13 @@ _get_primary_connection(PGconn *conn,
log_verbose(LOG_INFO, _("searching for primary node")); log_verbose(LOG_INFO, _("searching for primary node"));
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT node_id, conninfo, " " SELECT node_id, conninfo, "
" CASE WHEN type = 'primary' THEN 1 ELSE 2 END AS type_priority" " CASE WHEN type = 'primary' THEN 1 ELSE 2 END AS type_priority"
" FROM repmgr.nodes " " FROM repmgr.nodes "
" WHERE active IS TRUE " " WHERE active IS TRUE "
" AND type != 'witness' " " AND type != 'witness' "
"ORDER BY active DESC, type_priority, priority, node_id"); "ORDER BY active DESC, type_priority, priority, node_id");
log_verbose(LOG_DEBUG, "get_primary_connection():\n%s", query.data); log_verbose(LOG_DEBUG, "get_primary_connection():\n%s", query.data);
@@ -1341,11 +1341,11 @@ get_primary_node_id(PGconn *conn)
int retval = NODE_NOT_FOUND; int retval = NODE_NOT_FOUND;
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT node_id " "SELECT node_id "
" FROM repmgr.nodes " " FROM repmgr.nodes "
" WHERE type = 'primary' " " WHERE type = 'primary' "
" AND active IS TRUE "); " AND active IS TRUE ");
log_verbose(LOG_DEBUG, "get_primary_node_id():\n%s", query.data); log_verbose(LOG_DEBUG, "get_primary_node_id():\n%s", query.data);
@@ -1384,38 +1384,38 @@ get_replication_info(PGconn *conn, ReplInfo *replication_info)
server_version_num = get_server_version(conn, NULL); server_version_num = get_server_version(conn, NULL);
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT ts, " " SELECT ts, "
" last_wal_receive_lsn, " " last_wal_receive_lsn, "
" last_wal_replay_lsn, " " last_wal_replay_lsn, "
" last_xact_replay_timestamp, " " last_xact_replay_timestamp, "
" CASE WHEN (last_wal_receive_lsn = last_wal_replay_lsn) " " CASE WHEN (last_wal_receive_lsn = last_wal_replay_lsn) "
" THEN 0::INT " " THEN 0::INT "
" ELSE " " ELSE "
" EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - last_xact_replay_timestamp))::INT " " EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - last_xact_replay_timestamp))::INT "
" END AS replication_lag_time, " " END AS replication_lag_time, "
" COALESCE(last_wal_receive_lsn, '0/0') >= last_wal_replay_lsn AS receiving_streamed_wal " " COALESCE(last_wal_receive_lsn, '0/0') >= last_wal_replay_lsn AS receiving_streamed_wal "
" FROM ( "); " FROM ( ");
if (server_version_num >= 100000) if (server_version_num >= 100000)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT CURRENT_TIMESTAMP AS ts, " " SELECT CURRENT_TIMESTAMP AS ts, "
" pg_catalog.pg_last_wal_receive_lsn() AS last_wal_receive_lsn, " " pg_catalog.pg_last_wal_receive_lsn() AS last_wal_receive_lsn, "
" pg_catalog.pg_last_wal_replay_lsn() AS last_wal_replay_lsn, " " pg_catalog.pg_last_wal_replay_lsn() AS last_wal_replay_lsn, "
" pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); " pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT CURRENT_TIMESTAMP AS ts, " " SELECT CURRENT_TIMESTAMP AS ts, "
" pg_catalog.pg_last_xlog_receive_location() AS last_wal_receive_lsn, " " pg_catalog.pg_last_xlog_receive_location() AS last_wal_receive_lsn, "
" pg_catalog.pg_last_xlog_replay_location() AS last_wal_replay_lsn, " " pg_catalog.pg_last_xlog_replay_location() AS last_wal_replay_lsn, "
" pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); " pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
} }
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" ) q "); " ) q ");
log_verbose(LOG_DEBUG, "get_replication_info():\n%s", query.data); log_verbose(LOG_DEBUG, "get_replication_info():\n%s", query.data);
@@ -1538,21 +1538,21 @@ get_replication_lag_seconds(PGconn *conn)
if (server_version_num >= 100000) if (server_version_num >= 100000)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT CASE WHEN (pg_catalog.pg_last_wal_receive_lsn() = pg_catalog.pg_last_wal_replay_lsn()) "); " SELECT CASE WHEN (pg_catalog.pg_last_wal_receive_lsn() = pg_catalog.pg_last_wal_replay_lsn()) ");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT CASE WHEN (pg_catalog.pg_last_xlog_receive_location() = pg_catalog.pg_last_xlog_replay_location()) "); " SELECT CASE WHEN (pg_catalog.pg_last_xlog_receive_location() = pg_catalog.pg_last_xlog_replay_location()) ");
} }
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" THEN 0 " " THEN 0 "
" ELSE EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - pg_catalog.pg_last_xact_replay_timestamp()))::INT " " ELSE EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - pg_catalog.pg_last_xact_replay_timestamp()))::INT "
" END " " END "
" AS lag_seconds"); " AS lag_seconds");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
log_verbose(LOG_DEBUG, "get_replication_lag_seconds():\n%s", query.data); log_verbose(LOG_DEBUG, "get_replication_lag_seconds():\n%s", query.data);
@@ -1842,12 +1842,12 @@ get_repmgr_extension_status(PGconn *conn)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT ae.name, e.extname " " SELECT ae.name, e.extname "
" FROM pg_catalog.pg_available_extensions ae " " FROM pg_catalog.pg_available_extensions ae "
"LEFT JOIN pg_catalog.pg_extension e " "LEFT JOIN pg_catalog.pg_extension e "
" ON e.extname=ae.name " " ON e.extname=ae.name "
" WHERE ae.name='repmgr' "); " WHERE ae.name='repmgr' ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
@@ -2234,10 +2234,10 @@ get_all_node_records(PGconn *conn, NodeInfoList *node_list)
bool success = true; bool success = true;
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT " REPMGR_NODES_COLUMNS " SELECT " REPMGR_NODES_COLUMNS
" FROM repmgr.nodes n " " FROM repmgr.nodes n "
"ORDER BY n.node_id "); "ORDER BY n.node_id ");
log_verbose(LOG_DEBUG, "get_all_node_records():\n%s", query.data); log_verbose(LOG_DEBUG, "get_all_node_records():\n%s", query.data);
@@ -2340,10 +2340,10 @@ get_node_records_by_priority(PGconn *conn, NodeInfoList *node_list)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT " REPMGR_NODES_COLUMNS " SELECT " REPMGR_NODES_COLUMNS
" FROM repmgr.nodes n " " FROM repmgr.nodes n "
"ORDER BY n.priority DESC, n.node_name "); "ORDER BY n.priority DESC, n.node_name ");
log_verbose(LOG_DEBUG, "get_node_records_by_priority():\n%s", query.data); log_verbose(LOG_DEBUG, "get_node_records_by_priority():\n%s", query.data);
@@ -2377,13 +2377,13 @@ get_all_node_records_with_upstream(PGconn *conn, NodeInfoList *node_list)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT n.node_id, n.type, n.upstream_node_id, n.node_name, n.conninfo, n.repluser, " " SELECT n.node_id, n.type, n.upstream_node_id, n.node_name, n.conninfo, n.repluser, "
" n.slot_name, n.location, n.priority, n.active, n.config_file, un.node_name AS upstream_node_name " " n.slot_name, n.location, n.priority, n.active, n.config_file, un.node_name AS upstream_node_name "
" FROM repmgr.nodes n " " FROM repmgr.nodes n "
" LEFT JOIN repmgr.nodes un " " LEFT JOIN repmgr.nodes un "
" ON un.node_id = n.upstream_node_id" " ON un.node_id = n.upstream_node_id"
" ORDER BY n.node_id "); " ORDER BY n.node_id ");
log_verbose(LOG_DEBUG, "get_all_node_records_with_upstream():\n%s", query.data); log_verbose(LOG_DEBUG, "get_all_node_records_with_upstream():\n%s", query.data);
@@ -2526,31 +2526,30 @@ _create_update_node_record(PGconn *conn, char *action, t_node_info *node_info)
if (strcmp(action, "create") == 0) if (strcmp(action, "create") == 0)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"INSERT INTO repmgr.nodes " "INSERT INTO repmgr.nodes "
" (node_id, type, upstream_node_id, " " (node_id, type, upstream_node_id, "
" node_name, conninfo, repluser, slot_name, " " node_name, conninfo, repluser, slot_name, "
" location, priority, active, config_file) " " location, priority, active, config_file) "
"VALUES ($11, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) "); "VALUES ($11, $1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"UPDATE repmgr.nodes SET " "UPDATE repmgr.nodes SET "
" type = $1, " " type = $1, "
" upstream_node_id = $2, " " upstream_node_id = $2, "
" node_name = $3, " " node_name = $3, "
" conninfo = $4, " " conninfo = $4, "
" repluser = $5, " " repluser = $5, "
" slot_name = $6, " " slot_name = $6, "
" location = $7, " " location = $7, "
" priority = $8, " " priority = $8, "
" active = $9, " " active = $9, "
" config_file = $10 " " config_file = $10 "
" WHERE node_id = $11 "); " WHERE node_id = $11 ");
} }
res = PQexecParams(conn, res = PQexecParams(conn,
query.data, query.data,
param_count, param_count,
@@ -2987,31 +2986,31 @@ get_node_replication_stats(PGconn *conn, int server_version_num, t_node_info *no
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT pg_catalog.current_setting('max_wal_senders')::INT AS max_wal_senders, " " SELECT pg_catalog.current_setting('max_wal_senders')::INT AS max_wal_senders, "
" (SELECT pg_catalog.count(*) FROM pg_catalog.pg_stat_replication) AS attached_wal_receivers, "); " (SELECT pg_catalog.count(*) FROM pg_catalog.pg_stat_replication) AS attached_wal_receivers, ");
/* no replication slots in PostgreSQL 9.3 */ /* no replication slots in PostgreSQL 9.3 */
if (server_version_num < 90400) if (server_version_num < 90400)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" 0 AS max_replication_slots, " " 0 AS max_replication_slots, "
" 0 AS total_replication_slots, " " 0 AS total_replication_slots, "
" 0 AS active_replication_slots, " " 0 AS active_replication_slots, "
" 0 AS inactive_replication_slots, "); " 0 AS inactive_replication_slots, ");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" current_setting('max_replication_slots')::INT AS max_replication_slots, " " current_setting('max_replication_slots')::INT AS max_replication_slots, "
" (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots) AS total_replication_slots, " " (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots) AS total_replication_slots, "
" (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots WHERE active IS TRUE) AS active_replication_slots, " " (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots WHERE active IS TRUE) AS active_replication_slots, "
" (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots WHERE active IS FALSE) AS inactive_replication_slots, "); " (SELECT pg_catalog.count(*) FROM pg_catalog.pg_replication_slots WHERE active IS FALSE) AS inactive_replication_slots, ");
} }
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" pg_catalog.pg_is_in_recovery() AS in_recovery"); " pg_catalog.pg_is_in_recovery() AS in_recovery");
log_verbose(LOG_DEBUG, "get_node_replication_stats():\n%s", query.data); log_verbose(LOG_DEBUG, "get_node_replication_stats():\n%s", query.data);
@@ -3152,26 +3151,26 @@ get_datadir_configuration_files(PGconn *conn, KeyValueList *list)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"WITH files AS ( " "WITH files AS ( "
" WITH dd AS ( " " WITH dd AS ( "
" SELECT setting " " SELECT setting "
" FROM pg_catalog.pg_settings " " FROM pg_catalog.pg_settings "
" WHERE name = 'data_directory') " " WHERE name = 'data_directory') "
" SELECT distinct(sourcefile) AS config_file" " SELECT distinct(sourcefile) AS config_file"
" FROM dd, pg_catalog.pg_settings ps " " FROM dd, pg_catalog.pg_settings ps "
" WHERE ps.sourcefile IS NOT NULL " " WHERE ps.sourcefile IS NOT NULL "
" AND ps.sourcefile ~ ('^' || dd.setting) " " AND ps.sourcefile ~ ('^' || dd.setting) "
" UNION " " UNION "
" SELECT ps.setting AS config_file" " SELECT ps.setting AS config_file"
" FROM dd, pg_catalog.pg_settings ps " " FROM dd, pg_catalog.pg_settings ps "
" WHERE ps.name IN ('config_file', 'hba_file', 'ident_file') " " WHERE ps.name IN ('config_file', 'hba_file', 'ident_file') "
" AND ps.setting ~ ('^' || dd.setting) " " AND ps.setting ~ ('^' || dd.setting) "
") " ") "
" SELECT config_file, " " SELECT config_file, "
" pg_catalog.regexp_replace(config_file, '^.*\\/','') AS filename " " pg_catalog.regexp_replace(config_file, '^.*\\/','') AS filename "
" FROM files " " FROM files "
"ORDER BY config_file"); "ORDER BY config_file");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
@@ -3208,18 +3207,18 @@ get_configuration_file_locations(PGconn *conn, t_configfile_list *list)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" WITH dd AS ( " " WITH dd AS ( "
" SELECT setting AS data_directory" " SELECT setting AS data_directory"
" FROM pg_catalog.pg_settings " " FROM pg_catalog.pg_settings "
" WHERE name = 'data_directory' " " WHERE name = 'data_directory' "
" ) " " ) "
" SELECT DISTINCT(sourcefile), " " SELECT DISTINCT(sourcefile), "
" pg_catalog.regexp_replace(sourcefile, '^.*\\/', '') AS filename, " " pg_catalog.regexp_replace(sourcefile, '^.*\\/', '') AS filename, "
" sourcefile ~ ('^' || dd.data_directory) AS in_data_dir " " sourcefile ~ ('^' || dd.data_directory) AS in_data_dir "
" FROM dd, pg_catalog.pg_settings ps " " FROM dd, pg_catalog.pg_settings ps "
" WHERE sourcefile IS NOT NULL " " WHERE sourcefile IS NOT NULL "
" ORDER BY 1 "); " ORDER BY 1 ");
log_verbose(LOG_DEBUG, "get_configuration_file_locations():\n %s", log_verbose(LOG_DEBUG, "get_configuration_file_locations():\n %s",
query.data); query.data);
@@ -3258,19 +3257,18 @@ get_configuration_file_locations(PGconn *conn, t_configfile_list *list)
/* Fetch locations of pg_hba.conf and pg_ident.conf */ /* Fetch locations of pg_hba.conf and pg_ident.conf */
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" WITH dd AS ( " " WITH dd AS ( "
" SELECT setting AS data_directory" " SELECT setting AS data_directory"
" FROM pg_catalog.pg_settings " " FROM pg_catalog.pg_settings "
" WHERE name = 'data_directory' " " WHERE name = 'data_directory' "
" ) " " ) "
" SELECT ps.setting, " " SELECT ps.setting, "
" pg_catalog.regexp_replace(setting, '^.*\\/', '') AS filename, " " pg_catalog.regexp_replace(setting, '^.*\\/', '') AS filename, "
" ps.setting ~ ('^' || dd.data_directory) AS in_data_dir " " ps.setting ~ ('^' || dd.data_directory) AS in_data_dir "
" FROM dd, pg_catalog.pg_settings ps " " FROM dd, pg_catalog.pg_settings ps "
" WHERE ps.name IN ('hba_file', 'ident_file') " " WHERE ps.name IN ('hba_file', 'ident_file') "
" ORDER BY 1 "); " ORDER BY 1 ");
log_verbose(LOG_DEBUG, "get_configuration_file_locations():\n %s", log_verbose(LOG_DEBUG, "get_configuration_file_locations():\n %s",
query.data); query.data);
@@ -3444,15 +3442,15 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
int binary[4] = {1, 0, 0, 0}; int binary[4] = {1, 0, 0, 0};
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" INSERT INTO repmgr.events ( " " INSERT INTO repmgr.events ( "
" node_id, " " node_id, "
" event, " " event, "
" successful, " " successful, "
" details " " details "
" ) " " ) "
" VALUES ($1, $2, $3, $4) " " VALUES ($1, $2, $3, $4) "
" RETURNING event_timestamp "); " RETURNING event_timestamp ");
log_verbose(LOG_DEBUG, "_create_event():\n %s", query.data); log_verbose(LOG_DEBUG, "_create_event():\n %s", query.data);
@@ -3683,12 +3681,12 @@ get_event_records(PGconn *conn, int node_id, const char *node_name, const char *
initPQExpBuffer(&where_clause); initPQExpBuffer(&where_clause);
/* LEFT JOIN used here as a node record may have been removed */ /* LEFT JOIN used here as a node record may have been removed */
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT e.node_id, n.node_name, e.event, e.successful, " " SELECT e.node_id, n.node_name, e.event, e.successful, "
" pg_catalog.to_char(e.event_timestamp, 'YYYY-MM-DD HH24:MI:SS') AS timestamp, " " pg_catalog.to_char(e.event_timestamp, 'YYYY-MM-DD HH24:MI:SS') AS timestamp, "
" e.details " " e.details "
" FROM repmgr.events e " " FROM repmgr.events e "
"LEFT JOIN repmgr.nodes n ON e.node_id = n.node_id "); "LEFT JOIN repmgr.nodes n ON e.node_id = n.node_id ");
if (node_id != UNKNOWN_NODE_ID) if (node_id != UNKNOWN_NODE_ID)
{ {
@@ -3734,8 +3732,8 @@ get_event_records(PGconn *conn, int node_id, const char *node_name, const char *
appendPQExpBuffer(&query, "\n%s\n", appendPQExpBuffer(&query, "\n%s\n",
where_clause.data); where_clause.data);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" ORDER BY e.event_timestamp DESC"); " ORDER BY e.event_timestamp DESC");
if (all == false && limit > 0) if (all == false && limit > 0)
{ {
@@ -3937,10 +3935,10 @@ get_free_replication_slot_count(PGconn *conn)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT pg_catalog.current_setting('max_replication_slots')::INT - " " SELECT pg_catalog.current_setting('max_replication_slots')::INT - "
" pg_catalog.count(*) AS free_slots" " pg_catalog.count(*) AS free_slots"
" FROM pg_catalog.pg_replication_slots"); " FROM pg_catalog.pg_replication_slots");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
@@ -3976,11 +3974,11 @@ get_inactive_replication_slots(PGconn *conn, KeyValueList *list)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT slot_name, slot_type " " SELECT slot_name, slot_type "
" FROM pg_catalog.pg_replication_slots " " FROM pg_catalog.pg_replication_slots "
" WHERE active IS FALSE " " WHERE active IS FALSE "
" ORDER BY slot_name "); " ORDER BY slot_name ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
@@ -4360,8 +4358,8 @@ delete_monitoring_records(PGconn *primary_conn, int keep_history, int node_id)
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"TRUNCATE TABLE repmgr.monitoring_history"); "TRUNCATE TABLE repmgr.monitoring_history");
} }
res = PQexec(primary_conn, query.data); res = PQexec(primary_conn, query.data);
@@ -4636,10 +4634,10 @@ _is_bdr_db(PGconn *conn, PQExpBufferData *output, bool quiet)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT (pg_catalog.regexp_matches(extversion, '^\\d+'))[1] AS major_version " " SELECT (pg_catalog.regexp_matches(extversion, '^\\d+'))[1] AS major_version "
" FROM pg_catalog.pg_extension " " FROM pg_catalog.pg_extension "
" WHERE extname = 'bdr' "); " WHERE extname = 'bdr' ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
@@ -4664,7 +4662,7 @@ _is_bdr_db(PGconn *conn, PQExpBufferData *output, bool quiet)
const char *warning = _("BDR extension is not available for this database"); const char *warning = _("BDR extension is not available for this database");
if (output != NULL) if (output != NULL)
appendPQExpBuffer(output, "%s", warning); appendPQExpBufferStr(output, warning);
else if (quiet == false) else if (quiet == false)
log_warning("%s", warning); log_warning("%s", warning);
@@ -4675,8 +4673,8 @@ _is_bdr_db(PGconn *conn, PQExpBufferData *output, bool quiet)
{ {
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT bdr.bdr_is_active_in_db()"); "SELECT bdr.bdr_is_active_in_db()");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
@@ -4687,7 +4685,7 @@ _is_bdr_db(PGconn *conn, PQExpBufferData *output, bool quiet)
const char *warning = _("BDR extension available for this database, but the database is not configured for BDR"); const char *warning = _("BDR extension available for this database, but the database is not configured for BDR");
if (output != NULL) if (output != NULL)
appendPQExpBuffer(output, "%s", warning); appendPQExpBufferStr(output, warning);
else if (quiet == false) else if (quiet == false)
log_warning("%s", warning); log_warning("%s", warning);
} }
@@ -4782,10 +4780,10 @@ is_bdr_repmgr(PGconn *conn)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT pg_catalog.count(*)" "SELECT pg_catalog.count(*)"
" FROM repmgr.nodes n" " FROM repmgr.nodes n"
" WHERE n.type != 'bdr' "); " WHERE n.type != 'bdr' ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
@@ -4830,11 +4828,11 @@ get_default_bdr_replication_set(PGconn *conn)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT rs.set_name " " SELECT rs.set_name "
" FROM pglogical.replication_set rs " " FROM pglogical.replication_set rs "
" INNER JOIN bdr.node_group ng " " INNER JOIN bdr.node_group ng "
" ON ng.node_group_default_repset = rs.set_id "); " ON ng.node_group_default_repset = rs.set_id ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
@@ -4969,13 +4967,13 @@ bdr_node_name_matches(PGconn *conn, const char *node_name, PQExpBufferData *bdr_
if (bdr_version_num < 3) if (bdr_version_num < 3)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT bdr.bdr_get_local_node_name() AS node_name"); "SELECT bdr.bdr_get_local_node_name() AS node_name");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
"SELECT node_name FROM bdr.local_node_info()"); "SELECT node_name FROM bdr.local_node_info()");
} }
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
@@ -5098,13 +5096,13 @@ add_extension_tables_to_bdr_replication_set(PGconn *conn)
initPQExpBuffer(&query); initPQExpBuffer(&query);
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT c.relname " " SELECT c.relname "
" FROM pg_class c " " FROM pg_class c "
"INNER JOIN pg_namespace n " "INNER JOIN pg_namespace n "
" ON c.relnamespace = n.oid " " ON c.relnamespace = n.oid "
" WHERE n.nspname = 'repmgr' " " WHERE n.nspname = 'repmgr' "
" AND c.relkind = 'r' "); " AND c.relkind = 'r' ");
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
@@ -5140,17 +5138,17 @@ get_all_bdr_node_records(PGconn *conn, BdrNodeInfoList *node_list)
if (bdr_version_num < 3) if (bdr_version_num < 3)
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT " BDR2_NODES_COLUMNS " SELECT " BDR2_NODES_COLUMNS
" FROM bdr.bdr_nodes " " FROM bdr.bdr_nodes "
"ORDER BY node_seq_id "); "ORDER BY node_seq_id ");
} }
else else
{ {
appendPQExpBuffer(&query, appendPQExpBufferStr(&query,
" SELECT " BDR3_NODES_COLUMNS " SELECT " BDR3_NODES_COLUMNS
" FROM bdr.node_summary ns " " FROM bdr.node_summary ns "
" ORDER BY node_name"); " ORDER BY node_name");
} }
log_verbose(LOG_DEBUG, "get_all_bdr_node_records():\n%s", query.data); log_verbose(LOG_DEBUG, "get_all_bdr_node_records():\n%s", query.data);

View File

@@ -174,16 +174,16 @@ do_cluster_show(void)
switch (cell->node_info->recovery_type) switch (cell->node_info->recovery_type)
{ {
case RECTYPE_PRIMARY: case RECTYPE_PRIMARY:
appendPQExpBuffer(&details, "* running"); appendPQExpBufferStr(&details, "* running");
break; break;
case RECTYPE_STANDBY: case RECTYPE_STANDBY:
appendPQExpBuffer(&details, "! running as standby"); appendPQExpBufferStr(&details, "! running as standby");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is registered as primary but running as standby", "node \"%s\" (ID: %i) is registered as primary but running as standby",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
break; break;
case RECTYPE_UNKNOWN: case RECTYPE_UNKNOWN:
appendPQExpBuffer(&details, "! unknown"); appendPQExpBufferStr(&details, "! unknown");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) has unknown replication status", "node \"%s\" (ID: %i) has unknown replication status",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
@@ -194,14 +194,14 @@ do_cluster_show(void)
{ {
if (cell->node_info->recovery_type == RECTYPE_PRIMARY) if (cell->node_info->recovery_type == RECTYPE_PRIMARY)
{ {
appendPQExpBuffer(&details, "! running"); appendPQExpBufferStr(&details, "! running");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is running but the repmgr node record is inactive", "node \"%s\" (ID: %i) is running but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
} }
else else
{ {
appendPQExpBuffer(&details, "! running as standby"); appendPQExpBufferStr(&details, "! running as standby");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is registered as an inactive primary but running as standby", "node \"%s\" (ID: %i) is registered as an inactive primary but running as standby",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
@@ -214,7 +214,7 @@ do_cluster_show(void)
/* node is unreachable but marked active */ /* node is unreachable but marked active */
if (cell->node_info->active == true) if (cell->node_info->active == true)
{ {
appendPQExpBuffer(&details, "? unreachable"); appendPQExpBufferStr(&details, "? unreachable");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is registered as an active primary but is unreachable", "node \"%s\" (ID: %i) is registered as an active primary but is unreachable",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
@@ -222,7 +222,7 @@ do_cluster_show(void)
/* node is unreachable and marked as inactive */ /* node is unreachable and marked as inactive */
else else
{ {
appendPQExpBuffer(&details, "- failed"); appendPQExpBufferStr(&details, "- failed");
error_found = true; error_found = true;
} }
} }
@@ -238,16 +238,16 @@ do_cluster_show(void)
switch (cell->node_info->recovery_type) switch (cell->node_info->recovery_type)
{ {
case RECTYPE_STANDBY: case RECTYPE_STANDBY:
appendPQExpBuffer(&details, " running"); appendPQExpBufferStr(&details, " running");
break; break;
case RECTYPE_PRIMARY: case RECTYPE_PRIMARY:
appendPQExpBuffer(&details, "! running as primary"); appendPQExpBufferStr(&details, "! running as primary");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is registered as standby but running as primary", "node \"%s\" (ID: %i) is registered as standby but running as primary",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
break; break;
case RECTYPE_UNKNOWN: case RECTYPE_UNKNOWN:
appendPQExpBuffer(&details, "! unknown"); appendPQExpBufferStr(&details, "! unknown");
item_list_append_format( item_list_append_format(
&warnings, &warnings,
"node \"%s\" (ID: %i) has unknown replication status", "node \"%s\" (ID: %i) has unknown replication status",
@@ -259,14 +259,14 @@ do_cluster_show(void)
{ {
if (cell->node_info->recovery_type == RECTYPE_STANDBY) if (cell->node_info->recovery_type == RECTYPE_STANDBY)
{ {
appendPQExpBuffer(&details, "! running"); appendPQExpBufferStr(&details, "! running");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is running but the repmgr node record is inactive", "node \"%s\" (ID: %i) is running but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
} }
else else
{ {
appendPQExpBuffer(&details, "! running as primary"); appendPQExpBufferStr(&details, "! running as primary");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is running as primary but the repmgr node record is inactive", "node \"%s\" (ID: %i) is running as primary but the repmgr node record is inactive",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
@@ -279,14 +279,14 @@ do_cluster_show(void)
/* node is unreachable but marked active */ /* node is unreachable but marked active */
if (cell->node_info->active == true) if (cell->node_info->active == true)
{ {
appendPQExpBuffer(&details, "? unreachable"); appendPQExpBufferStr(&details, "? unreachable");
item_list_append_format(&warnings, item_list_append_format(&warnings,
"node \"%s\" (ID: %i) is registered as an active standby but is unreachable", "node \"%s\" (ID: %i) is registered as an active standby but is unreachable",
cell->node_info->node_name, cell->node_info->node_id); cell->node_info->node_name, cell->node_info->node_id);
} }
else else
{ {
appendPQExpBuffer(&details, "- failed"); appendPQExpBufferStr(&details, "- failed");
error_found = true; error_found = true;
} }
} }
@@ -300,11 +300,11 @@ do_cluster_show(void)
{ {
if (cell->node_info->active == true) if (cell->node_info->active == true)
{ {
appendPQExpBuffer(&details, "* running"); appendPQExpBufferStr(&details, "* running");
} }
else else
{ {
appendPQExpBuffer(&details, "! running"); appendPQExpBufferStr(&details, "! running");
error_found = true; error_found = true;
} }
} }
@@ -313,11 +313,11 @@ do_cluster_show(void)
{ {
if (cell->node_info->active == true) if (cell->node_info->active == true)
{ {
appendPQExpBuffer(&details, "? unreachable"); appendPQExpBufferStr(&details, "? unreachable");
} }
else else
{ {
appendPQExpBuffer(&details, "- failed"); appendPQExpBufferStr(&details, "- failed");
error_found = true; error_found = true;
} }
} }
@@ -326,7 +326,7 @@ do_cluster_show(void)
case UNKNOWN: case UNKNOWN:
{ {
/* this should never happen */ /* this should never happen */
appendPQExpBuffer(&details, "? unknown node type"); appendPQExpBufferStr(&details, "? unknown node type");
error_found = true; error_found = true;
} }
break; break;
@@ -1410,7 +1410,7 @@ do_cluster_cleanup(void)
if (delete_monitoring_records(primary_conn, runtime_options.keep_history, runtime_options.node_id) == false) if (delete_monitoring_records(primary_conn, runtime_options.keep_history, runtime_options.node_id) == false)
{ {
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
_("unable to delete monitoring records")); _("unable to delete monitoring records"));
log_error("%s", event_details.data); log_error("%s", event_details.data);
@@ -1436,12 +1436,12 @@ do_cluster_cleanup(void)
if (runtime_options.keep_history == 0) if (runtime_options.keep_history == 0)
{ {
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
_("all monitoring records deleted")); _("all monitoring records deleted"));
} }
else else
{ {
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
_("monitoring records deleted")); _("monitoring records deleted"));
} }

View File

@@ -170,8 +170,8 @@ do_primary_register(void)
&node_info); &node_info);
if (record_created == true) if (record_created == true)
{ {
appendPQExpBuffer(&event_description, appendPQExpBufferStr(&event_description,
"existing primary record updated"); "existing primary record updated");
} }
else else
{ {

View File

@@ -285,8 +285,8 @@ monitor_streaming_primary(void)
initPQExpBuffer(&event_details); initPQExpBuffer(&event_details);
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
_("unable to connect to local node")); _("unable to connect to local node"));
log_warning("%s", event_details.data); log_warning("%s", event_details.data);
@@ -951,8 +951,8 @@ monitor_streaming_standby(void)
degraded_monitoring_elapsed); degraded_monitoring_elapsed);
initPQExpBuffer(&event_details); initPQExpBuffer(&event_details);
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
"promotion command failed but promotion completed successfully"); _("promotion command failed but promotion completed successfully"));
create_event_notification(local_conn, create_event_notification(local_conn,
&config_file_options, &config_file_options,
local_node_info.node_id, local_node_info.node_id,
@@ -1069,8 +1069,8 @@ loop:
if (config_file_options.failover == FAILOVER_MANUAL) if (config_file_options.failover == FAILOVER_MANUAL)
{ {
appendPQExpBuffer(&monitoring_summary, appendPQExpBufferStr(&monitoring_summary,
_(" (automatic failover disabled)")); _(" (automatic failover disabled)"));
} }
log_info("%s", monitoring_summary.data); log_info("%s", monitoring_summary.data);
@@ -2509,8 +2509,8 @@ follow_new_primary(int new_primary_id)
if (upstream_recovery_type == RECTYPE_PRIMARY) if (upstream_recovery_type == RECTYPE_PRIMARY)
{ {
initPQExpBuffer(&event_details); initPQExpBuffer(&event_details);
appendPQExpBuffer(&event_details, appendPQExpBufferStr(&event_details,
_("original primary reappeared - no action taken")); _("original primary reappeared - no action taken"));
log_notice("%s", event_details.data); log_notice("%s", event_details.data);

View File

@@ -87,17 +87,17 @@ append_where_clause(PQExpBufferData *where_clause, const char *format,...)
if (where_clause->data[0] == '\0') if (where_clause->data[0] == '\0')
{ {
appendPQExpBuffer(where_clause, appendPQExpBufferStr(where_clause,
" WHERE "); " WHERE ");
} }
else else
{ {
appendPQExpBuffer(where_clause, appendPQExpBufferStr(where_clause,
" AND "); " AND ");
} }
appendPQExpBuffer(where_clause, appendPQExpBufferStr(where_clause,
"%s", stringbuf); stringbuf);
} }