const char *dbname);
static void get_publisher_databases(struct CreateSubscriberOptions *opt,
bool dbnamespecified);
-static void report_createsub_log(enum pg_log_level, enum pg_log_part,
- const char *pg_restrict fmt,...)
- pg_attribute_printf(3, 4);
-static void report_createsub_log_v(enum pg_log_level level, enum pg_log_part part,
- const char *pg_restrict fmt, va_list args)
- pg_attribute_printf(3, 0);
-pg_noreturn static void report_createsub_fatal(const char *pg_restrict fmt,...)
- pg_attribute_printf(1, 2);
-static void internal_log_file_write(enum pg_log_level level,
- enum pg_log_part part,
- const char *pg_restrict fmt, va_list args)
- pg_attribute_printf(3, 0);
#define WAIT_INTERVAL 1 /* 1 second */
static char *pg_ctl_path = NULL;
static char *pg_resetwal_path = NULL;
-static FILE *internal_log_file_fp = NULL; /* File ptr to log all messages to */
static char logdir[MAXPGPATH]; /* Subdirectory of the user specified logdir
* where the log files are written (if
* specified) */
static bool standby_running = false;
static bool recovery_params_set = false;
-/*
- * Report a message with a given log level.
- *
- * Writes to stderr, and also to the log file, if --logdir option was
- * specified.
- */
-static void
-report_createsub_log_v(enum pg_log_level level, enum pg_log_part part,
- const char *pg_restrict fmt, va_list args)
-{
- int save_errno = errno;
-
- if (internal_log_file_fp != NULL)
- {
- /* Output to both stderr and the log file */
- va_list arg_cpy;
-
- va_copy(arg_cpy, args);
- internal_log_file_write(level, part, fmt, arg_cpy);
- va_end(arg_cpy);
- /* Restore errno in case internal_log_file_write changed it */
- errno = save_errno;
- }
- pg_log_generic_v(level, part, fmt, args);
-}
-
-static void
-report_createsub_log(enum pg_log_level level, enum pg_log_part part,
- const char *pg_restrict fmt,...)
-{
- va_list args;
-
- va_start(args, fmt);
-
- report_createsub_log_v(level, part, fmt, args);
-
- va_end(args);
-}
-
-/*
- * Report a fatal error and exit
- */
-static void
-report_createsub_fatal(const char *pg_restrict fmt,...)
-{
- va_list args;
-
- va_start(args, fmt);
-
- report_createsub_log_v(PG_LOG_ERROR, PG_LOG_PRIMARY, fmt, args);
-
- va_end(args);
-
- exit(1);
-}
/*
* Clean up objects created by pg_createsubscriber.
if (durable_rename(conf_filename, conf_filename_disabled) != 0)
{
/* durable_rename() has already logged something. */
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "A manual removal of the recovery parameters may be required.");
+ pg_log_warning_hint("A manual removal of the recovery parameters may be required.");
}
}
*/
if (recovery_ended)
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "failed after the end of recovery");
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "The target server cannot be used as a physical replica anymore. "
- "You must recreate the physical replica before continuing.");
+ pg_log_warning("failed after the end of recovery");
+ pg_log_warning_hint("The target server cannot be used as a physical replica anymore. "
+ "You must recreate the physical replica before continuing.");
}
for (int i = 0; i < num_dbs; i++)
*/
if (dbinfo->made_publication)
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "publication \"%s\" created in database \"%s\" on primary was left behind",
- dbinfo->pubname,
- dbinfo->dbname);
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Drop this publication before trying again.");
+ pg_log_warning("publication \"%s\" created in database \"%s\" on primary was left behind",
+ dbinfo->pubname,
+ dbinfo->dbname);
+ pg_log_warning_hint("Drop this publication before trying again.");
}
if (dbinfo->made_replslot)
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "replication slot \"%s\" created in database \"%s\" on primary was left behind",
- dbinfo->replslotname,
- dbinfo->dbname);
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Drop this replication slot soon to avoid retention of WAL files.");
+ pg_log_warning("replication slot \"%s\" created in database \"%s\" on primary was left behind",
+ dbinfo->replslotname,
+ dbinfo->dbname);
+ pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files.");
}
}
}
conn_opts = PQconninfoParse(conninfo, &errmsg);
if (conn_opts == NULL)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not parse connection string: %s", errmsg);
+ pg_log_error("could not parse connection string: %s", errmsg);
PQfreemem(errmsg);
return NULL;
}
strlcpy(full_path, progname, sizeof(full_path));
if (ret == -1)
- report_createsub_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
- progname, "pg_createsubscriber", full_path);
+ pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
+ progname, "pg_createsubscriber", full_path);
else
- report_createsub_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
- progname, full_path, "pg_createsubscriber");
+ pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
+ progname, full_path, "pg_createsubscriber");
}
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "%s path is: %s", progname, exec_path);
+ pg_log_debug("%s path is: %s", progname, exec_path);
return exec_path;
}
uint32 major_version;
char *version_str;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "checking if directory \"%s\" is a cluster data directory",
- datadir);
+ pg_log_info("checking if directory \"%s\" is a cluster data directory",
+ datadir);
if (stat(datadir, &statbuf) != 0)
{
if (errno == ENOENT)
- report_createsub_fatal("data directory \"%s\" does not exist", datadir);
+ pg_fatal("data directory \"%s\" does not exist", datadir);
else
- report_createsub_fatal("could not access directory \"%s\": %m", datadir);
+ pg_fatal("could not access directory \"%s\": %m", datadir);
}
/*
major_version = GET_PG_MAJORVERSION_NUM(get_pg_version(datadir, &version_str));
if (major_version != PG_MAJORVERSION_NUM)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "data directory is of wrong version");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
- "PG_VERSION", version_str, PG_MAJORVERSION);
+ pg_log_error("data directory is of wrong version");
+ pg_log_error_detail("File \"%s\" contains \"%s\", which is not compatible with this program's version \"%s\".",
+ "PG_VERSION", version_str, PG_MAJORVERSION);
exit(1);
}
}
dbinfo[i].subname = NULL;
/* Other fields will be filled later */
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher(%d): publication: %s ; replication slot: %s ; connection string: %s", i,
- dbinfo[i].pubname ? dbinfo[i].pubname : "(auto)",
- dbinfo[i].replslotname ? dbinfo[i].replslotname : "(auto)",
- dbinfo[i].pubconninfo);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "subscriber(%d): subscription: %s ; connection string: %s, two_phase: %s", i,
- dbinfo[i].subname ? dbinfo[i].subname : "(auto)",
- dbinfo[i].subconninfo,
- dbinfos.two_phase ? "true" : "false");
+ pg_log_debug("publisher(%d): publication: %s ; replication slot: %s ; connection string: %s", i,
+ dbinfo[i].pubname ? dbinfo[i].pubname : "(auto)",
+ dbinfo[i].replslotname ? dbinfo[i].replslotname : "(auto)",
+ dbinfo[i].pubconninfo);
+ pg_log_debug("subscriber(%d): subscription: %s ; connection string: %s, two_phase: %s", i,
+ dbinfo[i].subname ? dbinfo[i].subname : "(auto)",
+ dbinfo[i].subconninfo,
+ dbinfos.two_phase ? "true" : "false");
if (num_pubs > 0)
pubcell = pubcell->next;
conn = PQconnectdb(conninfo);
if (PQstatus(conn) != CONNECTION_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "connection to database failed: %s",
- PQerrorMessage(conn));
+ pg_log_error("connection to database failed: %s",
+ PQerrorMessage(conn));
PQfinish(conn);
if (exit_on_error)
res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not clear \"search_path\": %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not clear \"search_path\": %s",
+ PQresultErrorMessage(res));
PQclear(res);
PQfinish(conn);
PGresult *res;
uint64 sysid;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "getting system identifier from publisher");
+ pg_log_info("getting system identifier from publisher");
conn = connect_database(conninfo, true);
res = PQexec(conn, "SELECT system_identifier FROM pg_catalog.pg_control_system()");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not get system identifier: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not get system identifier: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
if (PQntuples(res) != 1)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not get system identifier: got %d rows, expected %d row",
- PQntuples(res), 1);
+ pg_log_error("could not get system identifier: got %d rows, expected %d row",
+ PQntuples(res), 1);
disconnect_database(conn, true);
}
sysid = strtou64(PQgetvalue(res, 0, 0), NULL, 10);
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "system identifier is %" PRIu64 " on publisher", sysid);
+ pg_log_info("system identifier is %" PRIu64 " on publisher", sysid);
PQclear(res);
disconnect_database(conn, false);
bool crc_ok;
uint64 sysid;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "getting system identifier from subscriber");
+ pg_log_info("getting system identifier from subscriber");
cf = get_controlfile(datadir, &crc_ok);
if (!crc_ok)
- report_createsub_fatal("control file appears to be corrupt");
+ pg_fatal("control file appears to be corrupt");
sysid = cf->system_identifier;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "system identifier is %" PRIu64 " on subscriber", sysid);
+ pg_log_info("system identifier is %" PRIu64 " on subscriber", sysid);
pg_free(cf);
char *out_file;
char *cmd_str;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "modifying system identifier of subscriber");
+ pg_log_info("modifying system identifier of subscriber");
cf = get_controlfile(subscriber_dir, &crc_ok);
if (!crc_ok)
- report_createsub_fatal("control file appears to be corrupt");
+ pg_fatal("control file appears to be corrupt");
/*
* Select a new system identifier.
cf->system_identifier |= getpid() & 0xFFF;
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would set system identifier to %" PRIu64 " on subscriber",
- cf->system_identifier);
+ pg_log_info("dry-run: would set system identifier to %" PRIu64 " on subscriber",
+ cf->system_identifier);
else
{
update_controlfile(subscriber_dir, cf, true);
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "system identifier is %" PRIu64 " on subscriber",
- cf->system_identifier);
+ pg_log_info("system identifier is %" PRIu64 " on subscriber",
+ cf->system_identifier);
}
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would run pg_resetwal on the subscriber");
+ pg_log_info("dry-run: would run pg_resetwal on the subscriber");
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "running pg_resetwal on the subscriber");
+ pg_log_info("running pg_resetwal on the subscriber");
/*
* Redirecting the output to the logfile if specified. Since the output
if (opt->log_dir)
pg_free(out_file);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "pg_resetwal command is: %s", cmd_str);
+ pg_log_debug("pg_resetwal command is: %s", cmd_str);
if (!dry_run)
{
int rc = system(cmd_str);
if (rc == 0)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "successfully reset WAL on the subscriber");
+ pg_log_info("successfully reset WAL on the subscriber");
else
- report_createsub_fatal("could not reset WAL on subscriber: %s", wait_result_to_str(rc));
+ pg_fatal("could not reset WAL on subscriber: %s", wait_result_to_str(rc));
}
pg_free(cf);
"WHERE datname = pg_catalog.current_database()");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain database OID: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain database OID: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
if (PQntuples(res) != 1)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain database OID: got %d rows, expected %d row",
- PQntuples(res), 1);
+ pg_log_error("could not obtain database OID: got %d rows, expected %d row",
+ PQntuples(res), 1);
disconnect_database(conn, true);
}
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not find publication \"%s\" in database \"%s\": %s",
- pubname, dbname, PQerrorMessage(conn));
+ pg_log_error("could not find publication \"%s\" in database \"%s\": %s",
+ pubname, dbname, PQerrorMessage(conn));
disconnect_database(conn, true);
}
if (find_publication(conn, dbinfo[i].pubname, dbinfo[i].dbname))
{
/* Reuse existing publication on publisher. */
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "use existing publication \"%s\" in database \"%s\"",
- dbinfo[i].pubname, dbinfo[i].dbname);
+ pg_log_info("use existing publication \"%s\" in database \"%s\"",
+ dbinfo[i].pubname, dbinfo[i].dbname);
/* Don't remove pre-existing publication if an error occurs. */
dbinfo[i].made_publication = false;
}
res = PQexec(conn, "SELECT pg_log_standby_snapshot()");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not write an additional WAL record: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not write an additional WAL record: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
PQclear(res);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain recovery progress: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain recovery progress: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
return ret == 0;
}
-static void
-internal_log_file_write(enum pg_log_level level, enum pg_log_part part,
- const char *pg_restrict fmt, va_list args)
-{
- Assert(internal_log_file_fp);
-
- /* Do nothing if log level is too low. */
- if (level < __pg_log_level)
- return;
-
- /* Add prefix based on the log part and log level */
- switch (part)
- {
- case PG_LOG_PRIMARY:
- switch (level)
- {
- case PG_LOG_ERROR:
- fprintf(internal_log_file_fp, _("error: "));
- break;
- case PG_LOG_WARNING:
- fprintf(internal_log_file_fp, _("warning: "));
- break;
- default:
- break;
- }
- break;
- case PG_LOG_DETAIL:
- fprintf(internal_log_file_fp, _("detail: "));
- break;
- case PG_LOG_HINT:
- fprintf(internal_log_file_fp, _("hint: "));
- break;
- }
-
- vfprintf(internal_log_file_fp, _(fmt), args);
-
- fprintf(internal_log_file_fp, "\n");
- fflush(internal_log_file_fp);
-}
-
/*
* Open a new logfile with proper permissions.
*/
fh = fopen(filename, mode);
if (!fh)
- report_createsub_fatal("could not open log file \"%s\": %m",
- filename);
+ pg_fatal("could not open log file \"%s\": %m", filename);
return fh;
}
len = snprintf(logdir, MAXPGPATH, "%s/%s", log_basedir, timestamp);
if (len >= MAXPGPATH)
- report_createsub_fatal("directory path for log files is too long");
+ pg_fatal("directory path for log files is too long");
/* Create base directory (ignore if exists) */
if (mkdir(log_basedir, pg_dir_create_mode) < 0 && errno != EEXIST)
- report_createsub_fatal("could not create directory \"%s\": %m", log_basedir);
+ pg_fatal("could not create directory \"%s\": %m", log_basedir);
/* Create a timestamp-named subdirectory under the base directory */
if (mkdir(logdir, pg_dir_create_mode) < 0)
- report_createsub_fatal("could not create directory \"%s\": %m", logdir);
+ pg_fatal("could not create directory \"%s\": %m", logdir);
}
/*
int max_prepared_transactions;
char *max_slot_wal_keep_size;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "checking settings on publisher");
+ pg_log_info("checking settings on publisher");
conn = connect_database(dbinfo[0].pubconninfo, true);
*/
if (server_is_in_recovery(conn))
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "primary server cannot be in recovery");
+ pg_log_error("primary server cannot be in recovery");
disconnect_database(conn, true);
}
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain publisher settings: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain publisher settings: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
PQclear(res);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: wal_level: %s", wal_level);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: max_replication_slots: %d", max_repslots);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: current replication slots: %d", cur_repslots);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: max_wal_senders: %d", max_walsenders);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: current wal senders: %d", cur_walsenders);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: max_prepared_transactions: %d",
- max_prepared_transactions);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "publisher: max_slot_wal_keep_size: %s",
- max_slot_wal_keep_size);
+ pg_log_debug("publisher: wal_level: %s", wal_level);
+ pg_log_debug("publisher: max_replication_slots: %d", max_repslots);
+ pg_log_debug("publisher: current replication slots: %d", cur_repslots);
+ pg_log_debug("publisher: max_wal_senders: %d", max_walsenders);
+ pg_log_debug("publisher: current wal senders: %d", cur_walsenders);
+ pg_log_debug("publisher: max_prepared_transactions: %d",
+ max_prepared_transactions);
+ pg_log_debug("publisher: max_slot_wal_keep_size: %s",
+ max_slot_wal_keep_size);
disconnect_database(conn, false);
if (strcmp(wal_level, "minimal") == 0)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "publisher requires \"wal_level\" >= \"replica\"");
+ pg_log_error("publisher requires \"wal_level\" >= \"replica\"");
failed = true;
}
if (max_repslots - cur_repslots < num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "publisher requires %d replication slots, but only %d remain",
- num_dbs, max_repslots - cur_repslots);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Increase the configuration parameter \"%s\" to at least %d.",
- "max_replication_slots", cur_repslots + num_dbs);
+ pg_log_error("publisher requires %d replication slots, but only %d remain",
+ num_dbs, max_repslots - cur_repslots);
+ pg_log_error_hint("Increase the configuration parameter \"%s\" to at least %d.",
+ "max_replication_slots", cur_repslots + num_dbs);
failed = true;
}
if (max_walsenders - cur_walsenders < num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "publisher requires %d WAL sender processes, but only %d remain",
- num_dbs, max_walsenders - cur_walsenders);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Increase the configuration parameter \"%s\" to at least %d.",
- "max_wal_senders", cur_walsenders + num_dbs);
+ pg_log_error("publisher requires %d WAL sender processes, but only %d remain",
+ num_dbs, max_walsenders - cur_walsenders);
+ pg_log_error_hint("Increase the configuration parameter \"%s\" to at least %d.",
+ "max_wal_senders", cur_walsenders + num_dbs);
failed = true;
}
if (max_prepared_transactions != 0 && !dbinfos.two_phase)
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "two_phase option will not be enabled for replication slots");
- report_createsub_log(PG_LOG_WARNING, PG_LOG_DETAIL,
- "Subscriptions will be created with the two_phase option disabled. "
- "Prepared transactions will be replicated at COMMIT PREPARED.");
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "You can use the command-line option --enable-two-phase to enable two_phase.");
+ pg_log_warning("two_phase option will not be enabled for replication slots");
+ pg_log_warning_detail("Subscriptions will be created with the two_phase option disabled. "
+ "Prepared transactions will be replicated at COMMIT PREPARED.");
+ pg_log_warning_hint("You can use the command-line option --enable-two-phase to enable two_phase.");
}
/*
*/
if (dry_run && (strcmp(max_slot_wal_keep_size, "-1") != 0))
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "required WAL could be removed from the publisher");
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Set the configuration parameter \"%s\" to -1 to ensure that required WAL files are not prematurely removed.",
- "max_slot_wal_keep_size");
+ pg_log_warning("required WAL could be removed from the publisher");
+ pg_log_warning_hint("Set the configuration parameter \"%s\" to -1 to ensure that required WAL files are not prematurely removed.",
+ "max_slot_wal_keep_size");
}
pg_free(wal_level);
int max_replorigins;
int max_wprocs;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "checking settings on subscriber");
+ pg_log_info("checking settings on subscriber");
conn = connect_database(dbinfo[0].subconninfo, true);
/* The target server must be a standby */
if (!server_is_in_recovery(conn))
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "target server must be a standby");
+ pg_log_error("target server must be a standby");
disconnect_database(conn, true);
}
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain subscriber settings: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain subscriber settings: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
if (strcmp(PQgetvalue(res, 3, 0), "") != 0)
primary_slot_name = pg_strdup(PQgetvalue(res, 3, 0));
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "subscriber: max_logical_replication_workers: %d",
- max_lrworkers);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "subscriber: max_active_replication_origins: %d", max_replorigins);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "subscriber: max_worker_processes: %d", max_wprocs);
+ pg_log_debug("subscriber: max_logical_replication_workers: %d",
+ max_lrworkers);
+ pg_log_debug("subscriber: max_active_replication_origins: %d", max_replorigins);
+ pg_log_debug("subscriber: max_worker_processes: %d", max_wprocs);
if (primary_slot_name)
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "subscriber: primary_slot_name: %s", primary_slot_name);
+ pg_log_debug("subscriber: primary_slot_name: %s", primary_slot_name);
PQclear(res);
if (max_replorigins < num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "subscriber requires %d active replication origins, but only %d remain",
- num_dbs, max_replorigins);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Increase the configuration parameter \"%s\" to at least %d.",
- "max_active_replication_origins", num_dbs);
+ pg_log_error("subscriber requires %d active replication origins, but only %d remain",
+ num_dbs, max_replorigins);
+ pg_log_error_hint("Increase the configuration parameter \"%s\" to at least %d.",
+ "max_active_replication_origins", num_dbs);
failed = true;
}
if (max_lrworkers < num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "subscriber requires %d logical replication workers, but only %d remain",
- num_dbs, max_lrworkers);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Increase the configuration parameter \"%s\" to at least %d.",
- "max_logical_replication_workers", num_dbs);
+ pg_log_error("subscriber requires %d logical replication workers, but only %d remain",
+ num_dbs, max_lrworkers);
+ pg_log_error_hint("Increase the configuration parameter \"%s\" to at least %d.",
+ "max_logical_replication_workers", num_dbs);
failed = true;
}
if (max_wprocs < num_dbs + 1)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "subscriber requires %d worker processes, but only %d remain",
- num_dbs + 1, max_wprocs);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Increase the configuration parameter \"%s\" to at least %d.",
- "max_worker_processes", num_dbs + 1);
+ pg_log_error("subscriber requires %d worker processes, but only %d remain",
+ num_dbs + 1, max_wprocs);
+ pg_log_error_hint("Increase the configuration parameter \"%s\" to at least %d.",
+ "max_worker_processes", num_dbs + 1);
failed = true;
}
appendPQExpBuffer(query, " DROP SUBSCRIPTION %s;", subname);
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would drop subscription \"%s\" in database \"%s\"",
- subname, dbname);
+ pg_log_info("dry-run: would drop subscription \"%s\" in database \"%s\"",
+ subname, dbname);
else
{
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dropping subscription \"%s\" in database \"%s\"",
- subname, dbname);
+ pg_log_info("dropping subscription \"%s\" in database \"%s\"",
+ subname, dbname);
res = PQexec(conn, query->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not drop subscription \"%s\": %s",
- subname, PQresultErrorMessage(res));
+ pg_log_error("could not drop subscription \"%s\": %s",
+ subname, PQresultErrorMessage(res));
disconnect_database(conn, true);
}
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain pre-existing subscriptions: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain pre-existing subscriptions: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
lsn);
}
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "recovery parameters:\n%s", recoveryconfcontents->data);
+ pg_log_debug("recovery parameters:\n%s", recoveryconfcontents->data);
if (!dry_run)
{
INCLUDED_CONF_FILE);
fd = fopen(conf_filename, "w");
if (fd == NULL)
- report_createsub_fatal("could not open file \"%s\": %m", conf_filename);
+ pg_fatal("could not open file \"%s\": %m", conf_filename);
if (fwrite(recoveryconfcontents->data, recoveryconfcontents->len, 1, fd) != 1)
- report_createsub_fatal("could not write to file \"%s\": %m", conf_filename);
+ pg_fatal("could not write to file \"%s\": %m", conf_filename);
fclose(fd);
recovery_params_set = true;
}
else
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "could not drop replication slot \"%s\" on primary",
- slotname);
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Drop this replication slot soon to avoid retention of WAL files.");
+ pg_log_warning("could not drop replication slot \"%s\" on primary",
+ slotname);
+ pg_log_warning_hint("Drop this replication slot soon to avoid retention of WAL files.");
}
}
}
else
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "could not obtain failover replication slot information: %s",
- PQresultErrorMessage(res));
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Drop the failover replication slots on subscriber soon to avoid retention of WAL files.");
+ pg_log_warning("could not obtain failover replication slot information: %s",
+ PQresultErrorMessage(res));
+ pg_log_warning_hint("Drop the failover replication slots on subscriber soon to avoid retention of WAL files.");
}
PQclear(res);
}
else
{
- report_createsub_log(PG_LOG_WARNING, PG_LOG_PRIMARY,
- "could not drop failover replication slot");
- report_createsub_log(PG_LOG_WARNING, PG_LOG_HINT,
- "Drop the failover replication slots on subscriber soon to avoid retention of WAL files.");
+ pg_log_warning("could not drop failover replication slot");
+ pg_log_warning_hint("Drop the failover replication slots on subscriber soon to avoid retention of WAL files.");
}
}
Assert(conn != NULL);
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would create the replication slot \"%s\" in database \"%s\" on publisher",
- slot_name, dbinfo->dbname);
+ pg_log_info("dry-run: would create the replication slot \"%s\" in database \"%s\" on publisher",
+ slot_name, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "creating the replication slot \"%s\" in database \"%s\" on publisher",
- slot_name, dbinfo->dbname);
+ pg_log_info("creating the replication slot \"%s\" in database \"%s\" on publisher",
+ slot_name, dbinfo->dbname);
slot_name_esc = PQescapeLiteral(conn, slot_name, strlen(slot_name));
PQfreemem(slot_name_esc);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not create replication slot \"%s\" in database \"%s\": %s",
- slot_name, dbinfo->dbname,
- PQresultErrorMessage(res));
+ pg_log_error("could not create replication slot \"%s\" in database \"%s\": %s",
+ slot_name, dbinfo->dbname,
+ PQresultErrorMessage(res));
PQclear(res);
destroyPQExpBuffer(str);
return NULL;
Assert(conn != NULL);
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would drop the replication slot \"%s\" in database \"%s\"",
- slot_name, dbinfo->dbname);
+ pg_log_info("dry-run: would drop the replication slot \"%s\" in database \"%s\"",
+ slot_name, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dropping the replication slot \"%s\" in database \"%s\"",
- slot_name, dbinfo->dbname);
+ pg_log_info("dropping the replication slot \"%s\" in database \"%s\"",
+ slot_name, dbinfo->dbname);
slot_name_esc = PQescapeLiteral(conn, slot_name, strlen(slot_name));
PQfreemem(slot_name_esc);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not drop replication slot \"%s\" in database \"%s\": %s",
- slot_name, dbinfo->dbname, PQresultErrorMessage(res));
+ pg_log_error("could not drop replication slot \"%s\" in database \"%s\": %s",
+ slot_name, dbinfo->dbname, PQresultErrorMessage(res));
dbinfo->made_replslot = false; /* don't try again. */
}
{
if (WIFEXITED(rc))
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "pg_ctl failed with exit code %d",
- WEXITSTATUS(rc));
+ pg_log_error("pg_ctl failed with exit code %d", WEXITSTATUS(rc));
}
else if (WIFSIGNALED(rc))
{
#if defined(WIN32)
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "pg_ctl was terminated by exception 0x%X",
- WTERMSIG(rc));
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "See C include file \"ntstatus.h\" for a description of the hexadecimal value.");
+ pg_log_error("pg_ctl was terminated by exception 0x%X",
+ WTERMSIG(rc));
+ pg_log_error_detail("See C include file \"ntstatus.h\" for a description of the hexadecimal value.");
#else
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "pg_ctl was terminated by signal %d: %s",
- WTERMSIG(rc), pg_strsignal(WTERMSIG(rc)));
+ pg_log_error("pg_ctl was terminated by signal %d: %s",
+ WTERMSIG(rc), pg_strsignal(WTERMSIG(rc)));
#endif
}
else
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "pg_ctl exited with unrecognized status %d", rc);
+ pg_log_error("pg_ctl exited with unrecognized status %d", rc);
}
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "The failed command was: %s", pg_ctl_cmd);
+ pg_log_error_detail("The failed command was: %s", pg_ctl_cmd);
exit(1);
}
}
if (opt->log_dir)
appendPQExpBuffer(pg_ctl_cmd, " -l \"%s/%s\"", logdir, SERVER_LOG_FILE_NAME);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "pg_ctl command is: %s", pg_ctl_cmd->data);
+ pg_log_debug("pg_ctl command is: %s", pg_ctl_cmd->data);
rc = system(pg_ctl_cmd->data);
pg_ctl_status(pg_ctl_cmd->data, rc);
standby_running = true;
destroyPQExpBuffer(pg_ctl_cmd);
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "server was started");
+ pg_log_info("server was started");
}
static void
pg_ctl_cmd = psprintf("\"%s\" stop -D \"%s\" -s", pg_ctl_path,
datadir);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "pg_ctl command is: %s", pg_ctl_cmd);
+ pg_log_debug("pg_ctl command is: %s", pg_ctl_cmd);
rc = system(pg_ctl_cmd);
pg_ctl_status(pg_ctl_cmd, rc);
standby_running = false;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "server was stopped");
+ pg_log_info("server was stopped");
}
/*
bool ready = false;
int timer = 0;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "waiting for the target server to reach the consistent state");
+ pg_log_info("waiting for the target server to reach the consistent state");
conn = connect_database(conninfo, true);
if (opt->recovery_timeout > 0 && timer >= opt->recovery_timeout)
{
stop_standby_server(subscriber_dir);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "recovery timed out");
+ pg_log_error("recovery timed out");
disconnect_database(conn, true);
}
disconnect_database(conn, false);
if (!ready)
- report_createsub_fatal("server did not end recovery");
+ pg_fatal("server did not end recovery");
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "target server reached the consistent state");
- report_createsub_log(PG_LOG_INFO, PG_LOG_HINT,
- "If pg_createsubscriber fails after this point, you must recreate the physical replica before continuing.");
+ pg_log_info("target server reached the consistent state");
+ pg_log_info_hint("If pg_createsubscriber fails after this point, you must recreate the physical replica before continuing.");
}
/*
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain publication information: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain publication information: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
* pg_createsubscriber_ prefix followed by the exact database oid and
* a random number.
*/
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "publication \"%s\" already exists", dbinfo->pubname);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Consider renaming this publication before continuing.");
+ pg_log_error("publication \"%s\" already exists", dbinfo->pubname);
+ pg_log_error_hint("Consider renaming this publication before continuing.");
disconnect_database(conn, true);
}
resetPQExpBuffer(str);
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would create publication \"%s\" in database \"%s\"",
- dbinfo->pubname, dbinfo->dbname);
+ pg_log_info("dry-run: would create publication \"%s\" in database \"%s\"",
+ dbinfo->pubname, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "creating publication \"%s\" in database \"%s\"",
- dbinfo->pubname, dbinfo->dbname);
+ pg_log_info("creating publication \"%s\" in database \"%s\"",
+ dbinfo->pubname, dbinfo->dbname);
appendPQExpBuffer(str, "CREATE PUBLICATION %s FOR ALL TABLES",
ipubname_esc);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not create publication \"%s\" in database \"%s\": %s",
- dbinfo->pubname, dbinfo->dbname, PQresultErrorMessage(res));
+ pg_log_error("could not create publication \"%s\" in database \"%s\": %s",
+ dbinfo->pubname, dbinfo->dbname, PQresultErrorMessage(res));
disconnect_database(conn, true);
}
PQclear(res);
pubname_esc = PQescapeIdentifier(conn, pubname, strlen(pubname));
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would drop publication \"%s\" in database \"%s\"",
- pubname, dbname);
+ pg_log_info("dry-run: would drop publication \"%s\" in database \"%s\"",
+ pubname, dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dropping publication \"%s\" in database \"%s\"",
- pubname, dbname);
+ pg_log_info("dropping publication \"%s\" in database \"%s\"",
+ pubname, dbname);
appendPQExpBuffer(str, "DROP PUBLICATION %s", pubname_esc);
PQfreemem(pubname_esc);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not drop publication \"%s\" in database \"%s\": %s",
- pubname, dbname, PQresultErrorMessage(res));
+ pg_log_error("could not drop publication \"%s\" in database \"%s\": %s",
+ pubname, dbname, PQresultErrorMessage(res));
*made_publication = false; /* don't try again. */
/*
if (drop_all_pubs)
{
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dropping all existing publications in database \"%s\"",
- dbinfo->dbname);
+ pg_log_info("dropping all existing publications in database \"%s\"",
+ dbinfo->dbname);
/* Fetch all publication names */
res = PQexec(conn, "SELECT pubname FROM pg_catalog.pg_publication;");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain publication information: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain publication information: %s",
+ PQresultErrorMessage(res));
PQclear(res);
disconnect_database(conn, true);
}
else
{
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would preserve existing publication \"%s\" in database \"%s\"",
- dbinfo->pubname, dbinfo->dbname);
+ pg_log_info("dry-run: would preserve existing publication \"%s\" in database \"%s\"",
+ dbinfo->pubname, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "preserve existing publication \"%s\" in database \"%s\"",
- dbinfo->pubname, dbinfo->dbname);
+ pg_log_info("preserve existing publication \"%s\" in database \"%s\"",
+ dbinfo->pubname, dbinfo->dbname);
}
}
}
replslotname_esc = PQescapeLiteral(conn, dbinfo->replslotname, strlen(dbinfo->replslotname));
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would create subscription \"%s\" in database \"%s\"",
- dbinfo->subname, dbinfo->dbname);
+ pg_log_info("dry-run: would create subscription \"%s\" in database \"%s\"",
+ dbinfo->subname, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "creating subscription \"%s\" in database \"%s\"",
- dbinfo->subname, dbinfo->dbname);
+ pg_log_info("creating subscription \"%s\" in database \"%s\"",
+ dbinfo->subname, dbinfo->dbname);
appendPQExpBuffer(str,
"CREATE SUBSCRIPTION %s CONNECTION %s PUBLICATION %s "
PQfreemem(pubconninfo_esc);
PQfreemem(replslotname_esc);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not create subscription \"%s\" in database \"%s\": %s",
- dbinfo->subname, dbinfo->dbname, PQresultErrorMessage(res));
+ pg_log_error("could not create subscription \"%s\" in database \"%s\": %s",
+ dbinfo->subname, dbinfo->dbname, PQresultErrorMessage(res));
disconnect_database(conn, true);
}
PQclear(res);
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain subscription OID: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain subscription OID: %s",
+ PQresultErrorMessage(res));
disconnect_database(conn, true);
}
if (PQntuples(res) != 1 && !dry_run)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain subscription OID: got %d rows, expected %d row",
- PQntuples(res), 1);
+ pg_log_error("could not obtain subscription OID: got %d rows, expected %d row",
+ PQntuples(res), 1);
disconnect_database(conn, true);
}
originname = psprintf("pg_%u", suboid);
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would set the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
- originname, lsnstr, dbinfo->dbname);
+ pg_log_info("dry-run: would set the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
+ originname, lsnstr, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "setting the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
- originname, lsnstr, dbinfo->dbname);
+ pg_log_info("setting the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
+ originname, lsnstr, dbinfo->dbname);
resetPQExpBuffer(str);
appendPQExpBuffer(str,
"SELECT pg_catalog.pg_replication_origin_advance('%s', '%s')",
originname, lsnstr);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not set replication progress for subscription \"%s\": %s",
- dbinfo->subname, PQresultErrorMessage(res));
+ pg_log_error("could not set replication progress for subscription \"%s\": %s",
+ dbinfo->subname, PQresultErrorMessage(res));
disconnect_database(conn, true);
}
PQclear(res);
subname = PQescapeIdentifier(conn, dbinfo->subname, strlen(dbinfo->subname));
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "dry-run: would enable subscription \"%s\" in database \"%s\"",
- dbinfo->subname, dbinfo->dbname);
+ pg_log_info("dry-run: would enable subscription \"%s\" in database \"%s\"",
+ dbinfo->subname, dbinfo->dbname);
else
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "enabling subscription \"%s\" in database \"%s\"",
- dbinfo->subname, dbinfo->dbname);
+ pg_log_info("enabling subscription \"%s\" in database \"%s\"",
+ dbinfo->subname, dbinfo->dbname);
appendPQExpBuffer(str, "ALTER SUBSCRIPTION %s ENABLE", subname);
- report_createsub_log(PG_LOG_DEBUG, PG_LOG_PRIMARY,
- "command is: %s", str->data);
+ pg_log_debug("command is: %s", str->data);
if (!dry_run)
{
res = PQexec(conn, str->data);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not enable subscription \"%s\": %s",
- dbinfo->subname, PQresultErrorMessage(res));
+ pg_log_error("could not enable subscription \"%s\": %s",
+ dbinfo->subname, PQresultErrorMessage(res));
disconnect_database(conn, true);
}
res = PQexec(conn, "SELECT datname FROM pg_database WHERE datistemplate = false AND datallowconn AND datconnlimit <> -2 ORDER BY 1");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "could not obtain a list of databases: %s",
- PQresultErrorMessage(res));
+ pg_log_error("could not obtain a list of databases: %s", PQresultErrorMessage(res));
PQclear(res);
disconnect_database(conn, true);
}
#ifndef WIN32
if (geteuid() == 0)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "cannot be executed by \"root\"");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "You must run %s as the PostgreSQL superuser.",
- progname);
+ pg_log_error("cannot be executed by \"root\"");
+ pg_log_error_hint("You must run %s as the PostgreSQL superuser.",
+ progname);
exit(1);
}
#endif
num_dbs++;
}
else
- report_createsub_fatal("database \"%s\" specified more than once for -d/--database", optarg);
+ pg_fatal("database \"%s\" specified more than once for -d/--database", optarg);
break;
case 'D':
subscriber_dir = pg_strdup(optarg);
num_pubs++;
}
else
- report_createsub_fatal("publication \"%s\" specified more than once for --publication", optarg);
+ pg_fatal("publication \"%s\" specified more than once for --publication", optarg);
break;
case 3:
if (!simple_string_list_member(&opt.replslot_names, optarg))
num_replslots++;
}
else
- report_createsub_fatal("replication slot \"%s\" specified more than once for --replication-slot", optarg);
+ pg_fatal("replication slot \"%s\" specified more than once for --replication-slot", optarg);
break;
case 4:
if (!simple_string_list_member(&opt.sub_names, optarg))
num_subs++;
}
else
- report_createsub_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
+ pg_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
break;
case 5:
if (!simple_string_list_member(&opt.objecttypes_to_clean, optarg))
simple_string_list_append(&opt.objecttypes_to_clean, optarg);
else
- report_createsub_fatal("object type \"%s\" specified more than once for --clean", optarg);
+ pg_fatal("object type \"%s\" specified more than once for --clean", optarg);
break;
default:
/* getopt_long already emitted a complaint */
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.",
- progname);
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
}
if (bad_switch)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "options %s and %s cannot be used together",
- bad_switch, "-a/--all");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.",
- progname);
+ pg_log_error("options %s and %s cannot be used together",
+ bad_switch, "-a/--all");
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
}
/* Any non-option arguments? */
if (optind < argc)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "too many command-line arguments (first is \"%s\")",
- argv[optind]);
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.", progname);
+ pg_log_error("too many command-line arguments (first is \"%s\")",
+ argv[optind]);
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
/* Required arguments */
if (subscriber_dir == NULL)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "no subscriber data directory specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.", progname);
+ pg_log_error("no subscriber data directory specified");
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
char cwd[MAXPGPATH];
if (!getcwd(cwd, MAXPGPATH))
- report_createsub_fatal("could not determine current directory");
+ pg_fatal("could not determine current directory");
opt.socket_dir = pg_strdup(cwd);
canonicalize_path(opt.socket_dir);
}
* identical entries for physical and logical replication. If there is
* not, we would fail anyway.
*/
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "no publisher connection string specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.", progname);
+ pg_log_error("no publisher connection string specified");
+ pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1);
}
if (opt.log_dir != NULL)
{
char *internal_log_file;
+ FILE *internal_log_file_fp;
umask(PG_MODE_MASK_OWNER);
/* logfile_open() will exit if there is an error */
internal_log_file_fp = logfile_open(internal_log_file, "a");
pg_free(internal_log_file);
+
+ pg_logging_set_logfile(internal_log_file_fp);
}
if (dry_run)
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "Executing in dry-run mode.\n"
- "The target directory will not be modified.");
+ pg_log_info("Executing in dry-run mode.\n"
+ "The target directory will not be modified.");
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "validating publisher connection string");
+ pg_log_info("validating publisher connection string");
pub_base_conninfo = get_base_conninfo(opt.pub_conninfo_str,
&dbname_conninfo);
if (pub_base_conninfo == NULL)
exit(1);
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "validating subscriber connection string");
+ pg_log_info("validating subscriber connection string");
sub_base_conninfo = get_sub_conninfo(&opt);
/*
if (opt.database_names.head == NULL)
{
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "no database was specified");
+ pg_log_info("no database was specified");
/*
* Try to obtain the dbname from the publisher conninfo. If dbname
simple_string_list_append(&opt.database_names, dbname_conninfo);
num_dbs++;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "database name \"%s\" was extracted from the publisher connection string",
- dbname_conninfo);
+ pg_log_info("database name \"%s\" was extracted from the publisher connection string",
+ dbname_conninfo);
}
else
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "no database name specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Try \"%s --help\" for more information.",
- progname);
+ pg_log_error("no database name specified");
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ progname);
exit(1);
}
}
/* Number of object names must match number of databases */
if (num_pubs > 0 && num_pubs != num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "wrong number of publication names specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "The number of specified publication names (%d) must match the number of specified database names (%d).",
- num_pubs, num_dbs);
+ pg_log_error("wrong number of publication names specified");
+ pg_log_error_detail("The number of specified publication names (%d) must match the number of specified database names (%d).",
+ num_pubs, num_dbs);
exit(1);
}
if (num_subs > 0 && num_subs != num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "wrong number of subscription names specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "The number of specified subscription names (%d) must match the number of specified database names (%d).",
- num_subs, num_dbs);
+ pg_log_error("wrong number of subscription names specified");
+ pg_log_error_detail("The number of specified subscription names (%d) must match the number of specified database names (%d).",
+ num_subs, num_dbs);
exit(1);
}
if (num_replslots > 0 && num_replslots != num_dbs)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "wrong number of replication slot names specified");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_DETAIL,
- "The number of specified replication slot names (%d) must match the number of specified database names (%d).",
- num_replslots, num_dbs);
+ pg_log_error("wrong number of replication slot names specified");
+ pg_log_error_detail("The number of specified replication slot names (%d) must match the number of specified database names (%d).",
+ num_replslots, num_dbs);
exit(1);
}
dbinfos.objecttypes_to_clean |= OBJECTTYPE_PUBLICATIONS;
else
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "invalid object type \"%s\" specified for %s",
- cell->val, "--clean");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "The valid value is: \"%s\"", "publications");
+ pg_log_error("invalid object type \"%s\" specified for %s",
+ cell->val, "--clean");
+ pg_log_error_hint("The valid value is: \"%s\"", "publications");
exit(1);
}
}
pub_sysid = get_primary_sysid(dbinfos.dbinfo[0].pubconninfo);
sub_sysid = get_standby_sysid(subscriber_dir);
if (pub_sysid != sub_sysid)
- report_createsub_fatal("subscriber data directory is not a copy of the source database cluster");
+ pg_fatal("subscriber data directory is not a copy of the source database cluster");
/* Subscriber PID file */
snprintf(pidfile, MAXPGPATH, "%s/postmaster.pid", subscriber_dir);
*/
if (stat(pidfile, &statbuf) == 0)
{
- report_createsub_log(PG_LOG_ERROR, PG_LOG_PRIMARY,
- "standby server is running");
- report_createsub_log(PG_LOG_ERROR, PG_LOG_HINT,
- "Stop the standby server and try again.");
+ pg_log_error("standby server is running");
+ pg_log_error_hint("Stop the standby server and try again.");
exit(1);
}
* by command-line options). The goal is to avoid connections during the
* transformation steps.
*/
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "starting the standby server with command-line options");
+ pg_log_info("starting the standby server with command-line options");
start_standby_server(&opt, true, false);
/* Check if the standby server is ready for logical replication */
* guarantees it) *before* creating the replication slots in
* setup_publisher().
*/
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "stopping the subscriber");
+ pg_log_info("stopping the subscriber");
stop_standby_server(subscriber_dir);
/* Create the required objects for each database on publisher */
* until accepting connections. We don't want to start logical replication
* during setup.
*/
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "starting the subscriber");
+ pg_log_info("starting the subscriber");
start_standby_server(&opt, true, true);
/* Waiting the subscriber to be promoted */
drop_failover_replication_slots(dbinfos.dbinfo);
/* Stop the subscriber */
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "stopping the subscriber");
+ pg_log_info("stopping the subscriber");
stop_standby_server(subscriber_dir);
/* Change system identifier from subscriber */
success = true;
- report_createsub_log(PG_LOG_INFO, PG_LOG_PRIMARY,
- "Done!");
+ pg_log_info("Done!");
return 0;
}