43 #include "catalog/pg_class_d.h"
55 #define RESTORE_TRANSACTION_SIZE 1000
84 main(
int argc,
char **argv)
86 char *deletion_script_file_name = NULL;
110 pg_fatal(
"could not read permissions of directory \"%s\": %m",
143 "Performing Upgrade\n"
144 "------------------");
189 "\"%s/pg_resetwal\" -o %u \"%s\"",
213 "\"%s/initdb\" --sync-only \"%s\" --sync-method %s",
231 pg_free(deletion_script_file_name);
248 time_t run_time = time(NULL);
258 pg_fatal(
"directory path for new cluster is too long");
262 tt = (time_t) time.tv_sec;
263 strftime(timebuf,
sizeof(timebuf),
"%Y%m%dT%H%M%S", localtime(&tt));
265 snprintf(timebuf + strlen(timebuf),
sizeof(timebuf) - strlen(timebuf),
266 ".%03d", (
int) (time.tv_usec / 1000));
271 pg_fatal(
"directory path for new cluster is too long");
278 pg_fatal(
"directory path for new cluster is too long");
285 pg_fatal(
"directory path for new cluster is too long");
300 len =
snprintf(filename_path,
sizeof(filename_path),
"%s/%s",
302 if (
len >=
sizeof(filename_path))
303 pg_fatal(
"directory path for new cluster is too long");
306 pg_fatal(
"could not open log file \"%s\": %m", filename_path);
311 len =
snprintf(filename_path,
sizeof(filename_path),
"%s/%s",
313 if (
len >=
sizeof(filename_path))
314 pg_fatal(
"directory path for new cluster is too long");
315 if ((fp =
fopen_priv(filename_path,
"a")) == NULL)
316 pg_fatal(
"could not write to log file \"%s\": %m", filename_path);
319 "-----------------------------------------------------------------\n"
320 " pg_upgrade run on %s"
321 "-----------------------------------------------------------------\n\n",
347 pg_fatal(
"%s: could not find own program executable",
argv0);
373 pg_fatal(
"There seems to be a postmaster servicing the old cluster.\n"
374 "Please shutdown that postmaster and try again.");
386 pg_fatal(
"There seems to be a postmaster servicing the new cluster.\n"
387 "Please shutdown that postmaster and try again.");
402 PGconn *conn_new_template1;
403 char *datcollate_literal;
404 char *datctype_literal;
405 char *datlocale_literal = NULL;
408 prep_status(
"Setting locale and encoding for new cluster");
415 strlen(
locale->db_collate));
418 strlen(
locale->db_ctype));
422 strlen(
locale->db_locale));
429 "UPDATE pg_catalog.pg_database "
430 " SET encoding = %d, "
431 " datlocprovider = '%c', "
435 " WHERE datname = 'template0' ",
443 "UPDATE pg_catalog.pg_database "
444 " SET encoding = %d, "
445 " datlocprovider = '%c', "
448 " daticulocale = %s "
449 " WHERE datname = 'template0' ",
457 "UPDATE pg_catalog.pg_database "
458 " SET encoding = %d, "
461 " WHERE datname = 'template0' ",
484 prep_status(
"Analyzing all rows in the new cluster");
486 "\"%s/vacuumdb\" %s --all --analyze %s",
497 prep_status(
"Freezing all rows in the new cluster");
499 "\"%s/vacuumdb\" %s --all --freeze %s",
517 prep_status(
"Restoring global objects in the new cluster");
532 PGconn *conn_new_template1;
557 const char *create_opts;
560 if (strcmp(old_db->
db_name,
"template1") != 0)
572 create_opts =
"--clean --create";
578 "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
579 "--transaction-size=%d "
580 "--dbname postgres \"%s/%s\"",
596 const char *create_opts;
600 if (strcmp(old_db->
db_name,
"template1") == 0)
612 if (strcmp(old_db->
db_name,
"postgres") == 0)
613 create_opts =
"--clean --create";
615 create_opts =
"--create";
627 txn_size =
Max(txn_size, 10);
632 "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
633 "--transaction-size=%d "
634 "--dbname template1 \"%s/%s\"",
672 if (!
rmtree(new_path, rmtopdir))
673 pg_fatal(
"could not delete directory \"%s\"", new_path);
692 prep_status(
"Copying old %s to new server", old_subdir);
696 "cp -Rf \"%s\" \"%s\"",
699 "xcopy /e /y /q /r \"%s\" \"%s\\\"",
714 "pg_clog" :
"pg_xact",
716 "pg_clog" :
"pg_xact");
720 "\"%s/pg_resetwal\" -f -u %u \"%s\"",
726 prep_status(
"Setting next transaction ID and epoch for new cluster");
728 "\"%s/pg_resetwal\" -f -x %u \"%s\"",
732 "\"%s/pg_resetwal\" -f -e %u \"%s\"",
737 "\"%s/pg_resetwal\" -f -c %u,%u \"%s\"",
756 prep_status(
"Setting next multixact ID and offset for new cluster");
763 "\"%s/pg_resetwal\" -O %u -m %u,%u \"%s\"",
780 prep_status(
"Setting oldest multixact ID in new cluster");
791 "\"%s/pg_resetwal\" -m %u,%u \"%s\"",
843 prep_status(
"Setting frozenxid and minmxid counters in new cluster");
845 prep_status(
"Setting minmxid counter in new cluster");
852 "UPDATE pg_catalog.pg_database "
853 "SET datfrozenxid = '%u'",
858 "UPDATE pg_catalog.pg_database "
859 "SET datminmxid = '%u'",
864 "SELECT datname, datallowconn "
865 "FROM pg_catalog.pg_database");
868 i_datallowconn =
PQfnumber(dbres,
"datallowconn");
871 for (dbnum = 0; dbnum < ntups; dbnum++)
885 "ALTER DATABASE %s ALLOW_CONNECTIONS = true",
893 "UPDATE pg_catalog.pg_class "
894 "SET relfrozenxid = '%u' "
904 "UPDATE pg_catalog.pg_class "
905 "SET relminmxid = '%u' "
917 "ALTER DATABASE %s ALLOW_CONNECTIONS = false",
946 if (slot_arr->
nslots == 0)
954 for (
int slotnum = 0; slotnum < slot_arr->
nslots; slotnum++)
961 "pg_catalog.pg_create_logical_replication_slot(");
968 slot_info->
failover ?
"true" :
"false");
bool exec_prog(const char *log_filename, const char *opt_log_file, bool report_error, bool exit_on_error, const char *fmt,...)
bool pid_lock_file_exists(const char *datadir)
void verify_directories(void)
bool reap_child(bool wait_for_child)
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
#define PG_TEXTDOMAIN(domain)
void check_cluster_versions(void)
void issue_warnings_and_set_wal_level(void)
void check_cluster_compatibility(void)
void check_new_cluster(void)
void report_clusters_compatible(void)
void create_script_for_old_cluster_deletion(char **deletion_script_file_name)
void check_and_dump_old_cluster(void)
void output_completion_banner(char *deletion_script_file_name)
void output_check_banner(void)
int find_my_exec(const char *argv0, char *retpath)
void set_pglocale_pgservice(const char *argv0, const char *app)
void disable_old_cluster(void)
void PQfinish(PGconn *conn)
void PQfreemem(void *ptr)
int PQntuples(const PGresult *res)
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQfnumber(const PGresult *res, const char *field_name)
void * pg_malloc0(size_t size)
char * pg_strdup(const char *in)
bool GetDataDirectoryCreatePerm(const char *dataDir)
#define PG_MODE_MASK_OWNER
int count_old_cluster_logical_slots(void)
void get_db_rel_and_slot_infos(ClusterInfo *cluster)
static void check_ok(void)
void pg_logging_init(const char *argv0)
static void adjust_data_dir(void)
static pid_t start_postmaster(void)
static void create_logical_replication_slots(void)
static void set_frozenxids(bool minmxid_only)
static void make_outputdirs(char *pgdata)
static void prepare_new_cluster(void)
int main(int argc, char **argv)
static void copy_subdir_files(const char *old_subdir, const char *new_subdir)
static void create_new_objects(void)
static void remove_new_subdir(const char *subdir, bool rmtopdir)
static void copy_xact_xlog_xid(void)
static void set_locale_and_encoding(void)
static void setup(char *argv0)
#define RESTORE_TRANSACTION_SIZE
static void prepare_new_globals(void)
void transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata)
#define SERVER_START_LOG_FILE
void check_pghost_envvar(void)
#define MULTIXACT_FORMATCHANGE_CAT_VER
#define GLOBALS_DUMP_FILE
#define DB_DUMP_LOG_FILE_MASK
void cleanup_output_dirs(void)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
void void prep_status_progress(const char *fmt,...) pg_attribute_printf(1
#define fopen_priv(path, mode)
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
#define GET_MAJOR_VERSION(v)
void stop_postmaster(bool in_atexit)
void prep_status(const char *fmt,...) pg_attribute_printf(1
#define INTERNAL_LOG_FILE
void end_progress_output(void)
PGresult char * cluster_conn_opts(ClusterInfo *cluster)
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
#define DB_DUMP_FILE_MASK
char * last_dir_separator(const char *filename)
void canonicalize_path(char *path)
PQExpBuffer createPQExpBuffer(void)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void get_restricted_token(void)
bool rmtree(const char *path, bool rmtopdir)
const char * quote_identifier(const char *ident)
void parseCommandLine(int argc, char *argv[])
void get_sock_dir(ClusterInfo *cluster)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
LogicalSlotInfoArr slot_arr
transferMode transfer_mode
int gettimeofday(struct timeval *tp, void *tzp)