/* * transfer_all_new_dbs() * * Responsible for upgrading all database. invokes routines to generate mappings and then * physically link the databases. */ void transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata, char *old_tablespace) { int old_dbnum, new_dbnum; /* Scan the old cluster databases and transfer their files */ for (old_dbnum = new_dbnum = 0; old_dbnum < old_db_arr->ndbs; old_dbnum++, new_dbnum++) { DbInfo *old_db = &old_db_arr->dbs[old_dbnum], *new_db = NULL; FileNameMap *mappings; int n_maps; /* * Advance past any databases that exist in the new cluster but not in * the old, e.g. "postgres". (The user might have removed the * 'postgres' database from the old cluster.) */ for (; new_dbnum < new_db_arr->ndbs; new_dbnum++) { new_db = &new_db_arr->dbs[new_dbnum]; if (strcmp(old_db->db_name, new_db->db_name) == 0) break; } if (new_dbnum >= new_db_arr->ndbs) pg_fatal("old database \"%s\" not found in the new cluster\n", old_db->db_name); mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata, new_pgdata); if (n_maps) { print_maps(mappings, n_maps, new_db->db_name); transfer_single_new_db(mappings, n_maps, old_tablespace); } /* We allocate something even for n_maps == 0 */ pg_free(mappings); } return; }
/* * transfer_all_new_dbs() * * Responsible for upgrading all database. invokes routines to generate mappings and then * physically link the databases. */ const char * transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata) { int dbnum; const char *msg = NULL; prep_status("Restoring user relation files\n"); if (old_db_arr->ndbs != new_db_arr->ndbs) pg_log(PG_FATAL, "old and new clusters have a different number of databases\n"); for (dbnum = 0; dbnum < old_db_arr->ndbs; dbnum++) { DbInfo *old_db = &old_db_arr->dbs[dbnum]; DbInfo *new_db = &new_db_arr->dbs[dbnum]; FileNameMap *mappings; int n_maps; pageCnvCtx *pageConverter = NULL; if (strcmp(old_db->db_name, new_db->db_name) != 0) pg_log(PG_FATAL, "old and new databases have different names: old \"%s\", new \"%s\"\n", old_db->db_name, new_db->db_name); n_maps = 0; mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata, new_pgdata); if (n_maps) { print_maps(mappings, n_maps, new_db->db_name); #ifdef PAGE_CONVERSION msg = setupPageConverter(&pageConverter); #endif transfer_single_new_db(pageConverter, mappings, n_maps); pg_free(mappings); } } prep_status(""); /* in case nothing printed */ check_ok(); return msg; }
/* * transfer_all_new_dbs() * * Responsible for upgrading all database. invokes routines to generate mappings and then * physically link the databases. */ const char * transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata) { int old_dbnum, new_dbnum; const char *msg = NULL; prep_status("%s user relation files\n", user_opts.transfer_mode == TRANSFER_MODE_LINK ? "Linking" : "Copying"); /* Scan the old cluster databases and transfer their files */ for (old_dbnum = new_dbnum = 0; old_dbnum < old_db_arr->ndbs; old_dbnum++, new_dbnum++) { DbInfo *old_db = &old_db_arr->dbs[old_dbnum], *new_db = NULL; FileNameMap *mappings; int n_maps; pageCnvCtx *pageConverter = NULL; /* * Advance past any databases that exist in the new cluster but not in * the old, e.g. "postgres". (The user might have removed the * 'postgres' database from the old cluster.) */ for (; new_dbnum < new_db_arr->ndbs; new_dbnum++) { new_db = &new_db_arr->dbs[new_dbnum]; if (strcmp(old_db->db_name, new_db->db_name) == 0) break; } if (new_dbnum >= new_db_arr->ndbs) pg_log(PG_FATAL, "old database \"%s\" not found in the new cluster\n", old_db->db_name); n_maps = 0; mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata, new_pgdata); if (n_maps) { print_maps(mappings, n_maps, new_db->db_name); #ifdef PAGE_CONVERSION msg = setupPageConverter(&pageConverter); #endif transfer_single_new_db(pageConverter, mappings, n_maps); pg_free(mappings); } } prep_status(" "); /* in case nothing printed; pass a space so * gcc doesn't complain about empty format * string */ check_ok(); return msg; }