Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2896c87

Browse files
committed
Force pg_upgrade's to preserve pg_class.oid, not pg_class.relfilenode.
Toast tables have identical pg_class.oid and pg_class.relfilenode, butfor clarity it is good to preserve the pg_class.oid.Update comments regarding what is preserved, and do somevariable/function renaming for clarity.
1 parent541fc3d commit2896c87

File tree

10 files changed

+112
-106
lines changed

10 files changed

+112
-106
lines changed

‎contrib/pg_upgrade/function.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@ install_support_functions(void)
4949
"LANGUAGE C STRICT;"));
5050
PQclear(executeQueryOrDie(conn,
5151
"CREATE OR REPLACE FUNCTION "
52-
"binary_upgrade.set_next_pg_type_array_oid(OID) "
52+
"binary_upgrade.set_next_array_pg_type_oid(OID) "
5353
"RETURNS VOID "
5454
"AS '$libdir/pg_upgrade_support' "
5555
"LANGUAGE C STRICT;"));
5656
PQclear(executeQueryOrDie(conn,
5757
"CREATE OR REPLACE FUNCTION "
58-
"binary_upgrade.set_next_pg_type_toast_oid(OID) "
58+
"binary_upgrade.set_next_toast_pg_type_oid(OID) "
5959
"RETURNS VOID "
6060
"AS '$libdir/pg_upgrade_support' "
6161
"LANGUAGE C STRICT;"));
6262
PQclear(executeQueryOrDie(conn,
6363
"CREATE OR REPLACE FUNCTION "
64-
"binary_upgrade.set_next_heap_relfilenode(OID) "
64+
"binary_upgrade.set_next_heap_pg_class_oid(OID) "
6565
"RETURNS VOID "
6666
"AS '$libdir/pg_upgrade_support' "
6767
"LANGUAGE C STRICT;"));
6868
PQclear(executeQueryOrDie(conn,
6969
"CREATE OR REPLACE FUNCTION "
70-
"binary_upgrade.set_next_toast_relfilenode(OID) "
70+
"binary_upgrade.set_next_index_pg_class_oid(OID) "
7171
"RETURNS VOID "
7272
"AS '$libdir/pg_upgrade_support' "
7373
"LANGUAGE C STRICT;"));
7474
PQclear(executeQueryOrDie(conn,
7575
"CREATE OR REPLACE FUNCTION "
76-
"binary_upgrade.set_next_index_relfilenode(OID) "
76+
"binary_upgrade.set_next_toast_pg_class_oid(OID) "
7777
"RETURNS VOID "
7878
"AS '$libdir/pg_upgrade_support' "
7979
"LANGUAGE C STRICT;"));

‎contrib/pg_upgrade/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
266266

267267
/*
268268
* pg_largeobject contains user data that does not appear the pg_dumpall
269-
* --schema-only output, so we have toupgrade that system table heap and
269+
* --schema-only output, so we have tocopy that system table heap and
270270
* index. Ideally we could just get the relfilenode from template1 but
271271
* pg_largeobject_loid_pn_index's relfilenode can change if the table was
272272
* reindexed so we get the relfilenode for each database and upgrade it as

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@
88
*/
99

1010
/*
11-
*To simplify the upgrade process, we force certain systemitems to be
12-
*consistent between old and new clusters:
11+
*To simplify the upgrade process, we force certain systemvalues to be
12+
*identical between old and new clusters:
1313
*
14-
*We control all assignments of pg_class.relfilenode so we can keep the
15-
*same relfilenodes for old and new files. The only exception is
16-
*pg_largeobject, pg_largeobject_metadata, and its indexes, which can
17-
*change due to a cluster, reindex, or vacuum full. (We don't create
18-
*those so have no control over their oid/relfilenode values.)
14+
*We control all assignments of pg_class.oid (and relfilenode) so toast
15+
*oids are the same between old and new clusters. This is important
16+
*because toast oids are stored as toast pointers in user tables.
1917
*
20-
*While pg_class.oid and pg_class.relfilenode are intially the same, they
21-
*can diverge due to cluster, reindex, or vacuum full. The new cluster
22-
*will again have matching pg_class.relfilenodeand pg_class.oid values,
23-
*but based on the new relfilenode value,sothe old/new oids might
24-
*differ.
18+
*The only place where old/new relfilenode might not match is
19+
*pg_largeobject, pg_largeobject_metadata, and its indexes,
20+
*which can change theirrelfilenodevalues due to a cluster, reindex,
21+
*or vacuum full. (We don't create thosesohave no control over their
22+
*new relfilenode values.)
2523
*
26-
*We control all assignments of pg_type.oid because these are stored
27-
*in composite types.
24+
*FYI, while pg_class.oid and pg_class.relfilenode are intially the same
25+
*in a cluster, but they can diverge due to cluster, reindex, or vacuum
26+
*full. The new cluster will again have matching pg_class.relfilenode
27+
*and pg_class.oid values, but based on the old relfilenode value, so the
28+
*old/new oids might differ.
29+
*
30+
*We control all assignments of pg_type.oid because these oid are stored
31+
*in user composite type values.
32+
*
33+
*We control all assignments of pg_enum.oid because these oid are stored
34+
*in user tables as enum values.
2835
*/
2936

