PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <sys/time.h>
#include <sys/wait.h>
#include "catalog/pg_authid_d.h"
#include "common/connect.h"
#include "common/controldata_utils.h"
#include "common/file_perm.h"
#include "common/logging.h"
#include "common/pg_prng.h"
#include "common/restricted_token.h"
#include "fe_utils/recovery_gen.h"
#include "fe_utils/simple_list.h"
#include "getopt_long.h"
Go to the source code of this file.
Data Structures | |
struct | CreateSubscriberOptions |
struct | LogicalRepInfo |
Macros | |
#define | DEFAULT_SUB_PORT "50432" |
#define | USEC_PER_SEC 1000000 |
#define | WAIT_INTERVAL 1 /* 1 second */ |
#define | NUM_CONN_ATTEMPTS 10 |
Enumerations | |
enum | WaitPMResult { POSTMASTER_READY , POSTMASTER_STILL_STARTING , POSTMASTER_READY , POSTMASTER_STILL_STARTING , POSTMASTER_FAILED } |
Functions | |
static void | cleanup_objects_atexit (void) |
static void | usage () |
static char * | get_base_conninfo (const char *conninfo, char **dbname) |
static char * | get_sub_conninfo (const struct CreateSubscriberOptions *opt) |
static char * | get_exec_path (const char *argv0, const char *progname) |
static void | check_data_directory (const char *datadir) |
static char * | concat_conninfo_dbname (const char *conninfo, const char *dbname) |
static struct LogicalRepInfo * | store_pub_sub_info (const struct CreateSubscriberOptions *opt, const char *pub_base_conninfo, const char *sub_base_conninfo) |
static PGconn * | connect_database (const char *conninfo, bool exit_on_error) |
static void | disconnect_database (PGconn *conn, bool exit_on_error) |
static uint64 | get_primary_sysid (const char *conninfo) |
static uint64 | get_standby_sysid (const char *datadir) |
static void | modify_subscriber_sysid (const struct CreateSubscriberOptions *opt) |
static bool | server_is_in_recovery (PGconn *conn) |
static char * | generate_object_name (PGconn *conn) |
static void | check_publisher (const struct LogicalRepInfo *dbinfo) |
static char * | setup_publisher (struct LogicalRepInfo *dbinfo) |
static void | check_subscriber (const struct LogicalRepInfo *dbinfo) |
static void | setup_subscriber (struct LogicalRepInfo *dbinfo, const char *consistent_lsn) |
static void | setup_recovery (const struct LogicalRepInfo *dbinfo, const char *datadir, const char *lsn) |
static void | drop_primary_replication_slot (struct LogicalRepInfo *dbinfo, const char *slotname) |
static char * | create_logical_replication_slot (PGconn *conn, struct LogicalRepInfo *dbinfo) |
static void | drop_replication_slot (PGconn *conn, struct LogicalRepInfo *dbinfo, const char *slot_name) |
static void | pg_ctl_status (const char *pg_ctl_cmd, int rc) |
static void | start_standby_server (const struct CreateSubscriberOptions *opt, bool restricted_access) |
static void | stop_standby_server (const char *datadir) |
static void | wait_for_end_recovery (const char *conninfo, const struct CreateSubscriberOptions *opt) |
static void | create_publication (PGconn *conn, struct LogicalRepInfo *dbinfo) |
static void | drop_publication (PGconn *conn, struct LogicalRepInfo *dbinfo) |
static void | create_subscription (PGconn *conn, const struct LogicalRepInfo *dbinfo) |
static void | set_replication_progress (PGconn *conn, const struct LogicalRepInfo *dbinfo, const char *lsn) |
static void | enable_subscription (PGconn *conn, const struct LogicalRepInfo *dbinfo) |
int | main (int argc, char **argv) |
Variables | |
static const char * | progname |
static char * | primary_slot_name = NULL |
static bool | dry_run = false |
static bool | success = false |
static struct LogicalRepInfo * | dbinfo |
static int | num_dbs = 0 |
static int | num_pubs = 0 |
static int | num_subs = 0 |
static int | num_replslots = 0 |
static pg_prng_state | prng_state |
static char * | pg_ctl_path = NULL |
static char * | pg_resetwal_path = NULL |
static char * | subscriber_dir = NULL |
static bool | recovery_ended = false |
static bool | standby_running = false |
#define DEFAULT_SUB_PORT "50432" |
Definition at line 31 of file pg_createsubscriber.c.
#define NUM_CONN_ATTEMPTS 10 |
#define USEC_PER_SEC 1000000 |
Definition at line 105 of file pg_createsubscriber.c.
#define WAIT_INTERVAL 1 /* 1 second */ |
Definition at line 106 of file pg_createsubscriber.c.
enum WaitPMResult |
Enumerator | |
---|---|
POSTMASTER_READY | |
POSTMASTER_STILL_STARTING | |
POSTMASTER_READY | |
POSTMASTER_STILL_STARTING | |
POSTMASTER_FAILED |
Definition at line 132 of file pg_createsubscriber.c.
|
static |
Definition at line 364 of file pg_createsubscriber.c.
References datadir, MAXPGPATH, pg_fatal, pg_log_info, snprintf, and stat.
Referenced by main().
|
static |
Definition at line 806 of file pg_createsubscriber.c.
References appendPQExpBuffer(), conn, connect_database(), createPQExpBuffer(), dbinfo, disconnect_database(), exit(), num_dbs, pg_free(), pg_log_debug, pg_log_error, pg_log_error_hint, pg_log_info, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQescapeLiteral(), PQexec(), PQgetvalue(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), primary_slot_name, res, server_is_in_recovery(), str, and wal_level.
Referenced by main().
|
static |
Definition at line 967 of file pg_createsubscriber.c.
References conn, connect_database(), dbinfo, disconnect_database(), exit(), num_dbs, pg_log_debug, pg_log_error, pg_log_error_hint, pg_log_info, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQexec(), PQgetvalue(), PQresultErrorMessage(), PQresultStatus(), primary_slot_name, res, and server_is_in_recovery().
Referenced by main().
|
static |
Definition at line 151 of file pg_createsubscriber.c.
References conn, connect_database(), dbinfo, dbname, disconnect_database(), drop_publication(), drop_replication_slot(), i, LogicalRepInfo::made_publication, LogicalRepInfo::made_replslot, num_dbs, pg_log_warning, pg_log_warning_hint, LogicalRepInfo::pubconninfo, LogicalRepInfo::pubname, recovery_ended, LogicalRepInfo::replslotname, standby_running, stop_standby_server(), subscriber_dir, and success.
Referenced by main().
|
static |
Definition at line 396 of file pg_createsubscriber.c.
References appendPQExpBuffer(), appendPQExpBufferStr(), Assert, buf, createPQExpBuffer(), dbname, destroyPQExpBuffer(), and pg_strdup().
Referenced by store_pub_sub_info().
Definition at line 492 of file pg_createsubscriber.c.
References ALWAYS_SECURE_SEARCH_PATH_SQL, conn, CONNECTION_OK, exit(), pg_log_error, PGRES_TUPLES_OK, PQclear(), PQconnectdb(), PQerrorMessage(), PQexec(), PQfinish(), PQresultErrorMessage(), PQresultStatus(), PQstatus(), and res.
Referenced by check_publisher(), check_subscriber(), cleanup_objects_atexit(), drop_primary_replication_slot(), get_primary_sysid(), setup_publisher(), setup_recovery(), setup_subscriber(), and wait_for_end_recovery().
|
static |
Definition at line 1188 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), dry_run, LogicalRepInfo::made_replslot, pg_free(), pg_log_debug, pg_log_error, pg_log_info, pg_strdup(), PGRES_TUPLES_OK, PQclear(), PQescapeLiteral(), PQexec(), PQgetvalue(), PQresultErrorMessage(), PQresultStatus(), LogicalRepInfo::replslotname, res, and str.
Referenced by setup_publisher().
|
static |
Definition at line 1443 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), disconnect_database(), dry_run, LogicalRepInfo::made_publication, pg_free(), pg_log_debug, pg_log_error, pg_log_error_hint, pg_log_info, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PQclear(), PQescapeIdentifier(), PQescapeLiteral(), PQexec(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), LogicalRepInfo::pubname, res, resetPQExpBuffer(), and str.
Referenced by setup_publisher().
|
static |
Definition at line 1571 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), disconnect_database(), dry_run, pg_free(), pg_log_debug, pg_log_error, pg_log_info, PGRES_COMMAND_OK, PQclear(), PQescapeIdentifier(), PQescapeLiteral(), PQexec(), PQresultErrorMessage(), PQresultStatus(), LogicalRepInfo::pubconninfo, LogicalRepInfo::pubname, LogicalRepInfo::replslotname, res, str, and LogicalRepInfo::subname.
Referenced by setup_subscriber().
Definition at line 532 of file pg_createsubscriber.c.
References Assert, conn, exit(), and PQfinish().
Referenced by check_publisher(), check_subscriber(), cleanup_objects_atexit(), create_publication(), create_subscription(), drop_primary_replication_slot(), enable_subscription(), generate_object_name(), get_primary_sysid(), server_is_in_recovery(), set_replication_progress(), setup_publisher(), setup_recovery(), setup_subscriber(), and wait_for_end_recovery().
|
static |
Definition at line 1159 of file pg_createsubscriber.c.
References conn, connect_database(), dbinfo, disconnect_database(), drop_replication_slot(), pg_log_warning, pg_log_warning_hint, and primary_slot_name.
Referenced by main().
|
static |
Definition at line 1517 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), dry_run, LogicalRepInfo::made_publication, pg_free(), pg_log_debug, pg_log_error, pg_log_info, PGRES_COMMAND_OK, PQclear(), PQescapeIdentifier(), PQexec(), PQresultErrorMessage(), PQresultStatus(), LogicalRepInfo::pubname, res, and str.
Referenced by cleanup_objects_atexit(), and setup_subscriber().
|
static |
Definition at line 1237 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), dry_run, LogicalRepInfo::made_replslot, pg_free(), pg_log_debug, pg_log_error, pg_log_info, PGRES_TUPLES_OK, PQclear(), PQescapeLiteral(), PQexec(), PQresultErrorMessage(), PQresultStatus(), res, and str.
Referenced by cleanup_objects_atexit(), and drop_primary_replication_slot().
|
static |
Definition at line 1720 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, destroyPQExpBuffer(), disconnect_database(), dry_run, pg_free(), pg_log_debug, pg_log_error, pg_log_info, PGRES_COMMAND_OK, PQclear(), PQescapeIdentifier(), PQexec(), PQresultErrorMessage(), PQresultStatus(), res, str, LogicalRepInfo::subname, and subname.
Referenced by setup_subscriber().
|
static |
Definition at line 672 of file pg_createsubscriber.c.
References conn, disconnect_database(), pg_log_error, pg_prng_uint32(), PGRES_TUPLES_OK, PQclear(), PQexec(), PQgetvalue(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), prng_state, psprintf(), and res.
Referenced by setup_publisher().
|
static |
Definition at line 252 of file pg_createsubscriber.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), buf, createPQExpBuffer(), dbname, destroyPQExpBuffer(), errmsg(), i, _PQconninfoOption::keyword, pg_log_error, pg_strdup(), PQconninfoFree(), PQconninfoParse(), PQfreemem(), and _PQconninfoOption::val.
Referenced by main().
|
static |
Definition at line 328 of file pg_createsubscriber.c.
References argv0, exec_path, find_my_exec(), find_other_exec(), MAXPGPATH, pg_fatal, pg_log_debug, pg_malloc(), progname, psprintf(), and strlcpy().
Referenced by main().
|
static |
Definition at line 547 of file pg_createsubscriber.c.
References conn, connect_database(), disconnect_database(), pg_log_error, pg_log_info, PGRES_TUPLES_OK, PQclear(), PQexec(), PQgetvalue(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), res, and strtou64.
Referenced by main().
|
static |
Definition at line 588 of file pg_createsubscriber.c.
References datadir, get_controlfile(), pg_fatal, pg_free(), pg_log_info, and ControlFileData::system_identifier.
Referenced by main().
|
static |
Definition at line 302 of file pg_createsubscriber.c.
References appendPQExpBuffer(), buf, createPQExpBuffer(), destroyPQExpBuffer(), pg_strdup(), progname, CreateSubscriberOptions::socket_dir, CreateSubscriberOptions::sub_port, and CreateSubscriberOptions::sub_username.
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 1755 of file pg_createsubscriber.c.
References canonicalize_path(), check_data_directory(), check_publisher(), check_subscriber(), cleanup_objects_atexit(), CreateSubscriberOptions::config_file, CreateSubscriberOptions::database_names, dbinfo, DEFAULT_SUB_PORT, drop_primary_replication_slot(), dry_run, exit(), get_base_conninfo(), get_exec_path(), get_primary_sysid(), get_progname(), get_restricted_token(), get_standby_sysid(), get_sub_conninfo(), getopt_long(), SimpleStringList::head, MAXPGPATH, modify_subscriber_sysid(), no_argument, num_dbs, num_pubs, num_replslots, num_subs, optarg, optind, pg_ctl_path, pg_fatal, pg_log_error, pg_log_error_hint, pg_log_info, PG_LOG_WARNING, pg_logging_increase_verbosity(), pg_logging_init(), pg_logging_set_level(), pg_resetwal_path, pg_strdup(), PG_TEXTDOMAIN, primary_slot_name, progname, CreateSubscriberOptions::pub_conninfo_str, CreateSubscriberOptions::pub_names, CreateSubscriberOptions::recovery_timeout, CreateSubscriberOptions::replslot_names, required_argument, set_pglocale_pgservice(), setup_publisher(), setup_recovery(), setup_subscriber(), simple_string_list_append(), simple_string_list_member(), snprintf, CreateSubscriberOptions::socket_dir, start_standby_server(), stat, stop_standby_server(), store_pub_sub_info(), CreateSubscriberOptions::sub_names, CreateSubscriberOptions::sub_port, CreateSubscriberOptions::sub_username, subscriber_dir, success, usage(), and wait_for_end_recovery().
|
static |
Definition at line 616 of file pg_createsubscriber.c.
References DEVNULL, dry_run, get_controlfile(), gettimeofday(), pg_fatal, pg_free(), pg_log_debug, pg_log_info, pg_resetwal_path, psprintf(), subscriber_dir, ControlFileData::system_identifier, and update_controlfile().
Referenced by main().
|
static |
Definition at line 1277 of file pg_createsubscriber.c.
References exit(), pg_log_error, pg_log_error_detail, pg_strsignal(), WEXITSTATUS, WIFEXITED, WIFSIGNALED, and WTERMSIG.
Referenced by start_standby_server(), and stop_standby_server().
Definition at line 778 of file pg_createsubscriber.c.
References conn, disconnect_database(), pg_log_error, PGRES_TUPLES_OK, PQclear(), PQexec(), PQgetvalue(), PQresultErrorMessage(), PQresultStatus(), and res.
Referenced by check_publisher(), check_subscriber(), and wait_for_end_recovery().
|
static |
Definition at line 1629 of file pg_createsubscriber.c.
References appendPQExpBuffer(), Assert, conn, createPQExpBuffer(), dbinfo, LogicalRepInfo::dbname, dbname, destroyPQExpBuffer(), disconnect_database(), dry_run, InvalidOid, InvalidXLogRecPtr, LSN_FORMAT_ARGS, pg_free(), pg_log_debug, pg_log_error, pg_log_info, PGRES_TUPLES_OK, PQclear(), PQescapeLiteral(), PQexec(), PQgetvalue(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), psprintf(), res, resetPQExpBuffer(), str, LogicalRepInfo::subname, and subname.
Referenced by setup_subscriber().
|
static |
Definition at line 721 of file pg_createsubscriber.c.
References conn, connect_database(), create_logical_replication_slot(), create_publication(), dbinfo, disconnect_database(), dry_run, exit(), generate_object_name(), i, num_dbs, num_pubs, num_replslots, num_subs, pg_free(), pg_log_info, pg_prng_seed(), pg_strdup(), prng_state, LogicalRepInfo::pubname, LogicalRepInfo::replslotname, LogicalRepInfo::subname, and subname.
Referenced by main().
|
static |
Definition at line 1099 of file pg_createsubscriber.c.
References appendPQExpBuffer(), conn, connect_database(), PQExpBufferData::data, datadir, dbinfo, disconnect_database(), dry_run, GenerateRecoveryConfig(), InvalidXLogRecPtr, LSN_FORMAT_ARGS, pg_log_debug, recoveryconfcontents, and WriteRecoveryConfig().
Referenced by main().
|
static |
Definition at line 1067 of file pg_createsubscriber.c.
References conn, connect_database(), create_subscription(), dbinfo, disconnect_database(), drop_publication(), enable_subscription(), i, num_dbs, and set_replication_progress().
Referenced by main().
|
static |
Definition at line 1307 of file pg_createsubscriber.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), CreateSubscriberOptions::config_file, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), pg_ctl_path, pg_ctl_status(), pg_log_debug, pg_log_info, CreateSubscriberOptions::socket_dir, standby_running, CreateSubscriberOptions::sub_port, and subscriber_dir.
Referenced by main().
|
static |
Definition at line 1344 of file pg_createsubscriber.c.
References datadir, pg_ctl_path, pg_ctl_status(), pg_log_debug, pg_log_info, psprintf(), and standby_running.
Referenced by cleanup_objects_atexit(), main(), and wait_for_end_recovery().
|
static |
Definition at line 420 of file pg_createsubscriber.c.
References concat_conninfo_dbname(), CreateSubscriberOptions::database_names, dbinfo, LogicalRepInfo::dbname, SimpleStringList::head, i, LogicalRepInfo::made_publication, LogicalRepInfo::made_replslot, SimpleStringListCell::next, num_dbs, num_pubs, num_replslots, num_subs, pg_log_debug, pg_malloc_array, CreateSubscriberOptions::pub_names, LogicalRepInfo::pubconninfo, LogicalRepInfo::pubname, CreateSubscriberOptions::replslot_names, LogicalRepInfo::replslotname, CreateSubscriberOptions::sub_names, LogicalRepInfo::subconninfo, LogicalRepInfo::subname, subname, and SimpleStringListCell::val.
Referenced by main().
|
static |
Definition at line 211 of file pg_createsubscriber.c.
References _, DEFAULT_SUB_PORT, printf, and progname.
Referenced by main().
|
static |
Definition at line 1365 of file pg_createsubscriber.c.
References conn, connect_database(), disconnect_database(), dry_run, NUM_CONN_ATTEMPTS, pg_fatal, pg_log_error, pg_log_info, pg_log_info_hint, pg_usleep(), POSTMASTER_READY, POSTMASTER_STILL_STARTING, PQclear(), PQexec(), PQntuples(), recovery_ended, CreateSubscriberOptions::recovery_timeout, res, server_is_in_recovery(), stop_standby_server(), subscriber_dir, USEC_PER_SEC, and WAIT_INTERVAL.
Referenced by main().
|
static |
Definition at line 115 of file pg_createsubscriber.c.
Referenced by check_publisher(), check_subscriber(), cleanup_objects_atexit(), create_logical_replication_slot(), create_publication(), create_subscription(), drop_primary_replication_slot(), drop_publication(), drop_replication_slot(), enable_subscription(), get_db_subscription_count(), get_old_cluster_logical_slot_infos(), get_rel_infos(), main(), set_replication_progress(), setup_publisher(), setup_recovery(), setup_subscriber(), and store_pub_sub_info().
Definition at line 111 of file pg_createsubscriber.c.
Referenced by copy_file(), create_logical_replication_slot(), create_publication(), create_subscription(), create_target_dir(), create_target_symlink(), debug_reconstruction(), drop_publication(), drop_replication_slot(), enable_subscription(), main(), modify_subscriber_sysid(), open_target_file(), reconstruct_from_incremental_file(), remove_target_dir(), remove_target_file(), remove_target_symlink(), set_replication_progress(), setup_publisher(), setup_recovery(), sync_target_dir(), truncate_target_file(), wait_for_end_recovery(), write_reconstructed_file(), and write_target_range().
|
static |
Definition at line 116 of file pg_createsubscriber.c.
Referenced by check_publisher(), check_subscriber(), cleanup_objects_atexit(), main(), setup_publisher(), setup_subscriber(), and store_pub_sub_info().
|
static |
Definition at line 117 of file pg_createsubscriber.c.
Referenced by main(), setup_publisher(), and store_pub_sub_info().
|
static |
Definition at line 119 of file pg_createsubscriber.c.
Referenced by main(), setup_publisher(), and store_pub_sub_info().
|
static |
Definition at line 118 of file pg_createsubscriber.c.
Referenced by main(), setup_publisher(), and store_pub_sub_info().
|
static |
Definition at line 123 of file pg_createsubscriber.c.
Referenced by main(), start_standby_server(), and stop_standby_server().
|
static |
Definition at line 124 of file pg_createsubscriber.c.
Referenced by main(), and modify_subscriber_sysid().
|
static |
Definition at line 110 of file pg_createsubscriber.c.
Referenced by check_publisher(), check_subscriber(), drop_primary_replication_slot(), and main().
|
static |
Definition at line 121 of file pg_createsubscriber.c.
Referenced by generate_object_name(), and setup_publisher().
|
static |
Definition at line 108 of file pg_createsubscriber.c.
Referenced by get_exec_path(), get_sub_conninfo(), main(), and usage().
Definition at line 129 of file pg_createsubscriber.c.
Referenced by cleanup_objects_atexit(), and wait_for_end_recovery().
Definition at line 130 of file pg_createsubscriber.c.
Referenced by cleanup_objects_atexit(), start_standby_server(), and stop_standby_server().
|
static |
Definition at line 127 of file pg_createsubscriber.c.
Referenced by cleanup_objects_atexit(), main(), modify_subscriber_sysid(), start_standby_server(), and wait_for_end_recovery().
Definition at line 113 of file pg_createsubscriber.c.
Referenced by cleanup_objects_atexit(), and main().