2010-05-12 04:19:11 +02:00
|
|
|
/*
|
2011-02-10 01:17:33 +01:00
|
|
|
* pg_upgrade_support.c
|
2010-05-12 04:19:11 +02:00
|
|
|
*
|
|
|
|
* server-side functions to set backend global variables
|
2011-02-10 01:17:33 +01:00
|
|
|
* to control oid and relfilenode assignment, and do other special
|
|
|
|
* hacks needed for pg_upgrade.
|
2010-07-03 16:23:14 +02:00
|
|
|
*
|
2019-01-02 18:44:25 +01:00
|
|
|
* Copyright (c) 2010-2019, PostgreSQL Global Development Group
|
2015-03-11 03:33:25 +01:00
|
|
|
* src/backend/utils/adt/pg_upgrade_support.c
|
2010-05-12 04:19:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2013-12-19 22:10:01 +01:00
|
|
|
#include "catalog/binary_upgrade.h"
|
2018-06-22 14:42:36 +02:00
|
|
|
#include "catalog/heap.h"
|
2011-02-10 01:17:33 +01:00
|
|
|
#include "catalog/namespace.h"
|
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "commands/extension.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "utils/array.h"
|
|
|
|
#include "utils/builtins.h"
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
|
2015-05-24 03:35:49 +02:00
|
|
|
#define CHECK_IS_BINARY_UPGRADE \
|
|
|
|
do { \
|
2014-08-26 04:19:05 +02:00
|
|
|
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)
|
2011-01-08 03:25:34 +01:00
|
|
|
|
2010-05-12 04:19:11 +02:00
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_pg_type_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
Oid typoid = PG_GETARG_OID(0);
|
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2010-05-12 04:19:11 +02:00
|
|
|
binary_upgrade_next_pg_type_oid = typoid;
|
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
Oid typoid = PG_GETARG_OID(0);
|
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:25:34 +01:00
|
|
|
binary_upgrade_next_array_pg_type_oid = typoid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
Oid typoid = PG_GETARG_OID(0);
|
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:25:34 +01:00
|
|
|
binary_upgrade_next_toast_pg_type_oid = typoid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2011-01-08 03:25:34 +01:00
|
|
|
Oid reloid = PG_GETARG_OID(0);
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:25:34 +01:00
|
|
|
binary_upgrade_next_heap_pg_class_oid = reloid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2011-01-08 03:25:34 +01:00
|
|
|
Oid reloid = PG_GETARG_OID(0);
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:25:34 +01:00
|
|
|
binary_upgrade_next_index_pg_class_oid = reloid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2011-01-08 03:25:34 +01:00
|
|
|
Oid reloid = PG_GETARG_OID(0);
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:25:34 +01:00
|
|
|
binary_upgrade_next_toast_pg_class_oid = reloid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_pg_enum_oid(PG_FUNCTION_ARGS)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
Oid enumoid = PG_GETARG_OID(0);
|
2010-07-06 21:19:02 +02:00
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2010-10-25 05:04:37 +02:00
|
|
|
binary_upgrade_next_pg_enum_oid = enumoid;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
2011-01-08 03:59:29 +01:00
|
|
|
|
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_set_next_pg_authid_oid(PG_FUNCTION_ARGS)
|
2011-01-08 03:59:29 +01:00
|
|
|
{
|
|
|
|
Oid authoid = PG_GETARG_OID(0);
|
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
2011-01-08 03:59:29 +01:00
|
|
|
binary_upgrade_next_pg_authid_oid = authoid;
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
2011-02-10 01:17:33 +01:00
|
|
|
Datum
|
2015-03-11 03:33:25 +01:00
|
|
|
binary_upgrade_create_empty_extension(PG_FUNCTION_ARGS)
|
2011-02-10 01:17:33 +01:00
|
|
|
{
|
2016-01-03 22:26:38 +01:00
|
|
|
text *extName;
|
|
|
|
text *schemaName;
|
|
|
|
bool relocatable;
|
|
|
|
text *extVersion;
|
2011-02-10 01:17:33 +01:00
|
|
|
Datum extConfig;
|
|
|
|
Datum extCondition;
|
|
|
|
List *requiredExtensions;
|
|
|
|
|
2014-08-26 04:19:05 +02:00
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
|
|
|
|
2016-01-03 22:26:38 +01:00
|
|
|
/* We must check these things before dereferencing the arguments */
|
|
|
|
if (PG_ARGISNULL(0) ||
|
|
|
|
PG_ARGISNULL(1) ||
|
|
|
|
PG_ARGISNULL(2) ||
|
|
|
|
PG_ARGISNULL(3))
|
|
|
|
elog(ERROR, "null argument to binary_upgrade_create_empty_extension is not allowed");
|
|
|
|
|
|
|
|
extName = PG_GETARG_TEXT_PP(0);
|
|
|
|
schemaName = PG_GETARG_TEXT_PP(1);
|
|
|
|
relocatable = PG_GETARG_BOOL(2);
|
|
|
|
extVersion = PG_GETARG_TEXT_PP(3);
|
|
|
|
|
2011-02-10 01:17:33 +01:00
|
|
|
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++)
|
|
|
|
{
|
2017-03-13 00:35:31 +01:00
|
|
|
char *extName = TextDatumGetCString(textDatums[i]);
|
2011-04-10 17:42:00 +02:00
|
|
|
Oid extOid = get_extension_oid(extName, false);
|
2011-02-10 01:17:33 +01:00
|
|
|
|
|
|
|
requiredExtensions = lappend_oid(requiredExtensions, extOid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InsertExtensionTuple(text_to_cstring(extName),
|
|
|
|
GetUserId(),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
get_namespace_oid(text_to_cstring(schemaName), false),
|
2011-02-10 01:17:33 +01:00
|
|
|
relocatable,
|
2011-02-12 03:25:20 +01:00
|
|
|
text_to_cstring(extVersion),
|
2011-02-10 01:17:33 +01:00
|
|
|
extConfig,
|
|
|
|
extCondition,
|
|
|
|
requiredExtensions);
|
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
2016-04-07 03:45:32 +02:00
|
|
|
|
|
|
|
Datum
|
|
|
|
binary_upgrade_set_record_init_privs(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
bool record_init_privs = PG_GETARG_BOOL(0);
|
|
|
|
|
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
|
|
|
binary_upgrade_record_init_privs = record_init_privs;
|
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|
2018-06-22 14:42:36 +02:00
|
|
|
|
|
|
|
Datum
|
|
|
|
binary_upgrade_set_missing_value(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid table_id = PG_GETARG_OID(0);
|
|
|
|
text *attname = PG_GETARG_TEXT_P(1);
|
|
|
|
text *value = PG_GETARG_TEXT_P(2);
|
|
|
|
char *cattname = text_to_cstring(attname);
|
|
|
|
char *cvalue = text_to_cstring(value);
|
|
|
|
|
|
|
|
CHECK_IS_BINARY_UPGRADE;
|
|
|
|
SetAttrMissing(table_id, cattname, cvalue);
|
|
|
|
|
|
|
|
PG_RETURN_VOID();
|
|
|
|
}
|