@@ -33,8 +33,6 @@ static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
33
33
* generates database mappings for "old_db" and "new_db". Returns a malloc'ed
34
34
* array of mappings. nmaps is a return parameter which refers to the number
35
35
* mappings.
36
- *
37
- * NOTE: Its the Caller's responsibility to free the returned array.
38
36
*/
39
37
FileNameMap *
40
38
gen_db_file_maps (DbInfo * old_db ,DbInfo * new_db ,
@@ -45,72 +43,56 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
45
43
int num_maps = 0 ;
46
44
47
45
maps = (FileNameMap * )pg_malloc (sizeof (FileNameMap )*
48
- new_db -> rel_arr .nrels );
46
+ old_db -> rel_arr .nrels );
49
47
50
- for (relnum = 0 ;relnum < new_db -> rel_arr .nrels ;relnum ++ )
48
+ for (relnum = 0 ;relnum < old_db -> rel_arr .nrels ;relnum ++ )
51
49
{
52
- RelInfo * newrel = & new_db -> rel_arr .rels [relnum ];
53
- RelInfo * oldrel ;
50
+ RelInfo * oldrel = & old_db -> rel_arr .rels [relnum ];
51
+ RelInfo * newrel ;
54
52
55
- /* toast tables are handled by theirparent */
56
- if (strcmp (newrel -> nspname ,"pg_toast" )== 0 )
53
+ /* toast tables are handled by theirparents */
54
+ if (strcmp (oldrel -> nspname ,"pg_toast" )== 0 )
57
55
continue ;
58
56
59
- oldrel = relarr_lookup_rel_name (& old_cluster ,& old_db -> rel_arr ,
60
- newrel -> nspname ,newrel -> relname );
57
+ newrel = relarr_lookup_rel_name (& old_cluster ,& old_db -> rel_arr ,
58
+ oldrel -> nspname ,oldrel -> relname );
61
59
62
60
create_rel_filename_map (old_pgdata ,new_pgdata ,old_db ,new_db ,
63
61
oldrel ,newrel ,maps + num_maps );
64
62
num_maps ++ ;
65
63
66
64
/*
67
65
* So much for mapping this relation; now we need a mapping
68
- * for its corresponding toast relation, if any.
66
+ * for its corresponding toast relation and toast index , if any.
69
67
*/
70
68
if (oldrel -> toastrelid > 0 )
71
69
{
72
- RelInfo * new_toast ;
73
- RelInfo * old_toast ;
74
- char new_name [MAXPGPATH ];
75
- char old_name [MAXPGPATH ];
76
-
77
- /* construct the new and old relnames for the toast relation */
78
- snprintf (old_name ,sizeof (old_name ),"pg_toast_%u" ,oldrel -> reloid );
79
- snprintf (new_name ,sizeof (new_name ),"pg_toast_%u" ,newrel -> reloid );
70
+ char old_name [MAXPGPATH ],new_name [MAXPGPATH ];
71
+ RelInfo * old_toast ,* new_toast ;
80
72
81
- /* look them up in their respective arrays */
82
73
old_toast = relarr_lookup_rel_oid (& old_cluster ,& old_db -> rel_arr ,
83
- oldrel -> toastrelid );
84
- new_toast = relarr_lookup_rel_name (& new_cluster ,& new_db -> rel_arr ,
85
- "pg_toast" , new_name );
74
+ oldrel -> toastrelid );
75
+ new_toast = relarr_lookup_rel_oid (& new_cluster ,& new_db -> rel_arr ,
76
+ newrel -> toastrelid );
86
77
87
- /* finally create a mapping for them */
88
78
create_rel_filename_map (old_pgdata ,new_pgdata ,old_db ,new_db ,
89
79
old_toast ,new_toast ,maps + num_maps );
90
80
num_maps ++ ;
91
81
92
82
/*
93
- * also need to provide a mapping for the index of this toast
83
+ *We also need to provide a mapping for the index of this toast
94
84
* relation. The procedure is similar to what we did above for
95
85
* toast relation itself, the only difference being that the
96
86
* relnames need to be appended with _index.
97
87
*/
98
-
99
- /*
100
- * construct the new and old relnames for the toast index
101
- * relations
102
- */
103
88
snprintf (old_name ,sizeof (old_name ),"%s_index" ,old_toast -> relname );
104
- snprintf (new_name ,sizeof (new_name ),"pg_toast_%u_index" ,
105
- newrel -> reloid );
89
+ snprintf (new_name ,sizeof (new_name ),"%s_index" ,new_toast -> relname );
106
90
107
- /* look them up in their respective arrays */
108
91
old_toast = relarr_lookup_rel_name (& old_cluster ,& old_db -> rel_arr ,
109
92
"pg_toast" ,old_name );
110
93
new_toast = relarr_lookup_rel_name (& new_cluster ,& new_db -> rel_arr ,
111
94
"pg_toast" ,new_name );
112
95
113
- /* finally create a mapping for them */
114
96
create_rel_filename_map (old_pgdata ,new_pgdata ,old_db ,
115
97
new_db ,old_toast ,new_toast ,maps + num_maps );
116
98
num_maps ++ ;
@@ -133,15 +115,6 @@ create_rel_filename_map(const char *old_data, const char *new_data,
133
115
const RelInfo * old_rel ,const RelInfo * new_rel ,
134
116
FileNameMap * map )
135
117
{
136
- map -> old_relfilenode = old_rel -> relfilenode ;
137
- map -> new_relfilenode = new_rel -> relfilenode ;
138
-
139
- snprintf (map -> old_nspname ,sizeof (map -> old_nspname ),"%s" ,old_rel -> nspname );
140
- snprintf (map -> new_nspname ,sizeof (map -> new_nspname ),"%s" ,new_rel -> nspname );
141
-
142
- snprintf (map -> old_relname ,sizeof (map -> old_relname ),"%s" ,old_rel -> relname );
143
- snprintf (map -> new_relname ,sizeof (map -> new_relname ),"%s" ,new_rel -> relname );
144
-
145
118
if (strlen (old_rel -> tablespace )== 0 )
146
119
{
147
120
/*
@@ -155,14 +128,21 @@ create_rel_filename_map(const char *old_data, const char *new_data,
155
128
}
156
129
else
157
130
{
158
- /*
159
- * relation belongs to some tablespace, so use the tablespace location
160
- */
131
+ /* relation belongs to a tablespace, so use the tablespace location */
161
132
snprintf (map -> old_dir ,sizeof (map -> old_dir ),"%s%s/%u" ,old_rel -> tablespace ,
162
133
old_cluster .tablespace_suffix ,old_db -> db_oid );
163
134
snprintf (map -> new_dir ,sizeof (map -> new_dir ),"%s%s/%u" ,new_rel -> tablespace ,
164
135
new_cluster .tablespace_suffix ,new_db -> db_oid );
165
136
}
137
+
138
+ map -> old_relfilenode = old_rel -> relfilenode ;
139
+ map -> new_relfilenode = new_rel -> relfilenode ;
140
+
141
+ /* used only for logging and error reporing */
142
+ snprintf (map -> old_nspname ,sizeof (map -> old_nspname ),"%s" ,old_rel -> nspname );
143
+ snprintf (map -> new_nspname ,sizeof (map -> new_nspname ),"%s" ,new_rel -> nspname );
144
+ snprintf (map -> old_relname ,sizeof (map -> old_relname ),"%s" ,old_rel -> relname );
145
+ snprintf (map -> new_relname ,sizeof (map -> new_relname ),"%s" ,new_rel -> relname );
166
146
}
167
147
168
148