3037

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ typedef struct
6767
{
6868
charnspname[NAMEDATALEN];/* namespace name */
6969
charrelname[NAMEDATALEN];/* relation name */
70-
Oidreloid;/* relation oid */
71-
Oidrelfilenode;/* relation relfile node */
70+
Oidreloid;/* relation oid */
71+
Oidrelfilenode;/* relation relfile node */
7272
Oidtoastrelid;/* oid of the toast relation */
7373
chartablespace[MAXPGPATH];/* relations tablespace path */
7474
}RelInfo;

‎contrib/pg_upgrade_support/pg_upgrade_support.c

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,36 @@ PG_MODULE_MAGIC;
2121
#endif
2222

2323
externPGDLLIMPORTOidbinary_upgrade_next_pg_type_oid;
24-
externPGDLLIMPORTOidbinary_upgrade_next_pg_type_array_oid;
25-
externPGDLLIMPORTOidbinary_upgrade_next_pg_type_toast_oid;
26-
externPGDLLIMPORTOidbinary_upgrade_next_heap_relfilenode;
27-
externPGDLLIMPORTOidbinary_upgrade_next_toast_relfilenode;
28-
externPGDLLIMPORTOidbinary_upgrade_next_index_relfilenode;
24+
externPGDLLIMPORTOidbinary_upgrade_next_array_pg_type_oid;
25+
externPGDLLIMPORTOidbinary_upgrade_next_toast_pg_type_oid;
26+
27+
externPGDLLIMPORTOidbinary_upgrade_next_heap_pg_class_oid;
28+
externPGDLLIMPORTOidbinary_upgrade_next_index_pg_class_oid;
29+
externPGDLLIMPORTOidbinary_upgrade_next_toast_pg_class_oid;
30+
2931
externPGDLLIMPORTOidbinary_upgrade_next_pg_enum_oid;
3032

3133
Datumset_next_pg_type_oid(PG_FUNCTION_ARGS);
32-
Datumset_next_pg_type_array_oid(PG_FUNCTION_ARGS);
33-
Datumset_next_pg_type_toast_oid(PG_FUNCTION_ARGS);
34-
Datumset_next_heap_relfilenode(PG_FUNCTION_ARGS);
35-
Datumset_next_toast_relfilenode(PG_FUNCTION_ARGS);
36-
Datumset_next_index_relfilenode(PG_FUNCTION_ARGS);
34+
Datumset_next_array_pg_type_oid(PG_FUNCTION_ARGS);
35+
Datumset_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
36+
37+
Datumset_next_heap_pg_class_oid(PG_FUNCTION_ARGS);
38+
Datumset_next_index_pg_class_oid(PG_FUNCTION_ARGS);
39+
Datumset_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
40+
3741
Datumset_next_pg_enum_oid(PG_FUNCTION_ARGS);
3842

3943
PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
40-
PG_FUNCTION_INFO_V1(set_next_pg_type_array_oid);
41-
PG_FUNCTION_INFO_V1(set_next_pg_type_toast_oid);
42-
PG_FUNCTION_INFO_V1(set_next_heap_relfilenode);
43-
PG_FUNCTION_INFO_V1(set_next_toast_relfilenode);
44-
PG_FUNCTION_INFO_V1(set_next_index_relfilenode);
44+
PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid);
45+
PG_FUNCTION_INFO_V1(set_next_toast_pg_type_oid);
46+
47+
PG_FUNCTION_INFO_V1(set_next_heap_pg_class_oid);
48+
PG_FUNCTION_INFO_V1(set_next_index_pg_class_oid);
49+
PG_FUNCTION_INFO_V1(set_next_toast_pg_class_oid);
50+
4551
PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
4652

