1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/*
* 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-2011, PostgreSQL Global Development Group
* contrib/pg_upgrade_support/pg_upgrade_support.c
*/
#include "postgres.h"
#include "fmgr.h"
#include "catalog/dependency.h"
#include "catalog/namespace.h"
#include "catalog/pg_class.h"
#include "catalog/pg_type.h"
#include "commands/extension.h"
#include "miscadmin.h"
#include "utils/array.h"
#include "utils/builtins.h"
/* THIS IS USED ONLY FOR PG >= 9.0 */
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_array_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_type_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_oid;
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_authid_oid;
Datum set_next_pg_type_oid(PG_FUNCTION_ARGS);
Datum set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
Datum set_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
Datum set_next_heap_pg_class_oid(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_authid_oid(PG_FUNCTION_ARGS);
Datum create_empty_extension(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid);
PG_FUNCTION_INFO_V1(set_next_toast_pg_type_oid);
PG_FUNCTION_INFO_V1(set_next_heap_pg_class_oid);
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_authid_oid);
PG_FUNCTION_INFO_V1(create_empty_extension);
Datum
set_next_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
binary_upgrade_next_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
binary_upgrade_next_array_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
binary_upgrade_next_toast_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
binary_upgrade_next_heap_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
binary_upgrade_next_index_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
{
Oid reloid = PG_GETARG_OID(0);
binary_upgrade_next_toast_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
set_next_pg_enum_oid(PG_FUNCTION_ARGS)
{
Oid enumoid = PG_GETARG_OID(0);
binary_upgrade_next_pg_enum_oid = enumoid;
PG_RETURN_VOID();
}
Datum
set_next_pg_authid_oid(PG_FUNCTION_ARGS)
{
Oid authoid = PG_GETARG_OID(0);
binary_upgrade_next_pg_authid_oid = authoid;
PG_RETURN_VOID();
}
Datum
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;
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();
}
|