diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/catalog/heap.c | 2 | ||||
-rw-r--r-- | src/backend/catalog/index.c | 2 | ||||
-rw-r--r-- | src/backend/catalog/pg_enum.c | 2 | ||||
-rw-r--r-- | src/backend/catalog/pg_type.c | 2 | ||||
-rw-r--r-- | src/backend/catalog/toasting.c | 2 | ||||
-rw-r--r-- | src/backend/commands/typecmds.c | 2 | ||||
-rw-r--r-- | src/backend/commands/user.c | 2 | ||||
-rw-r--r-- | src/backend/utils/adt/Makefile | 3 | ||||
-rw-r--r-- | src/backend/utils/adt/pg_upgrade_support.c | 183 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 18 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 20 |
12 files changed, 222 insertions, 18 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index c518c50b21b..d04e94d74f3 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -76,7 +76,7 @@ #include "utils/tqual.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_heap_pg_class_oid = InvalidOid; Oid binary_upgrade_next_toast_pg_class_oid = InvalidOid; diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d8ff554387f..ac3b785b5a7 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -69,7 +69,7 @@ #include "utils/tqual.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_index_pg_class_oid = InvalidOid; /* state info for validate_index bulkdelete callback */ diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c index d87090a31b9..c880486c4bc 100644 --- a/src/backend/catalog/pg_enum.c +++ b/src/backend/catalog/pg_enum.c @@ -31,7 +31,7 @@ #include "utils/tqual.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_pg_enum_oid = InvalidOid; static void RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems); diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index d1ed53f5b4d..32453c3bb89 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -36,7 +36,7 @@ #include "utils/rel.h" #include "utils/syscache.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_pg_type_oid = InvalidOid; /* ---------------------------------------------------------------- diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index d14c33ce021..c99d3534ced 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -32,7 +32,7 @@ #include "utils/rel.h" #include "utils/syscache.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_toast_pg_type_oid = InvalidOid; static void CheckAndCreateToastTable(Oid relOid, Datum reloptions, diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 67e2ae22c68..907ba1100ac 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -80,7 +80,7 @@ typedef struct /* atts[] is of allocated length RelationGetNumberOfAttributes(rel) */ } RelToCheck; -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_array_pg_type_oid = InvalidOid; static void makeRangeConstructors(const char *name, Oid namespace, diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 75f1b3cd4f2..456c27ebe07 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -38,7 +38,7 @@ #include "utils/timestamp.h" #include "utils/tqual.h" -/* Potentially set by contrib/pg_upgrade_support functions */ +/* Potentially set by pg_upgrade_support functions */ Oid binary_upgrade_next_pg_authid_oid = InvalidOid; diff --git a/src/backend/utils/adt/Makefile b/src/backend/utils/adt/Makefile index 20e5ff10c7f..1f1bee7fb51 100644 --- a/src/backend/utils/adt/Makefile +++ b/src/backend/utils/adt/Makefile @@ -25,7 +25,8 @@ OBJS = acl.o arrayfuncs.o array_selfuncs.o array_typanalyze.o \ jsonfuncs.o like.o lockfuncs.o mac.o misc.o nabstime.o name.o \ network.o network_gist.o network_selfuncs.o \ numeric.o numutils.o oid.o oracle_compat.o \ - orderedsetaggs.o pg_locale.o pg_lsn.o pgstatfuncs.o \ + orderedsetaggs.o pg_locale.o pg_lsn.o pg_upgrade_support.o \ + pgstatfuncs.o \ pseudotypes.o quote.o rangetypes.o rangetypes_gist.o \ rangetypes_selfuncs.o rangetypes_spgist.o rangetypes_typanalyze.o \ regexp.o regproc.o ri_triggers.o rowtypes.o ruleutils.o \ diff --git a/src/backend/utils/adt/pg_upgrade_support.c b/src/backend/utils/adt/pg_upgrade_support.c new file mode 100644 index 00000000000..d69fa53567b --- /dev/null +++ b/src/backend/utils/adt/pg_upgrade_support.c @@ -0,0 +1,183 @@ +/* + * pg_upgrade_support.c + * + * server-side functions to set backend global variables + * to control oid and relfilenode assignment, and do other special + * hacks needed for pg_upgrade. + * + * Copyright (c) 2010-2015, PostgreSQL Global Development Group + * src/backend/utils/adt/pg_upgrade_support.c + */ + +#include "postgres.h" + +#include "catalog/binary_upgrade.h" +#include "catalog/namespace.h" +#include "catalog/pg_type.h" +#include "commands/extension.h" +#include "miscadmin.h" +#include "utils/array.h" +#include "utils/builtins.h" + + +Datum binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS); +Datum binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS); + + +#define CHECK_IS_BINARY_UPGRADE \ +do { \ + if (!IsBinaryUpgrade) \ + ereport(ERROR, \ + (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM), \ + (errmsg("function can only be called when server is in binary upgrade mode")))); \ +} while (0) + +Datum +binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS) +{ + Oid typoid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_pg_type_oid = typoid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS) +{ + Oid typoid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_array_pg_type_oid = typoid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS) +{ + Oid typoid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_toast_pg_type_oid = typoid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS) +{ + Oid reloid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_heap_pg_class_oid = reloid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS) +{ + Oid reloid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_index_pg_class_oid = reloid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS) +{ + Oid reloid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_toast_pg_class_oid = reloid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS) +{ + Oid enumoid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_pg_enum_oid = enumoid; + + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS) +{ + Oid authoid = PG_GETARG_OID(0); + + CHECK_IS_BINARY_UPGRADE; + binary_upgrade_next_pg_authid_oid = authoid; + PG_RETURN_VOID(); +} + +Datum +binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS) +{ + text *extName = PG_GETARG_TEXT_PP(0); + text *schemaName = PG_GETARG_TEXT_PP(1); + bool relocatable = PG_GETARG_BOOL(2); + text *extVersion = PG_GETARG_TEXT_PP(3); + Datum extConfig; + Datum extCondition; + List *requiredExtensions; + + CHECK_IS_BINARY_UPGRADE; + + if (PG_ARGISNULL(4)) + extConfig = PointerGetDatum(NULL); + else + extConfig = PG_GETARG_DATUM(4); + + if (PG_ARGISNULL(5)) + extCondition = PointerGetDatum(NULL); + else + extCondition = PG_GETARG_DATUM(5); + + requiredExtensions = NIL; + if (!PG_ARGISNULL(6)) + { + ArrayType *textArray = PG_GETARG_ARRAYTYPE_P(6); + Datum *textDatums; + int ndatums; + int i; + + deconstruct_array(textArray, + TEXTOID, -1, false, 'i', + &textDatums, NULL, &ndatums); + for (i = 0; i < ndatums; i++) + { + text *txtname = DatumGetTextPP(textDatums[i]); + char *extName = text_to_cstring(txtname); + Oid extOid = get_extension_oid(extName, false); + + requiredExtensions = lappend_oid(requiredExtensions, extOid); + } + } + + InsertExtensionTuple(text_to_cstring(extName), + GetUserId(), + get_namespace_oid(text_to_cstring(schemaName), false), + relocatable, + text_to_cstring(extVersion), + extConfig, + extCondition, + requiredExtensions); + + PG_RETURN_VOID(); +} diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 7da5c411949..fe08c1b15d2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -3045,7 +3045,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout, appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n"); appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n", + "SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n", pg_type_oid); /* we only support old >= 8.3 for binary upgrades */ @@ -3064,7 +3064,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout, appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type array oid\n"); appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n", + "SELECT pg_catalog.binary_upgrade_set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n", pg_type_array_oid); } @@ -3106,7 +3106,7 @@ binary_upgrade_set_type_oids_by_rel_oid(Archive *fout, appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n"); appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n", + "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n", pg_type_toast_oid); toast_set = true; @@ -3146,7 +3146,7 @@ binary_upgrade_set_pg_class_oids(Archive *fout, if (!is_index) { appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n", + "SELECT pg_catalog.binary_upgrade_set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n", pg_class_oid); /* only tables have toast tables, not indexes */ if (OidIsValid(pg_class_reltoastrelid)) @@ -3161,18 +3161,18 @@ binary_upgrade_set_pg_class_oids(Archive *fout, */ appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n", + "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n", pg_class_reltoastrelid); /* every toast table has an index */ appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n", + "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n", pg_index_indexrelid); } } else appendPQExpBuffer(upgrade_buffer, - "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n", + "SELECT pg_catalog.binary_upgrade_set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n", pg_class_oid); appendPQExpBufferChar(upgrade_buffer, '\n'); @@ -8352,7 +8352,7 @@ dumpExtension(Archive *fout, DumpOptions *dopt, ExtensionInfo *extinfo) appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname); appendPQExpBufferStr(q, - "SELECT binary_upgrade.create_empty_extension("); + "SELECT pg_catalog.binary_upgrade_create_empty_extension("); appendStringLiteralAH(q, extinfo->dobj.name, fout); appendPQExpBufferStr(q, ", "); appendStringLiteralAH(q, extinfo->namespace, fout); @@ -8530,7 +8530,7 @@ dumpEnumType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo) if (i == 0) appendPQExpBufferStr(q, "\n-- For binary upgrade, must preserve pg_enum oids\n"); appendPQExpBuffer(q, - "SELECT binary_upgrade.set_next_pg_enum_oid('%u'::pg_catalog.oid);\n", + "SELECT pg_catalog.binary_upgrade_set_next_pg_enum_oid('%u'::pg_catalog.oid);\n", enum_oid); appendPQExpBuffer(q, "ALTER TYPE %s.", fmtId(tyinfo->dobj.namespace->dobj.name)); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 6a7a6415f6e..7169ad09ccf 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -781,7 +781,7 @@ dumpRoles(PGconn *conn) { appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n"); appendPQExpBuffer(buf, - "SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n", + "SELECT pg_catalog.binary_upgrade_set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n", auth_oid); } diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 9caa0960d50..8469c82d27b 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -5181,6 +5181,26 @@ DESCR("rank of hypothetical row without gaps"); DATA(insert OID = 3993 ( dense_rank_final PGNSP PGUID 12 1 0 2276 0 f f f f f f i 2 0 20 "2281 2276" "{2281,2276}" "{i,v}" _null_ _null_ hypothetical_dense_rank_final _null_ _null_ _null_ )); DESCR("aggregate final function"); +/* pg_upgrade support */ +DATA(insert OID = 3582 ( binary_upgrade_set_next_pg_type_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_pg_type_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3584 ( binary_upgrade_set_next_array_pg_type_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_array_pg_type_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3585 ( binary_upgrade_set_next_toast_pg_type_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_toast_pg_type_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3586 ( binary_upgrade_set_next_heap_pg_class_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_heap_pg_class_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3587 ( binary_upgrade_set_next_index_pg_class_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_index_pg_class_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3588 ( binary_upgrade_set_next_toast_pg_class_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_toast_pg_class_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3589 ( binary_upgrade_set_next_pg_enum_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_pg_enum_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3590 ( binary_upgrade_set_next_pg_authid_oid PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 2278 "26" _null_ _null_ _null_ _null_ binary_upgrade_set_next_pg_authid_oid _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); +DATA(insert OID = 3591 ( binary_upgrade_create_empty_extension PGNSP PGUID 12 1 0 0 0 f f f f t f v 7 0 2278 "25 25 16 25 1028 1009 1009" _null_ _null_ _null_ _null_ binary_upgrade_create_empty_extension _null_ _null_ _null_ )); +DESCR("for use by pg_upgrade"); + /* * Symbolic values for provolatile column: these indicate whether the result |