53+
4754
Datum
4855
set_next_pg_type_oid(PG_FUNCTION_ARGS)
4956
{
@@ -55,51 +62,51 @@ set_next_pg_type_oid(PG_FUNCTION_ARGS)
5562
}
5663

5764
Datum
58-
set_next_pg_type_array_oid(PG_FUNCTION_ARGS)
65+
set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
5966
{
6067
Oidtypoid=PG_GETARG_OID(0);
6168

62-
binary_upgrade_next_pg_type_array_oid=typoid;
69+
binary_upgrade_next_array_pg_type_oid=typoid;
6370

6471
PG_RETURN_VOID();
6572
}
6673

6774
Datum
68-
set_next_pg_type_toast_oid(PG_FUNCTION_ARGS)
75+
set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
6976
{
7077
Oidtypoid=PG_GETARG_OID(0);
7178

72-
binary_upgrade_next_pg_type_toast_oid=typoid;
79+
binary_upgrade_next_toast_pg_type_oid=typoid;
7380

7481
PG_RETURN_VOID();
7582
}
7683

7784
Datum
78-
set_next_heap_relfilenode(PG_FUNCTION_ARGS)
85+
set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
7986
{
80-
Oidrelfilenode=PG_GETARG_OID(0);
87+
Oidreloid=PG_GETARG_OID(0);
8188

82-
binary_upgrade_next_heap_relfilenode=relfilenode;
89+
binary_upgrade_next_heap_pg_class_oid=reloid;
8390

8491
PG_RETURN_VOID();
8592
}
8693

8794
Datum
88-
set_next_toast_relfilenode(PG_FUNCTION_ARGS)
95+
set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
8996
{
90-
Oidrelfilenode=PG_GETARG_OID(0);
97+
Oidreloid=PG_GETARG_OID(0);
9198

92-
binary_upgrade_next_toast_relfilenode=relfilenode;
99+
binary_upgrade_next_index_pg_class_oid=reloid;
93100

94101
PG_RETURN_VOID();
95102
}
96103

97104
Datum
98-
set_next_index_relfilenode(PG_FUNCTION_ARGS)
105+
set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
99106
{
100-
Oidrelfilenode=PG_GETARG_OID(0);
107+
Oidreloid=PG_GETARG_OID(0);
101108

102-
binary_upgrade_next_index_relfilenode=relfilenode;
109+
binary_upgrade_next_toast_pg_class_oid=reloid;
103110

104111
PG_RETURN_VOID();
105112
}

‎src/backend/catalog/heap.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474

7575

7676
/* Potentially set by contrib/pg_upgrade_support functions */
77-
Oidbinary_upgrade_next_heap_relfilenode=InvalidOid;
78-
Oidbinary_upgrade_next_toast_relfilenode=InvalidOid;
77+
Oidbinary_upgrade_next_heap_pg_class_oid=InvalidOid;
78+
Oidbinary_upgrade_next_toast_pg_class_oid=InvalidOid;
7979

