43 #ifdef HAVE_LANGINFO_H
47 #include "catalog/pg_class_d.h"
61 static void setup(
char *
argv0,
bool *live_check);
81 main(
int argc,
char **argv)
83 char *deletion_script_file_name = NULL;
84 bool live_check =
false;
108 pg_fatal(
"could not read permissions of directory \"%s\": %m",
119 setup(argv[0], &live_check);
141 "Performing Upgrade\n"
142 "------------------");
187 "\"%s/pg_resetwal\" -o %u \"%s\"",
211 "\"%s/initdb\" --sync-only \"%s\" --sync-method %s",
229 pg_free(deletion_script_file_name);
246 time_t run_time = time(NULL);
256 pg_fatal(
"directory path for new cluster is too long");
260 tt = (time_t) time.tv_sec;
261 strftime(timebuf,
sizeof(timebuf),
"%Y%m%dT%H%M%S", localtime(&tt));
263 snprintf(timebuf + strlen(timebuf),
sizeof(timebuf) - strlen(timebuf),
264 ".%03d", (
int) (time.tv_usec / 1000));
269 pg_fatal(
"directory path for new cluster is too long");
276 pg_fatal(
"directory path for new cluster is too long");
283 pg_fatal(
"directory path for new cluster is too long");
298 len =
snprintf(filename_path,
sizeof(filename_path),
"%s/%s",
300 if (
len >=
sizeof(filename_path))
301 pg_fatal(
"directory path for new cluster is too long");
304 pg_fatal(
"could not open log file \"%s\": %m", filename_path);
309 len =
snprintf(filename_path,
sizeof(filename_path),
"%s/%s",
311 if (
len >=
sizeof(filename_path))
312 pg_fatal(
"directory path for new cluster is too long");
313 if ((fp =
fopen_priv(filename_path,
"a")) == NULL)
314 pg_fatal(
"could not write to log file \"%s\": %m", filename_path);
317 "-----------------------------------------------------------------\n"
318 " pg_upgrade run on %s"
319 "-----------------------------------------------------------------\n\n",
345 pg_fatal(
"%s: could not find own program executable",
argv0);
371 pg_fatal(
"There seems to be a postmaster servicing the old cluster.\n"
372 "Please shutdown that postmaster and try again.");
384 pg_fatal(
"There seems to be a postmaster servicing the new cluster.\n"
385 "Please shutdown that postmaster and try again.");
400 PGconn *conn_new_template1;
401 char *datcollate_literal;
402 char *datctype_literal;
403 char *datlocale_literal = NULL;
406 prep_status(
"Setting locale and encoding for new cluster");
413 strlen(
locale->db_collate));
416 strlen(
locale->db_ctype));
420 strlen(
locale->db_locale));
427 "UPDATE pg_catalog.pg_database "
428 " SET encoding = %d, "
429 " datlocprovider = '%c', "
433 " WHERE datname = 'template0' ",
441 "UPDATE pg_catalog.pg_database "
442 " SET encoding = %d, "
443 " datlocprovider = '%c', "
446 " daticulocale = %s "
447 " WHERE datname = 'template0' ",
455 "UPDATE pg_catalog.pg_database "
456 " SET encoding = %d, "
459 " WHERE datname = 'template0' ",
482 prep_status(
"Analyzing all rows in the new cluster");
484 "\"%s/vacuumdb\" %s --all --analyze %s",
495 prep_status(
"Freezing all rows in the new cluster");
497 "\"%s/vacuumdb\" %s --all --freeze %s",
515 prep_status(
"Restoring global objects in the new cluster");
543 const char *create_opts;
546 if (strcmp(old_db->
db_name,
"template1") != 0)
558 create_opts =
"--clean --create";
564 "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
565 "--dbname postgres \"%s/%s\"",
580 const char *create_opts;
583 if (strcmp(old_db->
db_name,
"template1") == 0)
595 if (strcmp(old_db->
db_name,
"postgres") == 0)
596 create_opts =
"--clean --create";
598 create_opts =
"--create";
602 "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
603 "--dbname template1 \"%s/%s\"",
640 if (!
rmtree(new_path, rmtopdir))
641 pg_fatal(
"could not delete directory \"%s\"", new_path);
660 prep_status(
"Copying old %s to new server", old_subdir);
664 "cp -Rf \"%s\" \"%s\"",
667 "xcopy /e /y /q /r \"%s\" \"%s\\\"",
682 "pg_clog" :
"pg_xact",
684 "pg_clog" :
"pg_xact");
688 "\"%s/pg_resetwal\" -f -u %u \"%s\"",
694 prep_status(
"Setting next transaction ID and epoch for new cluster");
696 "\"%s/pg_resetwal\" -f -x %u \"%s\"",
700 "\"%s/pg_resetwal\" -f -e %u \"%s\"",
705 "\"%s/pg_resetwal\" -f -c %u,%u \"%s\"",
724 prep_status(
"Setting next multixact ID and offset for new cluster");
731 "\"%s/pg_resetwal\" -O %u -m %u,%u \"%s\"",
748 prep_status(
"Setting oldest multixact ID in new cluster");
759 "\"%s/pg_resetwal\" -m %u,%u \"%s\"",
811 prep_status(
"Setting frozenxid and minmxid counters in new cluster");
813 prep_status(
"Setting minmxid counter in new cluster");
820 "UPDATE pg_catalog.pg_database "
821 "SET datfrozenxid = '%u'",
826 "UPDATE pg_catalog.pg_database "
827 "SET datminmxid = '%u'",
832 "SELECT datname, datallowconn "
833 "FROM pg_catalog.pg_database");
836 i_datallowconn =
PQfnumber(dbres,
"datallowconn");
839 for (dbnum = 0; dbnum < ntups; dbnum++)
853 "ALTER DATABASE %s ALLOW_CONNECTIONS = true",
861 "UPDATE pg_catalog.pg_class "
862 "SET relfrozenxid = '%u' "
872 "UPDATE pg_catalog.pg_class "
873 "SET relminmxid = '%u' "
885 "ALTER DATABASE %s ALLOW_CONNECTIONS = false",
914 if (slot_arr->
nslots == 0)
922 for (
int slotnum = 0; slotnum < slot_arr->
nslots; slotnum++)
929 "pg_catalog.pg_create_logical_replication_slot(");
936 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 output_check_banner(bool live_check)
void check_cluster_versions(void)
void check_cluster_compatibility(bool live_check)
void check_and_dump_old_cluster(bool live_check)
void issue_warnings_and_set_wal_level(void)
void check_new_cluster(void)
void report_clusters_compatible(void)
void create_script_for_old_cluster_deletion(char **deletion_script_file_name)
void output_completion_banner(char *deletion_script_file_name)
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
void get_db_rel_and_slot_infos(ClusterInfo *cluster, bool live_check)
int count_old_cluster_logical_slots(void)
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, bool *live_check)
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 get_sock_dir(ClusterInfo *cluster, bool live_check)
void parseCommandLine(int argc, char *argv[])
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
LogicalSlotInfoArr slot_arr
transferMode transfer_mode
int gettimeofday(struct timeval *tp, void *tzp)