static void prepare_new_databases(void) { /* * We set autovacuum_freeze_max_age to its maximum value so autovacuum * does not launch here and delete clog files, before the frozen xids are * set. */ set_frozenxids(false); prep_status("Restoring global objects in the new cluster"); /* * We have to create the databases first so we can install support * functions in all the other databases. Ideally we could create the * support functions in template1 but pg_dumpall creates database using * the template0 template. */ exec_prog(UTILITY_LOG_FILE, NULL, true, "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), GLOBALS_DUMP_FILE); check_ok(); /* we load this to get a current list of databases */ get_db_and_rel_infos(&new_cluster); }
static void create_new_objects(void) { int dbnum; prep_status("Restoring database schemas in the new cluster\n"); for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) { char sql_file_name[MAXPGPATH], log_file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; PQExpBufferData connstr, escaped_connstr; initPQExpBuffer(&connstr); appendPQExpBuffer(&connstr, "dbname="); appendConnStrVal(&connstr, old_db->db_name); initPQExpBuffer(&escaped_connstr); appendShellString(&escaped_connstr, connstr.data); termPQExpBuffer(&connstr); pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); /* * pg_dump only produces its output at the end, so there is little * parallelism if using the pipe. */ parallel_exec_prog(log_file_name, NULL, "\"%s/pg_restore\" %s --exit-on-error --verbose --dbname %s \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), escaped_connstr.data, sql_file_name); termPQExpBuffer(&escaped_connstr); } /* reap all children */ while (reap_child(true) == true) ; end_progress_output(); check_ok(); /* * We don't have minmxids for databases or relations in pre-9.3 clusters, * so set those after we have restored the schema. */ if (GET_MAJOR_VERSION(old_cluster.major_version) < 903) set_frozenxids(true); /* regenerate now that we have objects in the databases */ get_db_and_rel_infos(&new_cluster); }
static void prepare_new_globals(void) { /* * Before we restore anything, set frozenxids of initdb-created tables. */ set_frozenxids(false); /* * Now restore global objects (roles and tablespaces). */ prep_status("Restoring global objects in the new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), GLOBALS_DUMP_FILE); check_ok(); }
static void prepare_new_databases(void) { /* * We set autovacuum_freeze_max_age to its maximum value so autovacuum * does not launch here and delete clog files, before the frozen xids are * set. */ set_frozenxids(); prep_status("Creating databases in the new cluster"); /* * Install support functions in the global-restore database to preserve * pg_authid.oid. */ install_support_functions_in_new_db(GLOBAL_DUMP_DB); /* * We have to create the databases first so we can install support * functions in all the other databases. Ideally we could create the * support functions in template1 but pg_dumpall creates database using * the template0 template. */ exec_prog(true, SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on " /* --no-psqlrc prevents AUTOCOMMIT=off */ "--no-psqlrc --port %d --username \"%s\" " "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE, new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd, GLOBALS_DUMP_FILE, #ifndef WIN32 log_opts.filename #else DEVNULL #endif ); check_ok(); /* we load this to get a current list of databases */ get_db_and_rel_infos(&new_cluster); }
static void prepare_new_databases(void) { /* * We set autovacuum_freeze_max_age to its maximum value so autovacuum * does not launch here and delete clog files, before the frozen xids are * set. */ set_frozenxids(); prep_status("Creating databases in the new cluster"); /* * Install support functions in the global-object restore database to * preserve pg_authid.oid. pg_dumpall uses 'template0' as its template * database so objects we add into 'template1' are not propogated. They * are removed on pg_upgrade exit. */ install_support_functions_in_new_db("template1"); /* * We have to create the databases first so we can install support * functions in all the other databases. Ideally we could create the * support functions in template1 but pg_dumpall creates database using * the template0 template. */ exec_prog(true, true, RESTORE_LOG_FILE, SYSTEMQUOTE "\"%s/psql\" --echo-queries " "--set ON_ERROR_STOP=on " /* --no-psqlrc prevents AUTOCOMMIT=off */ "--no-psqlrc --port %d --username \"%s\" " "-f \"%s\" --dbname template1 >> \"%s\" 2>&1" SYSTEMQUOTE, new_cluster.bindir, new_cluster.port, os_info.user, GLOBALS_DUMP_FILE, RESTORE_LOG_FILE); check_ok(); /* we load this to get a current list of databases */ get_db_and_rel_infos(&new_cluster); }
static void prepare_new_databases(void) { /* * We set autovacuum_freeze_max_age to its maximum value so autovacuum * does not launch here and delete clog files, before the frozen xids are * set. */ set_frozenxids(); prep_status("Restoring global objects in the new cluster"); /* * Install support functions in the global-object restore database to * preserve pg_authid.oid. pg_dumpall uses 'template0' as its template * database so objects we add into 'template1' are not propogated. They * are removed on pg_upgrade exit. */ install_support_functions_in_new_db("template1"); /* * We have to create the databases first so we can install support * functions in all the other databases. Ideally we could create the * support functions in template1 but pg_dumpall creates database using * the template0 template. */ exec_prog(RESTORE_LOG_FILE, NULL, true, "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), GLOBALS_DUMP_FILE); check_ok(); /* we load this to get a current list of databases */ get_db_and_rel_infos(&new_cluster); }
static void create_new_objects(void) { int dbnum; prep_status("Restoring database schemas in the new cluster\n"); /* * We cannot process the template1 database concurrently with others, * because when it's transiently dropped, connection attempts would fail. * So handle it in a separate non-parallelized pass. */ for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) { char sql_file_name[MAXPGPATH], log_file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; const char *create_opts; /* Process only template1 in this pass */ if (strcmp(old_db->db_name, "template1") != 0) continue; pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); /* * template1 and postgres databases will already exist in the target * installation, so tell pg_restore to drop and recreate them; * otherwise we would fail to propagate their database-level * properties. */ create_opts = "--clean --create"; exec_prog(log_file_name, NULL, true, true, "\"%s/pg_restore\" %s %s --exit-on-error --verbose " "--dbname postgres \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), create_opts, sql_file_name); break; /* done once we've processed template1 */ } for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) { char sql_file_name[MAXPGPATH], log_file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; const char *create_opts; /* Skip template1 in this pass */ if (strcmp(old_db->db_name, "template1") == 0) continue; pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); /* * template1 and postgres databases will already exist in the target * installation, so tell pg_restore to drop and recreate them; * otherwise we would fail to propagate their database-level * properties. */ if (strcmp(old_db->db_name, "postgres") == 0) create_opts = "--clean --create"; else create_opts = "--create"; parallel_exec_prog(log_file_name, NULL, "\"%s/pg_restore\" %s %s --exit-on-error --verbose " "--dbname template1 \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), create_opts, sql_file_name); } /* reap all children */ while (reap_child(true) == true) ; end_progress_output(); check_ok(); /* * We don't have minmxids for databases or relations in pre-9.3 clusters, * so set those after we have restored the schema. */ if (GET_MAJOR_VERSION(old_cluster.major_version) < 903) set_frozenxids(true); /* update new_cluster info now that we have objects in the databases */ get_db_and_rel_infos(&new_cluster); }
static void create_new_objects(void) { int dbnum; prep_status("Adding support functions to new cluster"); /* * Technically, we only need to install these support functions in new * databases that also exist in the old cluster, but for completeness we * process all new databases. */ for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++) { DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum]; /* skip db we already installed */ if (strcmp(new_db->db_name, "template1") != 0) install_support_functions_in_new_db(new_db->db_name); } check_ok(); prep_status("Restoring database schemas in the new cluster\n"); for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) { char sql_file_name[MAXPGPATH], log_file_name[MAXPGPATH]; DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; pg_log(PG_STATUS, "%s", old_db->db_name); snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); /* * pg_dump only produces its output at the end, so there is little * parallelism if using the pipe. */ parallel_exec_prog(log_file_name, NULL, "\"%s/pg_restore\" %s --exit-on-error --verbose --dbname \"%s\" \"%s\"", new_cluster.bindir, cluster_conn_opts(&new_cluster), old_db->db_name, sql_file_name); } /* reap all children */ while (reap_child(true) == true) ; end_progress_output(); check_ok(); /* * We don't have minmxids for databases or relations in pre-9.3 * clusters, so set those after we have restores the schemas. */ if (GET_MAJOR_VERSION(old_cluster.major_version) < 903) set_frozenxids(true); optionally_create_toast_tables(); /* regenerate now that we have objects in the databases */ get_db_and_rel_infos(&new_cluster); uninstall_support_functions_from_new_cluster(); }