mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Integrate pg_upgrade_support module into backend
Previously, these functions were created in a schema "binary_upgrade", which was deleted after pg_upgrade was finished. Because we don't want to keep that schema around permanently, move them to pg_catalog but rename them with a binary_upgrade_... prefix. The provided functions are only small wrappers around global variables that were added specifically for pg_upgrade use, so keeping the module separate does not create any modularity. The functions still check that they are only called in binary upgrade mode, so it is not possible to call these during normal operation. Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
This commit is contained in:
@@ -37,7 +37,6 @@ SUBDIRS = \
|
||||
pg_test_timing \
|
||||
pg_trgm \
|
||||
pg_upgrade \
|
||||
pg_upgrade_support \
|
||||
pgcrypto \
|
||||
pgrowlocks \
|
||||
pgstattuple \
|
||||
|
@@ -121,7 +121,7 @@ optionally_create_toast_tables(void)
|
||||
for (rowno = 0; rowno < ntups; rowno++)
|
||||
{
|
||||
/* enable auto-oid-numbered TOAST creation if needed */
|
||||
PQclear(executeQueryOrDie(conn, "SELECT binary_upgrade.set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
|
||||
PQclear(executeQueryOrDie(conn, "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
|
||||
OPTIONALLY_CREATE_TOAST_OID));
|
||||
|
||||
/* dummy command that also triggers check for required TOAST table */
|
||||
|
@@ -13,112 +13,6 @@
|
||||
|
||||
#include "access/transam.h"
|
||||
|
||||
#define PG_UPGRADE_SUPPORT "$libdir/pg_upgrade_support"
|
||||
|
||||
/*
|
||||
* install_support_functions_in_new_db()
|
||||
*
|
||||
* pg_upgrade requires some support functions that enable it to modify
|
||||
* backend behavior.
|
||||
*/
|
||||
void
|
||||
install_support_functions_in_new_db(const char *db_name)
|
||||
{
|
||||
PGconn *conn = connectToServer(&new_cluster, db_name);
|
||||
|
||||
/* suppress NOTICE of dropped objects */
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"SET client_min_messages = warning;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"DROP SCHEMA IF EXISTS binary_upgrade CASCADE;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"RESET client_min_messages;"));
|
||||
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE SCHEMA binary_upgrade;"));
|
||||
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_pg_type_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_array_pg_type_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_toast_pg_type_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_heap_pg_class_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_index_pg_class_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_toast_pg_class_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_pg_enum_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.set_next_pg_authid_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
"binary_upgrade.create_empty_extension(text, text, bool, text, oid[], text[], text[]) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C;"));
|
||||
PQfinish(conn);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uninstall_support_functions_from_new_cluster(void)
|
||||
{
|
||||
int dbnum;
|
||||
|
||||
prep_status("Removing support functions from new cluster");
|
||||
|
||||
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
|
||||
{
|
||||
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(&new_cluster, new_db->db_name);
|
||||
|
||||
/* suppress NOTICE of dropped objects */
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"SET client_min_messages = warning;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"DROP SCHEMA binary_upgrade CASCADE;"));
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"RESET client_min_messages;"));
|
||||
PQfinish(conn);
|
||||
}
|
||||
check_ok();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_loadable_libraries()
|
||||
@@ -218,8 +112,6 @@ get_loadable_libraries(void)
|
||||
if (found_public_plpython_handler)
|
||||
pg_fatal("Remove the problem functions from the old cluster to continue.\n");
|
||||
|
||||
totaltups++; /* reserve for pg_upgrade_support */
|
||||
|
||||
/* Allocate what's certainly enough space */
|
||||
os_info.libraries = (char **) pg_malloc(totaltups * sizeof(char *));
|
||||
|
||||
@@ -228,7 +120,6 @@ get_loadable_libraries(void)
|
||||
* there probably aren't enough entries to matter.
|
||||
*/
|
||||
totaltups = 0;
|
||||
os_info.libraries[totaltups++] = pg_strdup(PG_UPGRADE_SUPPORT);
|
||||
|
||||
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
|
||||
{
|
||||
@@ -321,10 +212,6 @@ check_loadable_libraries(void)
|
||||
{
|
||||
found = true;
|
||||
|
||||
/* exit and report missing support library with special message */
|
||||
if (strcmp(lib, PG_UPGRADE_SUPPORT) == 0)
|
||||
pg_fatal("The pg_upgrade_support module must be created and installed in the new cluster.\n");
|
||||
|
||||
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
||||
pg_fatal("Could not open file \"%s\": %s\n",
|
||||
output_path, getErrorText(errno));
|
||||
|
@@ -278,14 +278,6 @@ prepare_new_databases(void)
|
||||
|
||||
prep_status("Restoring global objects in the new cluster");
|
||||
|
||||
/*
|
||||
* Install support functions in the global-object restore database to
|
||||
* preserve pg_authid.oid. pg_dumpall uses 'template0' as its template
|
||||
* database so objects we add into 'template1' are not propogated. They
|
||||
* are removed on pg_upgrade exit.
|
||||
*/
|
||||
install_support_functions_in_new_db("template1");
|
||||
|
||||
/*
|
||||
* We have to create the databases first so we can install support
|
||||
* functions in all the other databases. Ideally we could create the
|
||||
@@ -308,23 +300,6 @@ create_new_objects(void)
|
||||
{
|
||||
int dbnum;
|
||||
|
||||
prep_status("Adding support functions to new cluster");
|
||||
|
||||
/*
|
||||
* Technically, we only need to install these support functions in new
|
||||
* databases that also exist in the old cluster, but for completeness we
|
||||
* process all new databases.
|
||||
*/
|
||||
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
|
||||
{
|
||||
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
|
||||
|
||||
/* skip db we already installed */
|
||||
if (strcmp(new_db->db_name, "template1") != 0)
|
||||
install_support_functions_in_new_db(new_db->db_name);
|
||||
}
|
||||
check_ok();
|
||||
|
||||
prep_status("Restoring database schemas in the new cluster\n");
|
||||
|
||||
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
|
||||
@@ -368,8 +343,6 @@ create_new_objects(void)
|
||||
|
||||
/* regenerate now that we have objects in the databases */
|
||||
get_db_and_rel_infos(&new_cluster);
|
||||
|
||||
uninstall_support_functions_from_new_cluster();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -405,8 +405,6 @@ FILE *fopen_priv(const char *path, const char *mode);
|
||||
|
||||
/* function.c */
|
||||
|
||||
void install_support_functions_in_new_db(const char *db_name);
|
||||
void uninstall_support_functions_from_new_cluster(void);
|
||||
void get_loadable_libraries(void);
|
||||
void check_loadable_libraries(void);
|
||||
|
||||
|
@@ -70,7 +70,6 @@ if [ "$1" = '--install' ]; then
|
||||
libdir=$temp_install/$libdir
|
||||
|
||||
"$MAKE" -s -C ../.. install DESTDIR="$temp_install"
|
||||
"$MAKE" -s -C ../pg_upgrade_support install DESTDIR="$temp_install"
|
||||
"$MAKE" -s -C . install DESTDIR="$temp_install"
|
||||
|
||||
# platform-specific magic to find the shared libraries; see pg_regress.c
|
||||
|
@@ -1,16 +0,0 @@
|
||||
# contrib/pg_upgrade_support/Makefile
|
||||
|
||||
PGFILEDESC = "pg_upgrade_support - server-side functions for pg_upgrade"
|
||||
|
||||
MODULES = pg_upgrade_support
|
||||
|
||||
ifdef USE_PGXS
|
||||
PG_CONFIG = pg_config
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
else
|
||||
subdir = contrib/pg_upgrade_support
|
||||
top_builddir = ../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
include $(top_srcdir)/contrib/contrib-global.mk
|
||||
endif
|
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* contrib/pg_upgrade_support/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"
|
||||
|
||||
/* THIS IS USED ONLY FOR PG >= 9.0 */
|
||||
|
||||
#ifdef PG_MODULE_MAGIC
|
||||
PG_MODULE_MAGIC;
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
#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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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();
|
||||
}
|
Reference in New Issue
Block a user