mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Restructure the pg_upgrade code to use several global structures rather
than packing everything into 'ctx' and passing that to every function.
This commit is contained in:
@ -19,65 +19,65 @@
|
||||
* backend behavior.
|
||||
*/
|
||||
void
|
||||
install_support_functions(migratorContext *ctx)
|
||||
install_support_functions(void)
|
||||
{
|
||||
int dbnum;
|
||||
|
||||
prep_status(ctx, "Adding support functions to new cluster");
|
||||
prep_status("Adding support functions to new cluster");
|
||||
|
||||
for (dbnum = 0; dbnum < ctx->new.dbarr.ndbs; dbnum++)
|
||||
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
|
||||
{
|
||||
DbInfo *newdb = &ctx->new.dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(ctx, newdb->db_name, CLUSTER_NEW);
|
||||
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
|
||||
|
||||
/* suppress NOTICE of dropped objects */
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"SET client_min_messages = warning;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"DROP SCHEMA IF EXISTS binary_upgrade CASCADE;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"RESET client_min_messages;"));
|
||||
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE SCHEMA binary_upgrade;"));
|
||||
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
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(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.set_next_pg_type_array_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.set_next_pg_type_toast_oid(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.set_next_heap_relfilenode(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.set_next_toast_relfilenode(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.set_next_index_relfilenode(OID) "
|
||||
"RETURNS VOID "
|
||||
"AS '$libdir/pg_upgrade_support' "
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"CREATE OR REPLACE FUNCTION "
|
||||
" binary_upgrade.add_pg_enum_label(OID, OID, NAME) "
|
||||
"RETURNS VOID "
|
||||
@ -85,32 +85,32 @@ install_support_functions(migratorContext *ctx)
|
||||
"LANGUAGE C STRICT;"));
|
||||
PQfinish(conn);
|
||||
}
|
||||
check_ok(ctx);
|
||||
check_ok();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
uninstall_support_functions(migratorContext *ctx)
|
||||
uninstall_support_functions(void)
|
||||
{
|
||||
int dbnum;
|
||||
|
||||
prep_status(ctx, "Removing support functions from new cluster");
|
||||
prep_status("Removing support functions from new cluster");
|
||||
|
||||
for (dbnum = 0; dbnum < ctx->new.dbarr.ndbs; dbnum++)
|
||||
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
|
||||
{
|
||||
DbInfo *newdb = &ctx->new.dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(ctx, newdb->db_name, CLUSTER_NEW);
|
||||
DbInfo *newdb = &new_cluster.dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(newdb->db_name, CLUSTER_NEW);
|
||||
|
||||
/* suppress NOTICE of dropped objects */
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"SET client_min_messages = warning;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"DROP SCHEMA binary_upgrade CASCADE;"));
|
||||
PQclear(executeQueryOrDie(ctx, conn,
|
||||
PQclear(executeQueryOrDie(conn,
|
||||
"RESET client_min_messages;"));
|
||||
PQfinish(conn);
|
||||
}
|
||||
check_ok(ctx);
|
||||
check_ok();
|
||||
}
|
||||
|
||||
|
||||
@ -121,25 +121,25 @@ uninstall_support_functions(migratorContext *ctx)
|
||||
* We will later check that they all exist in the new installation.
|
||||
*/
|
||||
void
|
||||
get_loadable_libraries(migratorContext *ctx)
|
||||
get_loadable_libraries(void)
|
||||
{
|
||||
ClusterInfo *active_cluster = &ctx->old;
|
||||
ClusterInfo *active_cluster = &old_cluster;
|
||||
PGresult **ress;
|
||||
int totaltups;
|
||||
int dbnum;
|
||||
|
||||
ress = (PGresult **)
|
||||
pg_malloc(ctx, active_cluster->dbarr.ndbs * sizeof(PGresult *));
|
||||
pg_malloc(active_cluster->dbarr.ndbs * sizeof(PGresult *));
|
||||
totaltups = 0;
|
||||
|
||||
/* Fetch all library names, removing duplicates within each DB */
|
||||
for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
|
||||
{
|
||||
DbInfo *active_db = &active_cluster->dbarr.dbs[dbnum];
|
||||
PGconn *conn = connectToServer(ctx, active_db->db_name, CLUSTER_OLD);
|
||||
PGconn *conn = connectToServer(active_db->db_name, CLUSTER_OLD);
|
||||
|
||||
/* Fetch all libraries referenced in this DB */
|
||||
ress[dbnum] = executeQueryOrDie(ctx, conn,
|
||||
ress[dbnum] = executeQueryOrDie(conn,
|
||||
"SELECT DISTINCT probin "
|
||||
"FROM pg_catalog.pg_proc "
|
||||
"WHERE prolang = 13 /* C */ AND "
|
||||
@ -153,9 +153,9 @@ get_loadable_libraries(migratorContext *ctx)
|
||||
|
||||
/* Allocate what's certainly enough space */
|
||||
if (totaltups > 0)
|
||||
ctx->libraries = (char **) pg_malloc(ctx, totaltups * sizeof(char *));
|
||||
os_info.libraries = (char **) pg_malloc(totaltups * sizeof(char *));
|
||||
else
|
||||
ctx->libraries = NULL;
|
||||
os_info.libraries = NULL;
|
||||
|
||||
/*
|
||||
* Now remove duplicates across DBs. This is pretty inefficient code, but
|
||||
@ -178,20 +178,20 @@ get_loadable_libraries(migratorContext *ctx)
|
||||
|
||||
for (n = 0; n < totaltups; n++)
|
||||
{
|
||||
if (strcmp(lib, ctx->libraries[n]) == 0)
|
||||
if (strcmp(lib, os_info.libraries[n]) == 0)
|
||||
{
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dup)
|
||||
ctx->libraries[totaltups++] = pg_strdup(ctx, lib);
|
||||
os_info.libraries[totaltups++] = pg_strdup(lib);
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
}
|
||||
|
||||
ctx->num_libraries = totaltups;
|
||||
os_info.num_libraries = totaltups;
|
||||
|
||||
pg_free(ress);
|
||||
}
|
||||
@ -205,24 +205,24 @@ get_loadable_libraries(migratorContext *ctx)
|
||||
* compatibility as well as presence.
|
||||
*/
|
||||
void
|
||||
check_loadable_libraries(migratorContext *ctx)
|
||||
check_loadable_libraries(void)
|
||||
{
|
||||
PGconn *conn = connectToServer(ctx, "template1", CLUSTER_NEW);
|
||||
PGconn *conn = connectToServer("template1", CLUSTER_NEW);
|
||||
int libnum;
|
||||
FILE *script = NULL;
|
||||
bool found = false;
|
||||
char output_path[MAXPGPATH];
|
||||
|
||||
prep_status(ctx, "Checking for presence of required libraries");
|
||||
prep_status("Checking for presence of required libraries");
|
||||
|
||||
snprintf(output_path, sizeof(output_path), "%s/loadable_libraries.txt",
|
||||
ctx->cwd);
|
||||
os_info.cwd);
|
||||
|
||||
for (libnum = 0; libnum < ctx->num_libraries; libnum++)
|
||||
for (libnum = 0; libnum < os_info.num_libraries; libnum++)
|
||||
{
|
||||
char *lib = ctx->libraries[libnum];
|
||||
char *lib = os_info.libraries[libnum];
|
||||
int llen = strlen(lib);
|
||||
char *cmd = (char *) pg_malloc(ctx, 8 + 2 * llen + 1);
|
||||
char *cmd = (char *) pg_malloc(8 + 2 * llen + 1);
|
||||
PGresult *res;
|
||||
|
||||
strcpy(cmd, "LOAD '");
|
||||
@ -235,7 +235,7 @@ check_loadable_libraries(migratorContext *ctx)
|
||||
{
|
||||
found = true;
|
||||
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
|
||||
pg_log(ctx, PG_FATAL, "Could not create necessary file: %s\n",
|
||||
pg_log(PG_FATAL, "Could not create necessary file: %s\n",
|
||||
output_path);
|
||||
fprintf(script, "Failed to load library: %s\n%s\n",
|
||||
lib,
|
||||
@ -251,8 +251,8 @@ check_loadable_libraries(migratorContext *ctx)
|
||||
if (found)
|
||||
{
|
||||
fclose(script);
|
||||
pg_log(ctx, PG_REPORT, "fatal\n");
|
||||
pg_log(ctx, PG_FATAL,
|
||||
pg_log(PG_REPORT, "fatal\n");
|
||||
pg_log(PG_FATAL,
|
||||
"| Your installation references loadable libraries that are missing\n"
|
||||
"| from the new installation. You can add these libraries to\n"
|
||||
"| the new installation, or remove the functions using them\n"
|
||||
@ -261,5 +261,5 @@ check_loadable_libraries(migratorContext *ctx)
|
||||
"| \"%s\".\n\n", output_path);
|
||||
}
|
||||
else
|
||||
check_ok(ctx);
|
||||
check_ok();
|
||||
}
|
||||
|
Reference in New Issue
Block a user