const DbInfo *old_db, const DbInfo *new_db,
const RelInfo *old_rel, const RelInfo *new_rel,
FileNameMap *map);
-static RelInfo *relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
- const char *nspname, const char *relname);
-static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
- Oid oid);
/*
int relnum;
int num_maps = 0;
+ if (old_db->rel_arr.nrels != new_db->rel_arr.nrels)
+ pg_log(PG_FATAL, "old and new databases \"%s\" have a different number of relations\n",
+ old_db->db_name);
+
maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
old_db->rel_arr.nrels);
for (relnum = 0; relnum < old_db->rel_arr.nrels; relnum++)
{
RelInfo *old_rel = &old_db->rel_arr.rels[relnum];
- RelInfo *new_rel;
-
- /* old/new relation names always match */
- new_rel = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
- old_rel->nspname, old_rel->relname);
+ RelInfo *new_rel = &old_db->rel_arr.rels[relnum];
+ if (old_rel->reloid != new_rel->reloid)
+ pg_log(PG_FATAL, "mismatch of relation id: database \"%s\", old relid %d, new relid %d\n",
+ old_db->db_name, old_rel->reloid, new_rel->reloid);
+
create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
old_rel, new_rel, maps + num_maps);
num_maps++;
"FROM pg_catalog.pg_database d "
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
" ON d.dattablespace = t.oid "
- "WHERE d.datallowconn = true");
+ "WHERE d.datallowconn = true "
+ /* we don't preserve pg_database.oid so we sort by name */
+ "ORDER BY 2");
i_datname = PQfnumber(res, "datname");
i_oid = PQfnumber(res, "oid");
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
" c.reltoastrelid, t.spclocation, "
" n.nspname "
- "ORDER BY t.spclocation, n.nspname, c.relname;",
+ /* we preserve pg_class.oid so we sort by it to match old/new */
+ "ORDER BY 1;",
FirstNormalObjectId,
/* does pg_largeobject_metadata need to be migrated? */
(GET_MAJOR_VERSION(old_cluster.major_version) <= 804) ?
dbinfo->rel_arr.rels = relinfos;
dbinfo->rel_arr.nrels = num_rels;
- dbinfo->rel_arr.last_relname_lookup = 0;
-}
-
-
-/*
- * dbarr_lookup_db()
- *
- * Returns the pointer to the DbInfo structure
- */
-DbInfo *
-dbarr_lookup_db(DbInfoArr *db_arr, const char *db_name)
-{
- int dbnum;
-
- for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
- {
- if (strcmp(db_arr->dbs[dbnum].db_name, db_name) == 0)
- return &db_arr->dbs[dbnum];
- }
-
- return NULL;
-}
-
-
-/*
- * relarr_lookup_rel_name()
- *
- * Searches "relname" in rel_arr. Returns the *real* pointer to the
- * RelInfo structure.
- */
-static RelInfo *
-relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
- const char *nspname, const char *relname)
-{
- int relnum;
-
- /* Test next lookup first, for speed */
- if (rel_arr->last_relname_lookup + 1 < rel_arr->nrels &&
- strcmp(rel_arr->rels[rel_arr->last_relname_lookup + 1].nspname, nspname) == 0 &&
- strcmp(rel_arr->rels[rel_arr->last_relname_lookup + 1].relname, relname) == 0)
- {
- rel_arr->last_relname_lookup++;
- return &rel_arr->rels[rel_arr->last_relname_lookup];
- }
-
- for (relnum = 0; relnum < rel_arr->nrels; relnum++)
- {
- if (strcmp(rel_arr->rels[relnum].nspname, nspname) == 0 &&
- strcmp(rel_arr->rels[relnum].relname, relname) == 0)
- {
- rel_arr->last_relname_lookup = relnum;
- return &rel_arr->rels[relnum];
- }
- }
- pg_log(PG_FATAL, "Could not find %s.%s in %s cluster\n",
- nspname, relname, CLUSTER_NAME(cluster));
- return NULL;
-}
-
-
-/*
- * relarr_lookup_rel_oid()
- *
- * Returns a pointer to the RelInfo structure for the
- * given oid or NULL if the desired entry cannot be
- * found.
- */
-static RelInfo *
-relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
-{
- int relnum;
-
- for (relnum = 0; relnum < rel_arr->nrels; relnum++)
- {
- if (rel_arr->rels[relnum].reloid == oid)
- return &rel_arr->rels[relnum];
- }
- pg_log(PG_FATAL, "Could not find %d in %s cluster\n",
- oid, CLUSTER_NAME(cluster));
- return NULL;
}
{
pg_free(rel_arr->rels);
rel_arr->nrels = 0;
- rel_arr->last_relname_lookup = 0;
}
* Install support functions in the database accessed by
* GLOBALS_DUMP_FILE because it can preserve pg_authid.oid.
*/
- install_support_functions_in_db(os_info.user);
+ install_support_functions_in_new_db(os_info.user);
/*
* We have to create the databases first so we can install support
GLOBALS_DUMP_FILE, log_opts.filename);
check_ok();
+ /* we load this to get a current list of databases */
get_db_and_rel_infos(&new_cluster);
stop_postmaster(false, false);
/* skip db we already installed */
if (strcmp(new_db->db_name, os_info.user) != 0)
- install_support_functions_in_db(new_db->db_name);
+ install_support_functions_in_new_db(new_db->db_name);
}
check_ok();
DB_DUMP_FILE, log_opts.filename);
check_ok();
- /* regenerate now that we have db schemas */
+ /* regenerate now that we have objects in the databases */
dbarr_free(&new_cluster.dbarr);
get_db_and_rel_infos(&new_cluster);
- uninstall_support_functions();
+ uninstall_support_functions_from_new_cluster();
stop_postmaster(false, false);
}
* physically link the databases.
*/
const char *
-transfer_all_new_dbs(DbInfoArr *olddb_arr,
- DbInfoArr *newdb_arr, char *old_pgdata, char *new_pgdata)
+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");
- for (dbnum = 0; dbnum < newdb_arr->ndbs; dbnum++)
+ 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 *new_db = &newdb_arr->dbs[dbnum];
- DbInfo *old_db = dbarr_lookup_db(olddb_arr, new_db->db_name);
+ 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 a 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);