mirror of
https://github.com/postgres/postgres.git
synced 2025-05-20 00:03:14 -04:00
Force pg_upgrade's to preserve pg_class.oid, not pg_class.relfilenode.
Toast tables have identical pg_class.oid and pg_class.relfilenode, but for clarity it is good to preserve the pg_class.oid. Update comments regarding what is preserved, and do some variable/function renaming for clarity.
This commit is contained in:
parent
541fc3d4df
commit
2896c87ce4
@ -49,31 +49,31 @@ install_support_functions(void)
|
|||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
PQclear(executeQueryOrDie(conn,
|
PQclear(executeQueryOrDie(conn,
|
||||||
"CREATE OR REPLACE FUNCTION "
|
"CREATE OR REPLACE FUNCTION "
|
||||||
" binary_upgrade.set_next_pg_type_array_oid(OID) "
|
" binary_upgrade.set_next_array_pg_type_oid(OID) "
|
||||||
"RETURNS VOID "
|
"RETURNS VOID "
|
||||||
"AS '$libdir/pg_upgrade_support' "
|
"AS '$libdir/pg_upgrade_support' "
|
||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
PQclear(executeQueryOrDie(conn,
|
PQclear(executeQueryOrDie(conn,
|
||||||
"CREATE OR REPLACE FUNCTION "
|
"CREATE OR REPLACE FUNCTION "
|
||||||
" binary_upgrade.set_next_pg_type_toast_oid(OID) "
|
" binary_upgrade.set_next_toast_pg_type_oid(OID) "
|
||||||
"RETURNS VOID "
|
"RETURNS VOID "
|
||||||
"AS '$libdir/pg_upgrade_support' "
|
"AS '$libdir/pg_upgrade_support' "
|
||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
PQclear(executeQueryOrDie(conn,
|
PQclear(executeQueryOrDie(conn,
|
||||||
"CREATE OR REPLACE FUNCTION "
|
"CREATE OR REPLACE FUNCTION "
|
||||||
" binary_upgrade.set_next_heap_relfilenode(OID) "
|
" binary_upgrade.set_next_heap_pg_class_oid(OID) "
|
||||||
"RETURNS VOID "
|
"RETURNS VOID "
|
||||||
"AS '$libdir/pg_upgrade_support' "
|
"AS '$libdir/pg_upgrade_support' "
|
||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
PQclear(executeQueryOrDie(conn,
|
PQclear(executeQueryOrDie(conn,
|
||||||
"CREATE OR REPLACE FUNCTION "
|
"CREATE OR REPLACE FUNCTION "
|
||||||
" binary_upgrade.set_next_toast_relfilenode(OID) "
|
" binary_upgrade.set_next_index_pg_class_oid(OID) "
|
||||||
"RETURNS VOID "
|
"RETURNS VOID "
|
||||||
"AS '$libdir/pg_upgrade_support' "
|
"AS '$libdir/pg_upgrade_support' "
|
||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
PQclear(executeQueryOrDie(conn,
|
PQclear(executeQueryOrDie(conn,
|
||||||
"CREATE OR REPLACE FUNCTION "
|
"CREATE OR REPLACE FUNCTION "
|
||||||
" binary_upgrade.set_next_index_relfilenode(OID) "
|
" binary_upgrade.set_next_toast_pg_class_oid(OID) "
|
||||||
"RETURNS VOID "
|
"RETURNS VOID "
|
||||||
"AS '$libdir/pg_upgrade_support' "
|
"AS '$libdir/pg_upgrade_support' "
|
||||||
"LANGUAGE C STRICT;"));
|
"LANGUAGE C STRICT;"));
|
||||||
|
@ -266,7 +266,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* pg_largeobject contains user data that does not appear the pg_dumpall
|
* pg_largeobject contains user data that does not appear the pg_dumpall
|
||||||
* --schema-only output, so we have to upgrade that system table heap and
|
* --schema-only output, so we have to copy that system table heap and
|
||||||
* index. Ideally we could just get the relfilenode from template1 but
|
* index. Ideally we could just get the relfilenode from template1 but
|
||||||
* pg_largeobject_loid_pn_index's relfilenode can change if the table was
|
* pg_largeobject_loid_pn_index's relfilenode can change if the table was
|
||||||
* reindexed so we get the relfilenode for each database and upgrade it as
|
* reindexed so we get the relfilenode for each database and upgrade it as
|
||||||
|
@ -8,23 +8,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To simplify the upgrade process, we force certain system items to be
|
* To simplify the upgrade process, we force certain system values to be
|
||||||
* consistent between old and new clusters:
|
* identical between old and new clusters:
|
||||||
*
|
*
|
||||||
* We control all assignments of pg_class.relfilenode so we can keep the
|
* We control all assignments of pg_class.oid (and relfilenode) so toast
|
||||||
* same relfilenodes for old and new files. The only exception is
|
* oids are the same between old and new clusters. This is important
|
||||||
* pg_largeobject, pg_largeobject_metadata, and its indexes, which can
|
* because toast oids are stored as toast pointers in user tables.
|
||||||
* change due to a cluster, reindex, or vacuum full. (We don't create
|
|
||||||
* those so have no control over their oid/relfilenode values.)
|
|
||||||
*
|
*
|
||||||
* While pg_class.oid and pg_class.relfilenode are intially the same, they
|
* The only place where old/new relfilenode might not match is
|
||||||
* can diverge due to cluster, reindex, or vacuum full. The new cluster
|
* pg_largeobject, pg_largeobject_metadata, and its indexes,
|
||||||
* will again have matching pg_class.relfilenode and pg_class.oid values,
|
* which can change their relfilenode values due to a cluster, reindex,
|
||||||
* but based on the new relfilenode value, so the old/new oids might
|
* or vacuum full. (We don't create those so have no control over their
|
||||||
* differ.
|
* new relfilenode values.)
|
||||||
*
|
*
|
||||||
* We control all assignments of pg_type.oid because these are stored
|
* FYI, while pg_class.oid and pg_class.relfilenode are intially the same
|
||||||
* in composite types.
|
* in a cluster, but they can diverge due to cluster, reindex, or vacuum
|
||||||
|
* full. The new cluster will again have matching pg_class.relfilenode
|
||||||
|
* and pg_class.oid values, but based on the old relfilenode value, so the
|
||||||
|
* old/new oids might differ.
|
||||||
|
*
|
||||||
|
* We control all assignments of pg_type.oid because these oid are stored
|
||||||
|
* in user composite type values.
|
||||||
|
*
|
||||||
|
* We control all assignments of pg_enum.oid because these oid are stored
|
||||||
|
* in user tables as enum values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ typedef struct
|
|||||||
{
|
{
|
||||||
char nspname[NAMEDATALEN]; /* namespace name */
|
char nspname[NAMEDATALEN]; /* namespace name */
|
||||||
char relname[NAMEDATALEN]; /* relation name */
|
char relname[NAMEDATALEN]; /* relation name */
|
||||||
Oid reloid; /* relation oid */
|
Oid reloid; /* relation oid */
|
||||||
Oid relfilenode; /* relation relfile node */
|
Oid relfilenode; /* relation relfile node */
|
||||||
Oid toastrelid; /* oid of the toast relation */
|
Oid toastrelid; /* oid of the toast relation */
|
||||||
char tablespace[MAXPGPATH]; /* relations tablespace path */
|
char tablespace[MAXPGPATH]; /* relations tablespace path */
|
||||||
} RelInfo;
|
} RelInfo;
|
||||||
|
@ -21,29 +21,36 @@ PG_MODULE_MAGIC;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
|
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_array_oid;
|
extern PGDLLIMPORT Oid binary_upgrade_next_array_pg_type_oid;
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_toast_oid;
|
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_type_oid;
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_heap_relfilenode;
|
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_toast_relfilenode;
|
extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_oid;
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_index_relfilenode;
|
extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_oid;
|
||||||
|
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid;
|
||||||
|
|
||||||
extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
|
extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
|
||||||
|
|
||||||
Datum set_next_pg_type_oid(PG_FUNCTION_ARGS);
|
Datum set_next_pg_type_oid(PG_FUNCTION_ARGS);
|
||||||
Datum set_next_pg_type_array_oid(PG_FUNCTION_ARGS);
|
Datum set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
|
||||||
Datum set_next_pg_type_toast_oid(PG_FUNCTION_ARGS);
|
Datum set_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
|
||||||
Datum set_next_heap_relfilenode(PG_FUNCTION_ARGS);
|
|
||||||
Datum set_next_toast_relfilenode(PG_FUNCTION_ARGS);
|
Datum set_next_heap_pg_class_oid(PG_FUNCTION_ARGS);
|
||||||
Datum set_next_index_relfilenode(PG_FUNCTION_ARGS);
|
Datum set_next_index_pg_class_oid(PG_FUNCTION_ARGS);
|
||||||
|
Datum set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
Datum set_next_pg_enum_oid(PG_FUNCTION_ARGS);
|
Datum set_next_pg_enum_oid(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
|
PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
|
||||||
PG_FUNCTION_INFO_V1(set_next_pg_type_array_oid);
|
PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid);
|
||||||
PG_FUNCTION_INFO_V1(set_next_pg_type_toast_oid);
|
PG_FUNCTION_INFO_V1(set_next_toast_pg_type_oid);
|
||||||
PG_FUNCTION_INFO_V1(set_next_heap_relfilenode);
|
|
||||||
PG_FUNCTION_INFO_V1(set_next_toast_relfilenode);
|
PG_FUNCTION_INFO_V1(set_next_heap_pg_class_oid);
|
||||||
PG_FUNCTION_INFO_V1(set_next_index_relfilenode);
|
PG_FUNCTION_INFO_V1(set_next_index_pg_class_oid);
|
||||||
|
PG_FUNCTION_INFO_V1(set_next_toast_pg_class_oid);
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
|
PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
|
||||||
|
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_pg_type_oid(PG_FUNCTION_ARGS)
|
set_next_pg_type_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
@ -55,51 +62,51 @@ set_next_pg_type_oid(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_pg_type_array_oid(PG_FUNCTION_ARGS)
|
set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid typoid = PG_GETARG_OID(0);
|
Oid typoid = PG_GETARG_OID(0);
|
||||||
|
|
||||||
binary_upgrade_next_pg_type_array_oid = typoid;
|
binary_upgrade_next_array_pg_type_oid = typoid;
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_pg_type_toast_oid(PG_FUNCTION_ARGS)
|
set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid typoid = PG_GETARG_OID(0);
|
Oid typoid = PG_GETARG_OID(0);
|
||||||
|
|
||||||
binary_upgrade_next_pg_type_toast_oid = typoid;
|
binary_upgrade_next_toast_pg_type_oid = typoid;
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_heap_relfilenode(PG_FUNCTION_ARGS)
|
set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid relfilenode = PG_GETARG_OID(0);
|
Oid reloid = PG_GETARG_OID(0);
|
||||||
|
|
||||||
binary_upgrade_next_heap_relfilenode = relfilenode;
|
binary_upgrade_next_heap_pg_class_oid = reloid;
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_toast_relfilenode(PG_FUNCTION_ARGS)
|
set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid relfilenode = PG_GETARG_OID(0);
|
Oid reloid = PG_GETARG_OID(0);
|
||||||
|
|
||||||
binary_upgrade_next_toast_relfilenode = relfilenode;
|
binary_upgrade_next_index_pg_class_oid = reloid;
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
Datum
|
Datum
|
||||||
set_next_index_relfilenode(PG_FUNCTION_ARGS)
|
set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
Oid relfilenode = PG_GETARG_OID(0);
|
Oid reloid = PG_GETARG_OID(0);
|
||||||
|
|
||||||
binary_upgrade_next_index_relfilenode = relfilenode;
|
binary_upgrade_next_toast_pg_class_oid = reloid;
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Potentially set by contrib/pg_upgrade_support functions */
|
/* Potentially set by contrib/pg_upgrade_support functions */
|
||||||
Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
|
Oid binary_upgrade_next_heap_pg_class_oid = InvalidOid;
|
||||||
Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
|
Oid binary_upgrade_next_toast_pg_class_oid = InvalidOid;
|
||||||
|
|
||||||
static void AddNewRelationTuple(Relation pg_class_desc,
|
static void AddNewRelationTuple(Relation pg_class_desc,
|
||||||
Relation new_rel_desc,
|
Relation new_rel_desc,
|
||||||
@ -987,22 +987,22 @@ heap_create_with_catalog(const char *relname,
|
|||||||
if (!OidIsValid(relid))
|
if (!OidIsValid(relid))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Use binary-upgrade override for pg_class.relfilenode/oid,
|
* Use binary-upgrade override for pg_class.oid/relfilenode,
|
||||||
* if supplied.
|
* if supplied.
|
||||||
*/
|
*/
|
||||||
if (OidIsValid(binary_upgrade_next_heap_relfilenode) &&
|
if (OidIsValid(binary_upgrade_next_heap_pg_class_oid) &&
|
||||||
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
|
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
|
||||||
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
|
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
|
||||||
relkind == RELKIND_FOREIGN_TABLE))
|
relkind == RELKIND_FOREIGN_TABLE))
|
||||||
{
|
{
|
||||||
relid = binary_upgrade_next_heap_relfilenode;
|
relid = binary_upgrade_next_heap_pg_class_oid;
|
||||||
binary_upgrade_next_heap_relfilenode = InvalidOid;
|
binary_upgrade_next_heap_pg_class_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
else if (OidIsValid(binary_upgrade_next_toast_relfilenode) &&
|
else if (OidIsValid(binary_upgrade_next_toast_pg_class_oid) &&
|
||||||
relkind == RELKIND_TOASTVALUE)
|
relkind == RELKIND_TOASTVALUE)
|
||||||
{
|
{
|
||||||
relid = binary_upgrade_next_toast_relfilenode;
|
relid = binary_upgrade_next_toast_pg_class_oid;
|
||||||
binary_upgrade_next_toast_relfilenode = InvalidOid;
|
binary_upgrade_next_toast_pg_class_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
relid = GetNewRelFileNode(reltablespace, pg_class_desc,
|
relid = GetNewRelFileNode(reltablespace, pg_class_desc,
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Potentially set by contrib/pg_upgrade_support functions */
|
/* Potentially set by contrib/pg_upgrade_support functions */
|
||||||
Oid binary_upgrade_next_index_relfilenode = InvalidOid;
|
Oid binary_upgrade_next_index_pg_class_oid = InvalidOid;
|
||||||
|
|
||||||
/* state info for validate_index bulkdelete callback */
|
/* state info for validate_index bulkdelete callback */
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -641,13 +641,13 @@ index_create(Oid heapRelationId,
|
|||||||
if (!OidIsValid(indexRelationId))
|
if (!OidIsValid(indexRelationId))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Use binary-upgrade override for pg_class.relfilenode/oid,
|
* Use binary-upgrade override for pg_class.oid/relfilenode,
|
||||||
* if supplied.
|
* if supplied.
|
||||||
*/
|
*/
|
||||||
if (OidIsValid(binary_upgrade_next_index_relfilenode))
|
if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
|
||||||
{
|
{
|
||||||
indexRelationId = binary_upgrade_next_index_relfilenode;
|
indexRelationId = binary_upgrade_next_index_pg_class_oid;
|
||||||
binary_upgrade_next_index_relfilenode = InvalidOid;
|
binary_upgrade_next_index_pg_class_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -32,9 +32,9 @@
|
|||||||
#include "utils/syscache.h"
|
#include "utils/syscache.h"
|
||||||
|
|
||||||
/* Potentially set by contrib/pg_upgrade_support functions */
|
/* Potentially set by contrib/pg_upgrade_support functions */
|
||||||
extern Oid binary_upgrade_next_toast_relfilenode;
|
extern Oid binary_upgrade_next_toast_pg_class_oid;
|
||||||
|
|
||||||
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
|
Oid binary_upgrade_next_toast_pg_type_oid = InvalidOid;
|
||||||
|
|
||||||
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
|
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
|
||||||
Datum reloptions);
|
Datum reloptions);
|
||||||
@ -156,7 +156,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
|
|||||||
* creation even if it seems not to need one.
|
* creation even if it seems not to need one.
|
||||||
*/
|
*/
|
||||||
if (!needs_toast_table(rel) &&
|
if (!needs_toast_table(rel) &&
|
||||||
!OidIsValid(binary_upgrade_next_toast_relfilenode))
|
!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -201,10 +201,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
|
|||||||
namespaceid = PG_TOAST_NAMESPACE;
|
namespaceid = PG_TOAST_NAMESPACE;
|
||||||
|
|
||||||
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
||||||
if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
|
if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
|
||||||
{
|
{
|
||||||
toast_typid = binary_upgrade_next_pg_type_toast_oid;
|
toast_typid = binary_upgrade_next_toast_pg_type_oid;
|
||||||
binary_upgrade_next_pg_type_toast_oid = InvalidOid;
|
binary_upgrade_next_toast_pg_type_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast_relid = heap_create_with_catalog(toast_relname,
|
toast_relid = heap_create_with_catalog(toast_relname,
|
||||||
|
@ -75,7 +75,7 @@ typedef struct
|
|||||||
} RelToCheck;
|
} RelToCheck;
|
||||||
|
|
||||||
/* Potentially set by contrib/pg_upgrade_support functions */
|
/* Potentially set by contrib/pg_upgrade_support functions */
|
||||||
Oid binary_upgrade_next_pg_type_array_oid = InvalidOid;
|
Oid binary_upgrade_next_array_pg_type_oid = InvalidOid;
|
||||||
|
|
||||||
static Oid findTypeInputFunction(List *procname, Oid typeOid);
|
static Oid findTypeInputFunction(List *procname, Oid typeOid);
|
||||||
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
|
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
|
||||||
@ -1519,10 +1519,10 @@ AssignTypeArrayOid(void)
|
|||||||
Oid type_array_oid;
|
Oid type_array_oid;
|
||||||
|
|
||||||
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
|
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
|
||||||
if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
|
if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
|
||||||
{
|
{
|
||||||
type_array_oid = binary_upgrade_next_pg_type_array_oid;
|
type_array_oid = binary_upgrade_next_array_pg_type_oid;
|
||||||
binary_upgrade_next_pg_type_array_oid = InvalidOid;
|
binary_upgrade_next_array_pg_type_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ static void binary_upgrade_set_type_oids_by_type_oid(
|
|||||||
PQExpBuffer upgrade_buffer, Oid pg_type_oid);
|
PQExpBuffer upgrade_buffer, Oid pg_type_oid);
|
||||||
static bool binary_upgrade_set_type_oids_by_rel_oid(
|
static bool binary_upgrade_set_type_oids_by_rel_oid(
|
||||||
PQExpBuffer upgrade_buffer, Oid pg_rel_oid);
|
PQExpBuffer upgrade_buffer, Oid pg_rel_oid);
|
||||||
static void binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer,
|
static void binary_upgrade_set_pg_class_oids(PQExpBuffer upgrade_buffer,
|
||||||
Oid pg_class_oid, bool is_index);
|
Oid pg_class_oid, bool is_index);
|
||||||
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
|
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
|
||||||
static const char *fmtCopyColumnList(const TableInfo *ti);
|
static const char *fmtCopyColumnList(const TableInfo *ti);
|
||||||
@ -2243,7 +2243,7 @@ binary_upgrade_set_type_oids_by_type_oid(PQExpBuffer upgrade_buffer,
|
|||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"\n-- For binary upgrade, must preserve pg_type array oid\n");
|
"\n-- For binary upgrade, must preserve pg_type array oid\n");
|
||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"SELECT binary_upgrade.set_next_pg_type_array_oid('%u'::pg_catalog.oid);\n\n",
|
"SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
|
||||||
pg_type_array_oid);
|
pg_type_array_oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2296,7 +2296,7 @@ binary_upgrade_set_type_oids_by_rel_oid(PQExpBuffer upgrade_buffer,
|
|||||||
|
|
||||||
appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
|
appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
|
||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"SELECT binary_upgrade.set_next_pg_type_toast_oid('%u'::pg_catalog.oid);\n\n",
|
"SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
|
||||||
pg_type_toast_oid);
|
pg_type_toast_oid);
|
||||||
|
|
||||||
toast_set = true;
|
toast_set = true;
|
||||||
@ -2309,24 +2309,17 @@ binary_upgrade_set_type_oids_by_rel_oid(PQExpBuffer upgrade_buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
|
binary_upgrade_set_pg_class_oids(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
|
||||||
bool is_index)
|
bool is_index)
|
||||||
{
|
{
|
||||||
PQExpBuffer upgrade_query = createPQExpBuffer();
|
PQExpBuffer upgrade_query = createPQExpBuffer();
|
||||||
int ntups;
|
int ntups;
|
||||||
PGresult *upgrade_res;
|
PGresult *upgrade_res;
|
||||||
Oid pg_class_relfilenode;
|
|
||||||
Oid pg_class_reltoastrelid;
|
Oid pg_class_reltoastrelid;
|
||||||
Oid pg_class_reltoastidxid;
|
Oid pg_class_reltoastidxid;
|
||||||
|
|
||||||
/*
|
|
||||||
* Note: we don't need to use pg_relation_filenode() here because this
|
|
||||||
* function is not intended to be used against system catalogs. Otherwise
|
|
||||||
* we'd have to worry about which versions pg_relation_filenode is
|
|
||||||
* available in.
|
|
||||||
*/
|
|
||||||
appendPQExpBuffer(upgrade_query,
|
appendPQExpBuffer(upgrade_query,
|
||||||
"SELECT c.relfilenode, c.reltoastrelid, t.reltoastidxid "
|
"SELECT c.reltoastrelid, t.reltoastidxid "
|
||||||
"FROM pg_catalog.pg_class c LEFT JOIN "
|
"FROM pg_catalog.pg_class c LEFT JOIN "
|
||||||
"pg_catalog.pg_class t ON (c.reltoastrelid = t.oid) "
|
"pg_catalog.pg_class t ON (c.reltoastrelid = t.oid) "
|
||||||
"WHERE c.oid = '%u'::pg_catalog.oid;",
|
"WHERE c.oid = '%u'::pg_catalog.oid;",
|
||||||
@ -2346,44 +2339,43 @@ binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
|
|||||||
exit_nicely();
|
exit_nicely();
|
||||||
}
|
}
|
||||||
|
|
||||||
pg_class_relfilenode = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "relfilenode")));
|
|
||||||
pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
|
pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
|
||||||
pg_class_reltoastidxid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastidxid")));
|
pg_class_reltoastidxid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastidxid")));
|
||||||
|
|
||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"\n-- For binary upgrade, must preserve relfilenodes\n");
|
"\n-- For binary upgrade, must preserve pg_class oids\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_pg_class_oid('%u'::pg_catalog.oid);\n",
|
||||||
pg_class_relfilenode);
|
pg_class_oid);
|
||||||
/* only tables have toast tables, not indexes */
|
/* only tables have toast tables, not indexes */
|
||||||
if (OidIsValid(pg_class_reltoastrelid))
|
if (OidIsValid(pg_class_reltoastrelid))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* One complexity is that the table definition might not require the
|
* One complexity is that the table definition might not require
|
||||||
* creation of a TOAST table, and the TOAST table might have been
|
* the creation of a TOAST table, and the TOAST table might have
|
||||||
* created long after table creation, when the table was loaded with
|
* been created long after table creation, when the table was
|
||||||
* wide data. By setting the TOAST relfilenode we force creation of
|
* loaded with wide data. By setting the TOAST oid we force
|
||||||
* the TOAST heap and TOAST index by the backend so we can cleanly
|
* creation of the TOAST heap and TOAST index by the backend
|
||||||
* migrate the files during binary migration.
|
* so we can cleanly copy the files during binary upgrade.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"SELECT binary_upgrade.set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
|
"SELECT binary_upgrade.set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
|
||||||
pg_class_reltoastrelid);
|
pg_class_reltoastrelid);
|
||||||
|
|
||||||
/* every toast table has an index */
|
/* every toast table has an index */
|
||||||
appendPQExpBuffer(upgrade_buffer,
|
appendPQExpBuffer(upgrade_buffer,
|
||||||
"SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
|
"SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
|
||||||
pg_class_reltoastidxid);
|
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_pg_class_oid('%u'::pg_catalog.oid);\n",
|
||||||
pg_class_relfilenode);
|
pg_class_oid);
|
||||||
|
|
||||||
appendPQExpBuffer(upgrade_buffer, "\n");
|
appendPQExpBuffer(upgrade_buffer, "\n");
|
||||||
|
|
||||||
@ -7364,7 +7356,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
|
|||||||
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
|
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
|
||||||
|
|
||||||
binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
|
binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
|
||||||
binary_upgrade_set_relfilenodes(q, typrelid, false);
|
binary_upgrade_set_pg_class_oids(q, typrelid, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPQExpBuffer(q, "CREATE TYPE %s AS (",
|
appendPQExpBuffer(q, "CREATE TYPE %s AS (",
|
||||||
@ -11083,7 +11075,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
|
|||||||
fmtId(tbinfo->dobj.name));
|
fmtId(tbinfo->dobj.name));
|
||||||
|
|
||||||
if (binary_upgrade)
|
if (binary_upgrade)
|
||||||
binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
|
binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
|
||||||
|
|
||||||
appendPQExpBuffer(q, "CREATE VIEW %s AS\n %s\n",
|
appendPQExpBuffer(q, "CREATE VIEW %s AS\n %s\n",
|
||||||
fmtId(tbinfo->dobj.name), viewdef);
|
fmtId(tbinfo->dobj.name), viewdef);
|
||||||
@ -11134,7 +11126,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
|
|||||||
fmtId(tbinfo->dobj.name));
|
fmtId(tbinfo->dobj.name));
|
||||||
|
|
||||||
if (binary_upgrade)
|
if (binary_upgrade)
|
||||||
binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
|
binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
|
||||||
|
|
||||||
appendPQExpBuffer(q, "CREATE %s%s %s",
|
appendPQExpBuffer(q, "CREATE %s%s %s",
|
||||||
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
|
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
|
||||||
@ -11616,7 +11608,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
|
|||||||
if (indxinfo->indexconstraint == 0)
|
if (indxinfo->indexconstraint == 0)
|
||||||
{
|
{
|
||||||
if (binary_upgrade)
|
if (binary_upgrade)
|
||||||
binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
|
binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
|
||||||
|
|
||||||
/* Plain secondary index */
|
/* Plain secondary index */
|
||||||
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
|
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
|
||||||
@ -11699,7 +11691,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (binary_upgrade && !coninfo->condef)
|
if (binary_upgrade && !coninfo->condef)
|
||||||
binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
|
binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
|
||||||
|
|
||||||
appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
|
appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
|
||||||
fmtId(tbinfo->dobj.name));
|
fmtId(tbinfo->dobj.name));
|
||||||
@ -12112,7 +12104,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
|
|||||||
|
|
||||||
if (binary_upgrade)
|
if (binary_upgrade)
|
||||||
{
|
{
|
||||||
binary_upgrade_set_relfilenodes(query, tbinfo->dobj.catId.oid, false);
|
binary_upgrade_set_pg_class_oids(query, tbinfo->dobj.catId.oid, false);
|
||||||
binary_upgrade_set_type_oids_by_rel_oid(query, tbinfo->dobj.catId.oid);
|
binary_upgrade_set_type_oids_by_rel_oid(query, tbinfo->dobj.catId.oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user