Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
5cff5b57
Commit
5cff5b57
authored
Jan 05, 2011
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify pg_upgrade's creation of the map file structure. Also clean
up pg_dump's calling of pg_upgrade_support functions.
parent
66a8a042
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
80 deletions
+69
-80
contrib/pg_upgrade/info.c
contrib/pg_upgrade/info.c
+26
-46
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/pg_upgrade.h
+12
-6
contrib/pg_upgrade/version_old_8_3.c
contrib/pg_upgrade/version_old_8_3.c
+8
-8
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.c
+23
-20
No files found.
contrib/pg_upgrade/info.c
View file @
5cff5b57
...
@@ -33,8 +33,6 @@ static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
...
@@ -33,8 +33,6 @@ static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
* generates database mappings for "old_db" and "new_db". Returns a malloc'ed
* generates database mappings for "old_db" and "new_db". Returns a malloc'ed
* array of mappings. nmaps is a return parameter which refers to the number
* array of mappings. nmaps is a return parameter which refers to the number
* mappings.
* mappings.
*
* NOTE: Its the Caller's responsibility to free the returned array.
*/
*/
FileNameMap
*
FileNameMap
*
gen_db_file_maps
(
DbInfo
*
old_db
,
DbInfo
*
new_db
,
gen_db_file_maps
(
DbInfo
*
old_db
,
DbInfo
*
new_db
,
...
@@ -45,19 +43,19 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
...
@@ -45,19 +43,19 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
int
num_maps
=
0
;
int
num_maps
=
0
;
maps
=
(
FileNameMap
*
)
pg_malloc
(
sizeof
(
FileNameMap
)
*
maps
=
(
FileNameMap
*
)
pg_malloc
(
sizeof
(
FileNameMap
)
*
new
_db
->
rel_arr
.
nrels
);
old
_db
->
rel_arr
.
nrels
);
for
(
relnum
=
0
;
relnum
<
new
_db
->
rel_arr
.
nrels
;
relnum
++
)
for
(
relnum
=
0
;
relnum
<
old
_db
->
rel_arr
.
nrels
;
relnum
++
)
{
{
RelInfo
*
newrel
=
&
new
_db
->
rel_arr
.
rels
[
relnum
];
RelInfo
*
oldrel
=
&
old
_db
->
rel_arr
.
rels
[
relnum
];
RelInfo
*
old
rel
;
RelInfo
*
new
rel
;
/* toast tables are handled by their parent */
/* toast tables are handled by their parent
s
*/
if
(
strcmp
(
new
rel
->
nspname
,
"pg_toast"
)
==
0
)
if
(
strcmp
(
old
rel
->
nspname
,
"pg_toast"
)
==
0
)
continue
;
continue
;
old
rel
=
relarr_lookup_rel_name
(
&
old_cluster
,
&
old_db
->
rel_arr
,
new
rel
=
relarr_lookup_rel_name
(
&
old_cluster
,
&
old_db
->
rel_arr
,
newrel
->
nspname
,
new
rel
->
relname
);
oldrel
->
nspname
,
old
rel
->
relname
);
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
new_db
,
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
new_db
,
oldrel
,
newrel
,
maps
+
num_maps
);
oldrel
,
newrel
,
maps
+
num_maps
);
...
@@ -65,52 +63,36 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
...
@@ -65,52 +63,36 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
/*
/*
* So much for mapping this relation; now we need a mapping
* So much for mapping this relation; now we need a mapping
* for its corresponding toast relation, if any.
* for its corresponding toast relation
and toast index
, if any.
*/
*/
if
(
oldrel
->
toastrelid
>
0
)
if
(
oldrel
->
toastrelid
>
0
)
{
{
RelInfo
*
new_toast
;
char
old_name
[
MAXPGPATH
],
new_name
[
MAXPGPATH
];
RelInfo
*
old_toast
;
RelInfo
*
old_toast
,
*
new_toast
;
char
new_name
[
MAXPGPATH
];
char
old_name
[
MAXPGPATH
];
/* construct the new and old relnames for the toast relation */
snprintf
(
old_name
,
sizeof
(
old_name
),
"pg_toast_%u"
,
oldrel
->
reloid
);
snprintf
(
new_name
,
sizeof
(
new_name
),
"pg_toast_%u"
,
newrel
->
reloid
);
/* look them up in their respective arrays */
old_toast
=
relarr_lookup_rel_oid
(
&
old_cluster
,
&
old_db
->
rel_arr
,
old_toast
=
relarr_lookup_rel_oid
(
&
old_cluster
,
&
old_db
->
rel_arr
,
oldrel
->
toastrelid
);
oldrel
->
toastrelid
);
new_toast
=
relarr_lookup_rel_
name
(
&
new_cluster
,
&
new_db
->
rel_arr
,
new_toast
=
relarr_lookup_rel_
oid
(
&
new_cluster
,
&
new_db
->
rel_arr
,
"pg_toast"
,
new_name
);
newrel
->
toastrelid
);
/* finally create a mapping for them */
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
new_db
,
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
new_db
,
old_toast
,
new_toast
,
maps
+
num_maps
);
old_toast
,
new_toast
,
maps
+
num_maps
);
num_maps
++
;
num_maps
++
;
/*
/*
* also need to provide a mapping for the index of this toast
*
We
also need to provide a mapping for the index of this toast
* relation. The procedure is similar to what we did above for
* relation. The procedure is similar to what we did above for
* toast relation itself, the only difference being that the
* toast relation itself, the only difference being that the
* relnames need to be appended with _index.
* relnames need to be appended with _index.
*/
*/
/*
* construct the new and old relnames for the toast index
* relations
*/
snprintf
(
old_name
,
sizeof
(
old_name
),
"%s_index"
,
old_toast
->
relname
);
snprintf
(
old_name
,
sizeof
(
old_name
),
"%s_index"
,
old_toast
->
relname
);
snprintf
(
new_name
,
sizeof
(
new_name
),
"pg_toast_%u_index"
,
snprintf
(
new_name
,
sizeof
(
new_name
),
"%s_index"
,
new_toast
->
relname
);
newrel
->
reloid
);
/* look them up in their respective arrays */
old_toast
=
relarr_lookup_rel_name
(
&
old_cluster
,
&
old_db
->
rel_arr
,
old_toast
=
relarr_lookup_rel_name
(
&
old_cluster
,
&
old_db
->
rel_arr
,
"pg_toast"
,
old_name
);
"pg_toast"
,
old_name
);
new_toast
=
relarr_lookup_rel_name
(
&
new_cluster
,
&
new_db
->
rel_arr
,
new_toast
=
relarr_lookup_rel_name
(
&
new_cluster
,
&
new_db
->
rel_arr
,
"pg_toast"
,
new_name
);
"pg_toast"
,
new_name
);
/* finally create a mapping for them */
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
create_rel_filename_map
(
old_pgdata
,
new_pgdata
,
old_db
,
new_db
,
old_toast
,
new_toast
,
maps
+
num_maps
);
new_db
,
old_toast
,
new_toast
,
maps
+
num_maps
);
num_maps
++
;
num_maps
++
;
...
@@ -133,15 +115,6 @@ create_rel_filename_map(const char *old_data, const char *new_data,
...
@@ -133,15 +115,6 @@ create_rel_filename_map(const char *old_data, const char *new_data,
const
RelInfo
*
old_rel
,
const
RelInfo
*
new_rel
,
const
RelInfo
*
old_rel
,
const
RelInfo
*
new_rel
,
FileNameMap
*
map
)
FileNameMap
*
map
)
{
{
map
->
old_relfilenode
=
old_rel
->
relfilenode
;
map
->
new_relfilenode
=
new_rel
->
relfilenode
;
snprintf
(
map
->
old_nspname
,
sizeof
(
map
->
old_nspname
),
"%s"
,
old_rel
->
nspname
);
snprintf
(
map
->
new_nspname
,
sizeof
(
map
->
new_nspname
),
"%s"
,
new_rel
->
nspname
);
snprintf
(
map
->
old_relname
,
sizeof
(
map
->
old_relname
),
"%s"
,
old_rel
->
relname
);
snprintf
(
map
->
new_relname
,
sizeof
(
map
->
new_relname
),
"%s"
,
new_rel
->
relname
);
if
(
strlen
(
old_rel
->
tablespace
)
==
0
)
if
(
strlen
(
old_rel
->
tablespace
)
==
0
)
{
{
/*
/*
...
@@ -155,14 +128,21 @@ create_rel_filename_map(const char *old_data, const char *new_data,
...
@@ -155,14 +128,21 @@ create_rel_filename_map(const char *old_data, const char *new_data,
}
}
else
else
{
{
/*
/* relation belongs to a tablespace, so use the tablespace location */
* relation belongs to some tablespace, so use the tablespace location
*/
snprintf
(
map
->
old_dir
,
sizeof
(
map
->
old_dir
),
"%s%s/%u"
,
old_rel
->
tablespace
,
snprintf
(
map
->
old_dir
,
sizeof
(
map
->
old_dir
),
"%s%s/%u"
,
old_rel
->
tablespace
,
old_cluster
.
tablespace_suffix
,
old_db
->
db_oid
);
old_cluster
.
tablespace_suffix
,
old_db
->
db_oid
);
snprintf
(
map
->
new_dir
,
sizeof
(
map
->
new_dir
),
"%s%s/%u"
,
new_rel
->
tablespace
,
snprintf
(
map
->
new_dir
,
sizeof
(
map
->
new_dir
),
"%s%s/%u"
,
new_rel
->
tablespace
,
new_cluster
.
tablespace_suffix
,
new_db
->
db_oid
);
new_cluster
.
tablespace_suffix
,
new_db
->
db_oid
);
}
}
map
->
old_relfilenode
=
old_rel
->
relfilenode
;
map
->
new_relfilenode
=
new_rel
->
relfilenode
;
/* used only for logging and error reporing */
snprintf
(
map
->
old_nspname
,
sizeof
(
map
->
old_nspname
),
"%s"
,
old_rel
->
nspname
);
snprintf
(
map
->
new_nspname
,
sizeof
(
map
->
new_nspname
),
"%s"
,
new_rel
->
nspname
);
snprintf
(
map
->
old_relname
,
sizeof
(
map
->
old_relname
),
"%s"
,
old_rel
->
relname
);
snprintf
(
map
->
new_relname
,
sizeof
(
map
->
new_relname
),
"%s"
,
new_rel
->
relname
);
}
}
...
...
contrib/pg_upgrade/pg_upgrade.h
View file @
5cff5b57
...
@@ -87,12 +87,18 @@ typedef struct
...
@@ -87,12 +87,18 @@ typedef struct
{
{
char
old_dir
[
MAXPGPATH
];
char
old_dir
[
MAXPGPATH
];
char
new_dir
[
MAXPGPATH
];
char
new_dir
[
MAXPGPATH
];
Oid
old_relfilenode
;
/* Relfilenode of the old relation */
/*
Oid
new_relfilenode
;
/* Relfilenode of the new relation */
* old/new relfilenodes might differ for pg_largeobject(_metadata) indexes
char
old_nspname
[
NAMEDATALEN
];
/* old name of the namespace */
* due to VACUUM FULL or REINDEX. Other relfilenodes are preserved.
char
old_relname
[
NAMEDATALEN
];
/* old name of the relation */
*/
char
new_nspname
[
NAMEDATALEN
];
/* new name of the namespace */
Oid
old_relfilenode
;
char
new_relname
[
NAMEDATALEN
];
/* new name of the relation */
Oid
new_relfilenode
;
/* the rest are used only for logging and error reporting */
char
old_nspname
[
NAMEDATALEN
];
/* namespaces */
char
new_nspname
[
NAMEDATALEN
];
/* old/new relnames differ for toast tables and toast indexes */
char
old_relname
[
NAMEDATALEN
];
char
new_relname
[
NAMEDATALEN
];
}
FileNameMap
;
}
FileNameMap
;
/*
/*
...
...
contrib/pg_upgrade/version_old_8_3.c
View file @
5cff5b57
...
@@ -222,8 +222,8 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
...
@@ -222,8 +222,8 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
{
{
PGresult
*
res
;
PGresult
*
res
;
bool
db_used
=
false
;
bool
db_used
=
false
;
char
old_
nspname
[
NAMEDATALEN
]
=
""
,
char
nspname
[
NAMEDATALEN
]
=
""
,
old_
relname
[
NAMEDATALEN
]
=
""
;
relname
[
NAMEDATALEN
]
=
""
;
int
ntups
;
int
ntups
;
int
rowno
;
int
rowno
;
int
i_nspname
,
int
i_nspname
,
...
@@ -283,10 +283,10 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
...
@@ -283,10 +283,10 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
}
}
/* Rebuild all tsvector collumns with one ALTER TABLE command */
/* Rebuild all tsvector collumns with one ALTER TABLE command */
if
(
strcmp
(
PQgetvalue
(
res
,
rowno
,
i_nspname
),
old_
nspname
)
!=
0
||
if
(
strcmp
(
PQgetvalue
(
res
,
rowno
,
i_nspname
),
nspname
)
!=
0
||
strcmp
(
PQgetvalue
(
res
,
rowno
,
i_relname
),
old_
relname
)
!=
0
)
strcmp
(
PQgetvalue
(
res
,
rowno
,
i_relname
),
relname
)
!=
0
)
{
{
if
(
strlen
(
old_nspname
)
!=
0
||
strlen
(
old_
relname
)
!=
0
)
if
(
strlen
(
nspname
)
!=
0
||
strlen
(
relname
)
!=
0
)
fprintf
(
script
,
";
\n\n
"
);
fprintf
(
script
,
";
\n\n
"
);
fprintf
(
script
,
"ALTER TABLE %s.%s
\n
"
,
fprintf
(
script
,
"ALTER TABLE %s.%s
\n
"
,
quote_identifier
(
PQgetvalue
(
res
,
rowno
,
i_nspname
)),
quote_identifier
(
PQgetvalue
(
res
,
rowno
,
i_nspname
)),
...
@@ -294,8 +294,8 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
...
@@ -294,8 +294,8 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
}
}
else
else
fprintf
(
script
,
",
\n
"
);
fprintf
(
script
,
",
\n
"
);
strlcpy
(
old_nspname
,
PQgetvalue
(
res
,
rowno
,
i_nspname
),
sizeof
(
old_
nspname
));
strlcpy
(
nspname
,
PQgetvalue
(
res
,
rowno
,
i_nspname
),
sizeof
(
nspname
));
strlcpy
(
old_relname
,
PQgetvalue
(
res
,
rowno
,
i_relname
),
sizeof
(
old_
relname
));
strlcpy
(
relname
,
PQgetvalue
(
res
,
rowno
,
i_relname
),
sizeof
(
relname
));
fprintf
(
script
,
"ALTER COLUMN %s "
fprintf
(
script
,
"ALTER COLUMN %s "
/* This could have been a custom conversion function call. */
/* This could have been a custom conversion function call. */
...
@@ -304,7 +304,7 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
...
@@ -304,7 +304,7 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
quote_identifier
(
PQgetvalue
(
res
,
rowno
,
i_attname
)));
quote_identifier
(
PQgetvalue
(
res
,
rowno
,
i_attname
)));
}
}
}
}
if
(
strlen
(
old_nspname
)
!=
0
||
strlen
(
old_
relname
)
!=
0
)
if
(
strlen
(
nspname
)
!=
0
||
strlen
(
relname
)
!=
0
)
fprintf
(
script
,
";
\n\n
"
);
fprintf
(
script
,
";
\n\n
"
);
PQclear
(
res
);
PQclear
(
res
);
...
...
src/bin/pg_dump/pg_dump.c
View file @
5cff5b57
...
@@ -2354,34 +2354,37 @@ binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
...
@@ -2354,34 +2354,37 @@ binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
"
\n
-- For binary upgrade, must preserve relfilenodes
\n
"
);
"
\n
-- For binary upgrade, must preserve relfilenodes
\n
"
);
if
(
!
is_index
)
if
(
!
is_index
)
{
appendPQExpBuffer
(
upgrade_buffer
,
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_heap_relfilenode('%u'::pg_catalog.oid);
\n
"
,
"SELECT binary_upgrade.set_next_heap_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_relfilenode
);
pg_class_relfilenode
);
/* only tables have toast tables, not indexes */
if
(
OidIsValid
(
pg_class_reltoastrelid
))
{
/*
* One complexity is that the table definition might not require the
* creation of a TOAST table, and the TOAST table might have been
* created long after table creation, when the table was loaded with
* wide data. By setting the TOAST relfilenode we force creation of
* the TOAST heap and TOAST index by the backend so we can cleanly
* migrate the files during binary migration.
*/
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_toast_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_reltoastrelid
);
/* every toast table has an index */
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_reltoastidxid
);
}
}
else
else
appendPQExpBuffer
(
upgrade_buffer
,
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);
\n
"
,
"SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_relfilenode
);
pg_class_relfilenode
);
if
(
OidIsValid
(
pg_class_reltoastrelid
))
{
/*
* One complexity is that the table definition might not require the
* creation of a TOAST table, and the TOAST table might have been
* created long after table creation, when the table was loaded with
* wide data. By setting the TOAST relfilenode we force creation of
* the TOAST heap and TOAST index by the backend so we can cleanly
* migrate the files during binary migration.
*/
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_toast_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_reltoastrelid
);
/* every toast table has an index */
appendPQExpBuffer
(
upgrade_buffer
,
"SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);
\n
"
,
pg_class_reltoastidxid
);
}
appendPQExpBuffer
(
upgrade_buffer
,
"
\n
"
);
appendPQExpBuffer
(
upgrade_buffer
,
"
\n
"
);
PQclear
(
upgrade_res
);
PQclear
(
upgrade_res
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment