Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 30982be

Browse files
committed
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>
1 parent 936546d commit 30982be

File tree

20 files changed

+61
-208
lines changed

20 files changed

+61
-208
lines changed

contrib/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ SUBDIRS = \
3737
pg_test_timing \
3838
pg_trgm \
3939
pg_upgrade \
40-
pg_upgrade_support \
4140
pgcrypto \
4241
pgrowlocks \
4342
pgstattuple \

contrib/pg_upgrade/dump.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ optionally_create_toast_tables(void)
121121
for (rowno = 0; rowno < ntups; rowno++)
122122
{
123123
/* enable auto-oid-numbered TOAST creation if needed */
124-
PQclear(executeQueryOrDie(conn, "SELECT binary_upgrade.set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
124+
PQclear(executeQueryOrDie(conn, "SELECT pg_catalog.binary_upgrade_set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
125125
OPTIONALLY_CREATE_TOAST_OID));
126126

127127
/* dummy command that also triggers check for required TOAST table */

contrib/pg_upgrade/function.c

-113
Original file line numberDiff line numberDiff line change
@@ -13,112 +13,6 @@
1313

1414
#include "access/transam.h"
1515

16-
#define PG_UPGRADE_SUPPORT "$libdir/pg_upgrade_support"
17-
18-
/*
19-
* install_support_functions_in_new_db()
20-
*
21-
* pg_upgrade requires some support functions that enable it to modify
22-
* backend behavior.
23-
*/
24-
void
25-
install_support_functions_in_new_db(const char *db_name)
26-
{
27-
PGconn *conn = connectToServer(&new_cluster, db_name);
28-
29-
/* suppress NOTICE of dropped objects */
30-
PQclear(executeQueryOrDie(conn,
31-
"SET client_min_messages = warning;"));
32-
PQclear(executeQueryOrDie(conn,
33-
"DROP SCHEMA IF EXISTS binary_upgrade CASCADE;"));
34-
PQclear(executeQueryOrDie(conn,
35-
"RESET client_min_messages;"));
36-
37-
PQclear(executeQueryOrDie(conn,
38-
"CREATE SCHEMA binary_upgrade;"));
39-
40-
PQclear(executeQueryOrDie(conn,
41-
"CREATE OR REPLACE FUNCTION "
42-
"binary_upgrade.set_next_pg_type_oid(OID) "
43-
"RETURNS VOID "
44-
"AS '$libdir/pg_upgrade_support' "
45-
"LANGUAGE C STRICT;"));
46-
PQclear(executeQueryOrDie(conn,
47-
"CREATE OR REPLACE FUNCTION "
48-
"binary_upgrade.set_next_array_pg_type_oid(OID) "
49-
"RETURNS VOID "
50-
"AS '$libdir/pg_upgrade_support' "
51-
"LANGUAGE C STRICT;"));
52-
PQclear(executeQueryOrDie(conn,
53-
"CREATE OR REPLACE FUNCTION "
54-
"binary_upgrade.set_next_toast_pg_type_oid(OID) "
55-
"RETURNS VOID "
56-
"AS '$libdir/pg_upgrade_support' "
57-
"LANGUAGE C STRICT;"));
58-
PQclear(executeQueryOrDie(conn,
59-
"CREATE OR REPLACE FUNCTION "
60-
"binary_upgrade.set_next_heap_pg_class_oid(OID) "
61-
"RETURNS VOID "
62-
"AS '$libdir/pg_upgrade_support' "
63-
"LANGUAGE C STRICT;"));
64-
PQclear(executeQueryOrDie(conn,
65-
"CREATE OR REPLACE FUNCTION "
66-
"binary_upgrade.set_next_index_pg_class_oid(OID) "
67-
"RETURNS VOID "
68-
"AS '$libdir/pg_upgrade_support' "
69-
"LANGUAGE C STRICT;"));
70-
PQclear(executeQueryOrDie(conn,
71-
"CREATE OR REPLACE FUNCTION "
72-
"binary_upgrade.set_next_toast_pg_class_oid(OID) "
73-
"RETURNS VOID "
74-
"AS '$libdir/pg_upgrade_support' "
75-
"LANGUAGE C STRICT;"));
76-
PQclear(executeQueryOrDie(conn,
77-
"CREATE OR REPLACE FUNCTION "
78-
"binary_upgrade.set_next_pg_enum_oid(OID) "
79-
"RETURNS VOID "
80-
"AS '$libdir/pg_upgrade_support' "
81-
"LANGUAGE C STRICT;"));
82-
PQclear(executeQueryOrDie(conn,
83-
"CREATE OR REPLACE FUNCTION "
84-
"binary_upgrade.set_next_pg_authid_oid(OID) "
85-
"RETURNS VOID "
86-
"AS '$libdir/pg_upgrade_support' "
87-
"LANGUAGE C STRICT;"));
88-
PQclear(executeQueryOrDie(conn,
89-
"CREATE OR REPLACE FUNCTION "
90-
"binary_upgrade.create_empty_extension(text, text, bool, text, oid[], text[], text[]) "
91-
"RETURNS VOID "
92-
"AS '$libdir/pg_upgrade_support' "
93-
"LANGUAGE C;"));
94-
PQfinish(conn);
95-
}
96-
97-
98-
void
99-
uninstall_support_functions_from_new_cluster(void)
100-
{
101-
int dbnum;
102-
103-
prep_status("Removing support functions from new cluster");
104-
105-
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
106-
{
107-
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
108-
PGconn *conn = connectToServer(&new_cluster, new_db->db_name);
109-
110-
/* suppress NOTICE of dropped objects */
111-
PQclear(executeQueryOrDie(conn,
112-
"SET client_min_messages = warning;"));
113-
PQclear(executeQueryOrDie(conn,
114-
"DROP SCHEMA binary_upgrade CASCADE;"));
115-
PQclear(executeQueryOrDie(conn,
116-
"RESET client_min_messages;"));
117-
PQfinish(conn);
118-
}
119-
check_ok();
120-
}
121-
12216

12317
/*
12418
* get_loadable_libraries()
@@ -218,8 +112,6 @@ get_loadable_libraries(void)
218112
if (found_public_plpython_handler)
219113
pg_fatal("Remove the problem functions from the old cluster to continue.\n");
220114

221-
totaltups++; /* reserve for pg_upgrade_support */
222-
223115
/* Allocate what's certainly enough space */
224116
os_info.libraries = (char **) pg_malloc(totaltups * sizeof(char *));
225117

@@ -228,7 +120,6 @@ get_loadable_libraries(void)
228120
* there probably aren't enough entries to matter.
229121
*/
230122
totaltups = 0;
231-
os_info.libraries[totaltups++] = pg_strdup(PG_UPGRADE_SUPPORT);
232123

233124
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
234125
{
@@ -321,10 +212,6 @@ check_loadable_libraries(void)
321212
{
322213
found = true;
323214

324-
/* exit and report missing support library with special message */
325-
if (strcmp(lib, PG_UPGRADE_SUPPORT) == 0)
326-
pg_fatal("The pg_upgrade_support module must be created and installed in the new cluster.\n");
327-
328215
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
329216
pg_fatal("Could not open file \"%s\": %s\n",
330217
output_path, getErrorText(errno));

contrib/pg_upgrade/pg_upgrade.c

-27
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,6 @@ prepare_new_databases(void)
278278

279279
prep_status("Restoring global objects in the new cluster");
280280

281-
/*
282-
* Install support functions in the global-object restore database to
283-
* preserve pg_authid.oid. pg_dumpall uses 'template0' as its template
284-
* database so objects we add into 'template1' are not propogated. They
285-
* are removed on pg_upgrade exit.
286-
*/
287-
install_support_functions_in_new_db("template1");
288-
289281
/*
290282
* We have to create the databases first so we can install support
291283
* functions in all the other databases. Ideally we could create the
@@ -308,23 +300,6 @@ create_new_objects(void)
308300
{
309301
int dbnum;
310302

311-
prep_status("Adding support functions to new cluster");
312-
313-
/*
314-
* Technically, we only need to install these support functions in new
315-
* databases that also exist in the old cluster, but for completeness we
316-
* process all new databases.
317-
*/
318-
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
319-
{
320-
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
321-
322-
/* skip db we already installed */
323-
if (strcmp(new_db->db_name, "template1") != 0)
324-
install_support_functions_in_new_db(new_db->db_name);
325-
}
326-
check_ok();
327-
328303
prep_status("Restoring database schemas in the new cluster\n");
329304

330305
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
@@ -368,8 +343,6 @@ create_new_objects(void)
368343

369344
/* regenerate now that we have objects in the databases */
370345
get_db_and_rel_infos(&new_cluster);
371-
372-
uninstall_support_functions_from_new_cluster();
373346
}
374347

375348
/*

contrib/pg_upgrade/pg_upgrade.h

-2
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ FILE *fopen_priv(const char *path, const char *mode);
405405

406406
/* function.c */
407407

408-
void install_support_functions_in_new_db(const char *db_name);
409-
void uninstall_support_functions_from_new_cluster(void);
410408
void get_loadable_libraries(void);
411409
void check_loadable_libraries(void);
412410

contrib/pg_upgrade/test.sh

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ if [ "$1" = '--install' ]; then
7070
libdir=$temp_install/$libdir
7171

7272
"$MAKE" -s -C ../.. install DESTDIR="$temp_install"
73-
"$MAKE" -s -C ../pg_upgrade_support install DESTDIR="$temp_install"
7473
"$MAKE" -s -C . install DESTDIR="$temp_install"
7574

7675
# platform-specific magic to find the shared libraries; see pg_regress.c

contrib/pg_upgrade_support/Makefile

-16
This file was deleted.

doc/src/sgml/pgupgrade.sgml

+2-3
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,10 @@ make prefix=/usr/local/pgsql.new install
253253
</step>
254254

255255
<step>
256-
<title>Install pg_upgrade and pg_upgrade_support</title>
256+
<title>Install pg_upgrade</title>
257257

258258
<para>
259-
Install the <application>pg_upgrade</> binary and
260-
<application>pg_upgrade_support</> library in the new PostgreSQL
259+
Install the <application>pg_upgrade</> binary in the new PostgreSQL
261260
installation.
262261
</para>
263262
</step>

src/backend/catalog/heap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#include "utils/tqual.h"
7777

7878

79-
/* Potentially set by contrib/pg_upgrade_support functions */
79+
/* Potentially set by pg_upgrade_support functions */
8080
Oid binary_upgrade_next_heap_pg_class_oid = InvalidOid;
8181
Oid binary_upgrade_next_toast_pg_class_oid = InvalidOid;
8282

src/backend/catalog/index.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#include "utils/tqual.h"
7070

7171

72-
/* Potentially set by contrib/pg_upgrade_support functions */
72+
/* Potentially set by pg_upgrade_support functions */
7373
Oid binary_upgrade_next_index_pg_class_oid = InvalidOid;
7474

7575
/* state info for validate_index bulkdelete callback */

src/backend/catalog/pg_enum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "utils/tqual.h"
3232

3333

34-
/* Potentially set by contrib/pg_upgrade_support functions */
34+
/* Potentially set by pg_upgrade_support functions */
3535
Oid binary_upgrade_next_pg_enum_oid = InvalidOid;
3636

3737
static void RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems);

src/backend/catalog/pg_type.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "utils/rel.h"
3737
#include "utils/syscache.h"
3838

39-
/* Potentially set by contrib/pg_upgrade_support functions */
39+
/* Potentially set by pg_upgrade_support functions */
4040
Oid binary_upgrade_next_pg_type_oid = InvalidOid;
4141

4242
/* ----------------------------------------------------------------

src/backend/catalog/toasting.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "utils/rel.h"
3333
#include "utils/syscache.h"
3434

35-
/* Potentially set by contrib/pg_upgrade_support functions */
35+
/* Potentially set by pg_upgrade_support functions */
3636
Oid binary_upgrade_next_toast_pg_type_oid = InvalidOid;
3737

3838
static void CheckAndCreateToastTable(Oid relOid, Datum reloptions,

src/backend/commands/typecmds.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct
8080
/* atts[] is of allocated length RelationGetNumberOfAttributes(rel) */
8181
} RelToCheck;
8282

83-
/* Potentially set by contrib/pg_upgrade_support functions */
83+
/* Potentially set by pg_upgrade_support functions */
8484
Oid binary_upgrade_next_array_pg_type_oid = InvalidOid;
8585

8686
static void makeRangeConstructors(const char *name, Oid namespace,

src/backend/commands/user.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "utils/timestamp.h"
3939
#include "utils/tqual.h"
4040

41-
/* Potentially set by contrib/pg_upgrade_support functions */
41+
/* Potentially set by pg_upgrade_support functions */
4242
Oid binary_upgrade_next_pg_authid_oid = InvalidOid;
4343

4444

src/backend/utils/adt/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ OBJS = acl.o arrayfuncs.o array_selfuncs.o array_typanalyze.o \
2525
jsonfuncs.o like.o lockfuncs.o mac.o misc.o nabstime.o name.o \
2626
network.o network_gist.o network_selfuncs.o \
2727
numeric.o numutils.o oid.o oracle_compat.o \
28-
orderedsetaggs.o pg_locale.o pg_lsn.o pgstatfuncs.o \
28+
orderedsetaggs.o pg_locale.o pg_lsn.o pg_upgrade_support.o \
29+
pgstatfuncs.o \
2930
pseudotypes.o quote.o rangetypes.o rangetypes_gist.o \
3031
rangetypes_selfuncs.o rangetypes_spgist.o rangetypes_typanalyze.o \
3132
regexp.o regproc.o ri_triggers.o rowtypes.o ruleutils.o \

0 commit comments

Comments
 (0)