mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
pg_upgrade: prevent oid conflicts with new-cluster TOAST tables
Previously, TOAST tables only required in the new cluster could cause oid conflicts if they were auto-numbered and a later conflicting oid had to be assigned. Backpatch through 9.3
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "catalog/heap.h"
|
||||
#include "catalog/index.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/pg_authid.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_type.h"
|
||||
@ -39,6 +40,9 @@ static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
|
||||
Datum reloptions);
|
||||
static bool needs_toast_table(Relation rel);
|
||||
|
||||
/* pick a OID that will never be used for TOAST tables */
|
||||
#define OPTIONALLY_CREATE_TOAST_OID BOOTSTRAP_SUPERUSERID
|
||||
|
||||
|
||||
/*
|
||||
* AlterTableCreateToastTable
|
||||
@ -150,16 +154,51 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
|
||||
if (rel->rd_rel->reltoastrelid != InvalidOid)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Check to see whether the table actually needs a TOAST table.
|
||||
*
|
||||
* If an update-in-place toast relfilenode is specified, force toast file
|
||||
* creation even if it seems not to need one.
|
||||
*/
|
||||
if (!needs_toast_table(rel) &&
|
||||
(!IsBinaryUpgrade ||
|
||||
!OidIsValid(binary_upgrade_next_toast_pg_class_oid)))
|
||||
return false;
|
||||
if (!IsBinaryUpgrade)
|
||||
{
|
||||
if (!needs_toast_table(rel))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Check to see whether the table needs a TOAST table.
|
||||
*
|
||||
* If an update-in-place TOAST relfilenode is specified, force TOAST file
|
||||
* creation even if it seems not to need one. This handles the case
|
||||
* where the old cluster needed a TOAST table but the new cluster
|
||||
* would not normally create one.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If a TOAST oid is not specified, skip TOAST creation as we will do
|
||||
* it later so we don't create a TOAST table whose OID later conflicts
|
||||
* with a user-supplied OID. This handles cases where the old cluster
|
||||
* didn't need a TOAST table, but the new cluster does.
|
||||
*/
|
||||
if (!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* If a special TOAST value has been passed in, it means we are in
|
||||
* cleanup mode --- we are creating needed TOAST tables after all user
|
||||
* tables with specified OIDs have been created. We let the system
|
||||
* assign a TOAST oid for us. The tables are empty so the missing
|
||||
* TOAST tables were not a problem.
|
||||
*/
|
||||
if (binary_upgrade_next_toast_pg_class_oid == OPTIONALLY_CREATE_TOAST_OID)
|
||||
{
|
||||
/* clear as it is not to be used; it is just a flag */
|
||||
binary_upgrade_next_toast_pg_class_oid = InvalidOid;
|
||||
|
||||
if (!needs_toast_table(rel))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* both should be set, or not set */
|
||||
Assert(OidIsValid(binary_upgrade_next_toast_pg_class_oid) ==
|
||||
OidIsValid(binary_upgrade_next_toast_pg_type_oid));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the toast table and its index
|
||||
|
Reference in New Issue
Block a user