void issue_warnings(char *sequence_script_file_name) { /* old = PG 8.3 warnings? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803) { start_postmaster(&new_cluster); /* restore proper sequence values using file created from old server */ if (sequence_script_file_name) { prep_status("Adjusting sequences"); exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), sequence_script_file_name); unlink(sequence_script_file_name); check_ok(); } old_8_3_rebuild_tsvector_tables(&new_cluster, false); old_8_3_invalidate_hash_gin_indexes(&new_cluster, false); old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false); stop_postmaster(false); } /* Create dummy large object permissions for old < PG 9.0? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) { start_postmaster(&new_cluster); new_9_0_populate_pg_largeobject_metadata(&new_cluster, false); stop_postmaster(false); } }
static void setup(char *argv0, bool *live_check) { char exec_path[MAXPGPATH]; /* full path to my executable */ /* * make sure the user has a clean environment, otherwise, we may confuse * libpq when we connect to one (or both) of the servers. */ check_pghost_envvar(); verify_directories(); /* no postmasters should be running, except for a live check */ if (pid_lock_file_exists(old_cluster.pgdata)) { /* * If we have a postmaster.pid file, try to start the server. If it * starts, the pid file was stale, so stop the server. If it doesn't * start, assume the server is running. If the pid file is left over * from a server crash, this also allows any committed transactions * stored in the WAL to be replayed so they are not lost, because WAL * files are not transferred from old to new servers. We later check * for a clean shutdown. */ if (start_postmaster(&old_cluster, false)) stop_postmaster(false); else { if (!user_opts.check) pg_fatal("There seems to be a postmaster servicing the old cluster.\n" "Please shutdown that postmaster and try again.\n"); else *live_check = true; } } /* same goes for the new postmaster */ if (pid_lock_file_exists(new_cluster.pgdata)) { if (start_postmaster(&new_cluster, false)) stop_postmaster(false); else pg_fatal("There seems to be a postmaster servicing the new cluster.\n" "Please shutdown that postmaster and try again.\n"); } /* get path to pg_upgrade executable */ if (find_my_exec(argv0, exec_path) < 0) pg_fatal("%s: could not find own program executable\n", argv0); /* Trim off program name and keep just path */ *last_dir_separator(exec_path) = '\0'; canonicalize_path(exec_path); os_info.exec_path = pg_strdup(exec_path); }
void issue_warnings(void) { /* Create dummy large object permissions for old < PG 9.0? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) { start_postmaster(&new_cluster, true); new_9_0_populate_pg_largeobject_metadata(&new_cluster, false); stop_postmaster(false); } }
void issue_warnings(char *sequence_script_file_name) { /* old = PG 8.3 warnings? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803) { start_postmaster(&new_cluster); /* restore proper sequence values using file created from old server */ if (sequence_script_file_name) { prep_status("Adjusting sequences"); exec_prog(true, true, UTILITY_LOG_FILE, NULL, SYSTEMQUOTE "\"%s/psql\" --echo-queries " "--set ON_ERROR_STOP=on " "--no-psqlrc --port %d --username \"%s\" " "-f \"%s\" --dbname template1 >> \"%s\" 2>&1" SYSTEMQUOTE, new_cluster.bindir, new_cluster.port, os_info.user, sequence_script_file_name, UTILITY_LOG_FILE); unlink(sequence_script_file_name); check_ok(); } old_8_3_rebuild_tsvector_tables(&new_cluster, false); old_8_3_invalidate_hash_gin_indexes(&new_cluster, false); old_8_3_invalidate_bpchar_pattern_ops_indexes(&new_cluster, false); stop_postmaster(false); } /* Create dummy large object permissions for old < PG 9.0? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) { start_postmaster(&new_cluster); new_9_0_populate_pg_largeobject_metadata(&new_cluster, false); stop_postmaster(false); } }
void check_and_dump_old_cluster(bool live_check) { /* -- OLD -- */ if (!live_check) start_postmaster(&old_cluster, true); get_pg_database_relfilenode(&old_cluster); /* Extract a list of databases and tables from the old cluster */ get_db_and_rel_infos(&old_cluster); init_tablespaces(); get_loadable_libraries(); /* * Check for various failure cases */ check_is_install_user(&old_cluster); check_proper_datallowconn(&old_cluster); check_for_prepared_transactions(&old_cluster); check_for_reg_data_type_usage(&old_cluster); check_for_isn_and_int8_passing_mismatch(&old_cluster); if (GET_MAJOR_VERSION(old_cluster.major_version) == 904 && old_cluster.controldata.cat_ver < JSONB_FORMAT_CHANGE_CAT_VER) check_for_jsonb_9_4_usage(&old_cluster); /* Pre-PG 9.4 had a different 'line' data type internal format */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 903) old_9_3_check_for_line_data_type_usage(&old_cluster); /* Pre-PG 9.0 had no large object permissions */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) new_9_0_populate_pg_largeobject_metadata(&old_cluster, true); /* * While not a check option, we do this now because this is the only time * the old server is running. */ if (!user_opts.check) generate_old_dump(); if (!live_check) stop_postmaster(false); }
void issue_warnings_and_set_wal_level(void) { /* * We unconditionally start/stop the new server because pg_resetwal -o set * wal_level to 'minimum'. If the user is upgrading standby servers using * the rsync instructions, they will need pg_upgrade to write its final * WAL record showing wal_level as 'replica'. */ start_postmaster(&new_cluster, true); /* Create dummy large object permissions for old < PG 9.0? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) new_9_0_populate_pg_largeobject_metadata(&new_cluster, false); /* Reindex hash indexes for old < 10.0 */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906) old_9_6_invalidate_hash_indexes(&new_cluster, false); stop_postmaster(false); }
int main(int argc, char **argv) { char *analyze_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_upgrade")); /* Set default restrictive mask until new cluster permissions are read */ umask(PG_MODE_MASK_OWNER); parseCommandLine(argc, argv); get_restricted_token(os_info.progname); adjust_data_dir(&old_cluster); adjust_data_dir(&new_cluster); setup(argv[0], &live_check); output_check_banner(live_check); check_cluster_versions(); get_sock_dir(&old_cluster, live_check); get_sock_dir(&new_cluster, false); check_cluster_compatibility(live_check); /* Set mask based on PGDATA permissions */ if (!GetDataDirectoryCreatePerm(new_cluster.pgdata)) { pg_log(PG_FATAL, "could not read permissions of directory \"%s\": %s\n", new_cluster.pgdata, strerror(errno)); exit(1); } umask(pg_mode_mask); check_and_dump_old_cluster(live_check); /* -- NEW -- */ start_postmaster(&new_cluster, true); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\n" "Performing Upgrade\n" "------------------\n"); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_xact_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster, true); prepare_new_globals(); create_new_objects(); stop_postmaster(false); /* * Most failures happen in create_new_objects(), which has completed at * this point. We do this here because it is just before linking, which * will link the old and new cluster data files, preventing the old * cluster from being safely started once the new cluster is started. */ if (user_opts.transfer_mode == TRANSFER_MODE_LINK) disable_old_cluster(); transfer_all_new_tablespaces(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next OID for new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/pg_resetwal\" -o %u \"%s\"", new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); prep_status("Sync data directory to disk"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir, new_cluster.pgdata); check_ok(); create_script_for_cluster_analyze(&analyze_script_file_name); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings_and_set_wal_level(); pg_log(PG_REPORT, "\n" "Upgrade Complete\n" "----------------\n"); output_completion_banner(analyze_script_file_name, deletion_script_file_name); pg_free(analyze_script_file_name); pg_free(deletion_script_file_name); cleanup(); return 0; }
void check_old_cluster(bool live_check, char **sequence_script_file_name) { /* -- OLD -- */ if (!live_check) start_postmaster(&old_cluster); set_locale_and_encoding(&old_cluster); get_pg_database_relfilenode(&old_cluster); /* Extract a list of databases and tables from the old cluster */ get_db_and_rel_infos(&old_cluster); init_tablespaces(); get_loadable_libraries(); /* * Check for various failure cases */ check_is_super_user(&old_cluster); check_for_prepared_transactions(&old_cluster); check_for_reg_data_type_usage(&old_cluster); check_for_isn_and_int8_passing_mismatch(&old_cluster); /* old = PG 8.3 checks? */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 803) { old_8_3_check_for_name_data_type_usage(&old_cluster); old_8_3_check_for_tsquery_usage(&old_cluster); old_8_3_check_ltree_usage(&old_cluster); if (user_opts.check) { old_8_3_rebuild_tsvector_tables(&old_cluster, true); old_8_3_invalidate_hash_gin_indexes(&old_cluster, true); old_8_3_invalidate_bpchar_pattern_ops_indexes(&old_cluster, true); } else /* * While we have the old server running, create the script to * properly restore its sequence values but we report this at the * end. */ *sequence_script_file_name = old_8_3_create_sequence_script(&old_cluster); } /* Pre-PG 9.0 had no large object permissions */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) new_9_0_populate_pg_largeobject_metadata(&old_cluster, true); /* * While not a check option, we do this now because this is the only time * the old server is running. */ if (!user_opts.check) { generate_old_dump(); split_old_dump(); } if (!live_check) stop_postmaster(false); }
int main(int argc, char **argv) { char *sequence_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; parseCommandLine(argc, argv); output_check_banner(&live_check); setup(argv[0], live_check); check_cluster_versions(); check_cluster_compatibility(live_check); check_old_cluster(live_check, &sequence_script_file_name); /* -- NEW -- */ start_postmaster(&new_cluster); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\nPerforming Upgrade\n"); pg_log(PG_REPORT, "------------------\n"); disable_old_cluster(); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_clog_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster); prepare_new_databases(); create_new_objects(); stop_postmaster(false); transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next oid for new cluster"); exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -o %u \"%s\" > " DEVNULL SYSTEMQUOTE, new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings(sequence_script_file_name); pg_log(PG_REPORT, "\nUpgrade complete\n"); pg_log(PG_REPORT, "----------------\n"); output_completion_banner(deletion_script_file_name); pg_free(deletion_script_file_name); pg_free(sequence_script_file_name); cleanup(); return 0; }
int main(int argc, char **argv) { char *sequence_script_file_name = NULL; char *analyze_script_file_name = NULL; char *deletion_script_file_name = NULL; bool live_check = false; parseCommandLine(argc, argv); adjust_data_dir(&old_cluster); adjust_data_dir(&new_cluster); output_check_banner(&live_check); setup(argv[0], live_check); check_cluster_versions(); get_sock_dir(&old_cluster, live_check); get_sock_dir(&new_cluster, false); check_cluster_compatibility(live_check); check_and_dump_old_cluster(live_check, &sequence_script_file_name); /* -- NEW -- */ start_postmaster(&new_cluster); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\nPerforming Upgrade\n"); pg_log(PG_REPORT, "------------------\n"); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_clog_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster); prepare_new_databases(); create_new_objects(); stop_postmaster(false); /* * Most failures happen in create_new_objects(), which has completed at * this point. We do this here because it is just before linking, which * will link the old and new cluster data files, preventing the old * cluster from being safely started once the new cluster is started. */ if (user_opts.transfer_mode == TRANSFER_MODE_LINK) disable_old_cluster(); transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr, old_cluster.pgdata, new_cluster.pgdata); /* * Assuming OIDs are only used in system tables, there is no need to * restore the OID counter because we have not transferred any OIDs from * the old system, but we do it anyway just in case. We do it late here * because there is no need to have the schema load use new oids. */ prep_status("Setting next OID for new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/pg_resetxlog\" -o %u \"%s\"", new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid, new_cluster.pgdata); check_ok(); prep_status("Sync data directory to disk"); exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir, new_cluster.pgdata); check_ok(); create_script_for_cluster_analyze(&analyze_script_file_name); create_script_for_old_cluster_deletion(&deletion_script_file_name); issue_warnings(sequence_script_file_name); pg_log(PG_REPORT, "\nUpgrade Complete\n"); pg_log(PG_REPORT, "----------------\n"); output_completion_banner(analyze_script_file_name, deletion_script_file_name); pg_free(analyze_script_file_name); pg_free(deletion_script_file_name); pg_free(sequence_script_file_name); cleanup(); return 0; }
static void do_start(void) { pgpid_t pid; pgpid_t old_pid = 0; int exitcode; if (ctl_command != RESTART_COMMAND) { old_pid = get_pgpid(); if (old_pid != 0) write_stderr(_("%s: another server might be running; " "trying to start server anyway\n"), progname); } read_post_opts(); /* No -D or -D already added during server start */ if (ctl_command == RESTART_COMMAND || pgdata_opt == NULL) pgdata_opt = ""; if (exec_path == NULL) exec_path = find_other_exec_or_die(argv0, "postgres", PG_BACKEND_VERSIONSTR); #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) if (allow_core_files) unlimit_core_size(); #endif /* * If possible, tell the postmaster our parent shell's PID (see the * comments in CreateLockFile() for motivation). Windows hasn't got * getppid() unfortunately. */ #ifndef WIN32 { static char env_var[32]; snprintf(env_var, sizeof(env_var), "PG_GRANDPARENT_PID=%d", (int) getppid()); putenv(env_var); } #endif exitcode = start_postmaster(); if (exitcode != 0) { write_stderr(_("%s: could not start server: exit code was %d\n"), progname, exitcode); exit(1); } if (old_pid != 0) { pg_usleep(1000000); pid = get_pgpid(); if (pid == old_pid) { write_stderr(_("%s: could not start server\n" "Examine the log output.\n"), progname); exit(1); } } if (do_wait) { print_msg(_("waiting for server to start...")); if (test_postmaster_connection(false) == false) { write_stderr(_("%s: could not start server\n" "Examine the log output.\n"), progname); exit(1); } else { print_msg(_(" done\n")); print_msg(_("server started\n")); } } else print_msg(_("server starting\n")); }
static void do_start(void) { pgpid_t pid; pgpid_t old_pid = 0; int exitcode; if (ctl_command != RESTART_COMMAND) { old_pid = get_pgpid(); if (old_pid != 0) write_stderr(_("%s: another server might be running; " "trying to start server anyway\n"), progname); } read_post_opts(); /* No -D or -D already added during server start */ if (ctl_command == RESTART_COMMAND || pgdata_opt == NULL) pgdata_opt = ""; if (postgres_path == NULL) { char *postmaster_path; int ret; postmaster_path = pg_malloc(MAXPGPATH); if ((ret = find_other_exec(argv0, "postgres", PM_VERSIONSTR, postmaster_path)) < 0) { char full_path[MAXPGPATH]; if (find_my_exec(argv0, full_path) < 0) strlcpy(full_path, progname, sizeof(full_path)); if (ret == -1) write_stderr(_("The program \"postgres\" is needed by %s " "but was not found in the\n" "same directory as \"%s\".\n" "Check your installation.\n"), progname, full_path); else write_stderr(_("The program \"postgres\" was found by \"%s\"\n" "but was not the same version as %s.\n" "Check your installation.\n"), full_path, progname); exit(1); } postgres_path = postmaster_path; } #if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) if (allow_core_files) unlimit_core_size(); #endif exitcode = start_postmaster(); if (exitcode != 0) { write_stderr(_("%s: could not start server: exit code was %d\n"), progname, exitcode); exit(1); } if (old_pid != 0) { pg_usleep(1000000); pid = get_pgpid(); if (pid == old_pid) { write_stderr(_("%s: could not start server\n" "Examine the log output.\n"), progname); exit(1); } } if (do_wait) { print_msg(_("waiting for server to start...")); if (test_postmaster_connection(false) == false) { printf(_("could not start server\n")); exit(1); } else { print_msg(_(" done\n")); print_msg(_("server started\n")); } } else print_msg(_("server starting\n")); }