8080
staticvoidAddNewRelationTuple(Relationpg_class_desc,
8181
Relationnew_rel_desc,
@@ -987,22 +987,22 @@ heap_create_with_catalog(const char *relname,
987987
if (!OidIsValid(relid))
988988
{
989989
/*
990-
*Use binary-upgrade override for pg_class.relfilenode/oid,
990+
*Use binary-upgrade override for pg_class.oid/relfilenode,
991991
*if supplied.
992992
*/
993-
if (OidIsValid(binary_upgrade_next_heap_relfilenode)&&
993+
if (OidIsValid(binary_upgrade_next_heap_pg_class_oid)&&
994994
(relkind==RELKIND_RELATION||relkind==RELKIND_SEQUENCE||
995995
relkind==RELKIND_VIEW||relkind==RELKIND_COMPOSITE_TYPE||
996996
relkind==RELKIND_FOREIGN_TABLE))
997997
{
998-
relid=binary_upgrade_next_heap_relfilenode;
999-
binary_upgrade_next_heap_relfilenode=InvalidOid;
998+
relid=binary_upgrade_next_heap_pg_class_oid;
999+
binary_upgrade_next_heap_pg_class_oid=InvalidOid;
10001000
}
1001-
elseif (OidIsValid(binary_upgrade_next_toast_relfilenode)&&
1001+
elseif (OidIsValid(binary_upgrade_next_toast_pg_class_oid)&&
10021002
relkind==RELKIND_TOASTVALUE)
10031003
{
1004-
relid=binary_upgrade_next_toast_relfilenode;
1005-
binary_upgrade_next_toast_relfilenode=InvalidOid;
1004+
relid=binary_upgrade_next_toast_pg_class_oid;
1005+
binary_upgrade_next_toast_pg_class_oid=InvalidOid;
10061006
}
10071007
else
10081008
relid=GetNewRelFileNode(reltablespace,pg_class_desc,

‎src/backend/catalog/index.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070

7171
/* Potentially set by contrib/pg_upgrade_support functions */
72-
Oidbinary_upgrade_next_index_relfilenode=InvalidOid;
72+
Oidbinary_upgrade_next_index_pg_class_oid=InvalidOid;
7373

7474
/* state info for validate_index bulkdelete callback */
7575
typedefstruct
@@ -641,13 +641,13 @@ index_create(Oid heapRelationId,
641641
if (!OidIsValid(indexRelationId))
642642
{
643643
/*
644-
*Use binary-upgrade override for pg_class.relfilenode/oid,
644+
*Use binary-upgrade override for pg_class.oid/relfilenode,
645645
*if supplied.
646646
*/
647-
if (OidIsValid(binary_upgrade_next_index_relfilenode))
647+
if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
648648
{
649-
indexRelationId=binary_upgrade_next_index_relfilenode;
650-
binary_upgrade_next_index_relfilenode=InvalidOid;
649+
indexRelationId=binary_upgrade_next_index_pg_class_oid;
650+
binary_upgrade_next_index_pg_class_oid=InvalidOid;
651651
}
652652
else
653653
{

‎src/backend/catalog/toasting.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
#include"utils/syscache.h"
3333

3434
/* Potentially set by contrib/pg_upgrade_support functions */
35-
externOidbinary_upgrade_next_toast_relfilenode;
35+
externOidbinary_upgrade_next_toast_pg_class_oid;
3636

37-
Oidbinary_upgrade_next_pg_type_toast_oid=InvalidOid;
37+
Oidbinary_upgrade_next_toast_pg_type_oid=InvalidOid;
3838

3939
staticboolcreate_toast_table(Relationrel,OidtoastOid,OidtoastIndexOid,
4040
Datumreloptions);
@@ -156,7 +156,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
156156
* creation even if it seems not to need one.
157157
*/
158158
if (!needs_toast_table(rel)&&
159-
!OidIsValid(binary_upgrade_next_toast_relfilenode))
159+
!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
160160
return false;
161161

162162
/*
@@ -201,10 +201,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
201201
namespaceid=PG_TOAST_NAMESPACE;
202202

203203
/* Use binary-upgrade override for pg_type.oid, if supplied. */
204-
if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
204+
if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
205205
{
206-
toast_typid=binary_upgrade_next_pg_type_toast_oid;
207-
binary_upgrade_next_pg_type_toast_oid=InvalidOid;
206+
toast_typid=binary_upgrade_next_toast_pg_type_oid;
207+
binary_upgrade_next_toast_pg_type_oid=InvalidOid;
208208
}
209209

210210
toast_relid=heap_create_with_catalog(toast_relname,

‎src/backend/commands/typecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef struct
7575
}RelToCheck;
7676

7777
/* Potentially set by contrib/pg_upgrade_support functions */
78-
Oidbinary_upgrade_next_pg_type_array_oid=InvalidOid;
78+
Oidbinary_upgrade_next_array_pg_type_oid=InvalidOid;
7979

8080
staticOidfindTypeInputFunction(List*procname,OidtypeOid);
8181
staticOidfindTypeOutputFunction(List*procname,OidtypeOid);
@@ -1519,10 +1519,10 @@ AssignTypeArrayOid(void)
15191519
Oidtype_array_oid;
15201520

15211521
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
1522-
if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
1522+
if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
15231523
{
1524-
type_array_oid=binary_upgrade_next_pg_type_array_oid;
1525-
binary_upgrade_next_pg_type_array_oid=InvalidOid;
1524+
type_array_oid=binary_upgrade_next_array_pg_type_oid;
1525+
binary_upgrade_next_array_pg_type_oid=InvalidOid;
15261526
}
15271527
else
15281528
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp