Skip to content

Commit d8d3d2a

Browse files
committed
Fix pg_upgrade of large object permissions by preserving pg_auth.oid,
which is stored in pg_largeobject_metadata. No backpatch to 9.0 because you can't migrate from 9.0 to 9.0 with the same catversion (because of tablespace conflict), and a pre-9.0 migration to 9.0 has not large object permissions to migrate.
1 parent 2896c87 commit d8d3d2a

File tree

8 files changed

+79
-30
lines changed

8 files changed

+79
-30
lines changed

contrib/pg_upgrade/dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ generate_old_dump(void)
3333
*
3434
* This function splits pg_dumpall output into global values and
3535
* database creation, and per-db schemas. This allows us to create
36-
* the toast place holders between restoring these two parts of the
36+
* the support functions between restoring these two parts of the
3737
* dump. We split on the first "\connect " after a CREATE ROLE
3838
* username match; this is where the per-db restore starts.
3939
*

contrib/pg_upgrade/function.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@
1313

1414

1515
/*
16-
* install_support_functions()
16+
* install_db_support_functions()
1717
*
1818
* pg_upgrade requires some support functions that enable it to modify
1919
* backend behavior.
2020
*/
2121
void
22-
install_support_functions(void)
22+
install_db_support_functions(const char *db_name)
2323
{
24-
int dbnum;
25-
26-
prep_status("Adding support functions to new cluster");
27-
28-
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
29-
{
30-
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
31-
PGconn *conn = connectToServer(&new_cluster, new_db->db_name);
32-
24+
PGconn *conn = connectToServer(&new_cluster, db_name);
25+
3326
/* suppress NOTICE of dropped objects */
3427
PQclear(executeQueryOrDie(conn,
3528
"SET client_min_messages = warning;"));
@@ -83,9 +76,13 @@ install_support_functions(void)
8376
"RETURNS VOID "
8477
"AS '$libdir/pg_upgrade_support' "
8578
"LANGUAGE C STRICT;"));
79+
PQclear(executeQueryOrDie(conn,
80+
"CREATE OR REPLACE FUNCTION "
81+
" binary_upgrade.set_next_pg_authid_oid(OID) "
82+
"RETURNS VOID "
83+
"AS '$libdir/pg_upgrade_support' "
84+
"LANGUAGE C STRICT;"));
8685
PQfinish(conn);
87-
}
88-
check_ok();
8986
}
9087

9188

contrib/pg_upgrade/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
282282
" ON c.relnamespace = n.oid "
283283
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
284284
" ON c.reltablespace = t.oid "
285-
"WHERE (( n.nspname NOT IN ('pg_catalog', 'information_schema') "
285+
"WHERE (( n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') "
286286
" AND c.oid >= %u "
287287
" ) OR ( "
288288
" n.nspname = 'pg_catalog' "

contrib/pg_upgrade/pg_upgrade.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,15 @@ prepare_new_databases(void)
224224

225225
set_frozenxids();
226226

227+
prep_status("Creating databases in the new cluster");
228+
229+
/* install support functions in the database used by GLOBALS_DUMP_FILE */
230+
install_db_support_functions(os_info.user);
231+
227232
/*
228-
* We have to create the databases first so we can create the toast table
229-
* placeholder relfiles.
233+
* We have to create the databases first so we can install support
234+
* functions in all the other databases.
230235
*/
231-
prep_status("Creating databases in the new cluster");
232236
exec_prog(true,
233237
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
234238
/* --no-psqlrc prevents AUTOCOMMIT=off */
@@ -247,10 +251,20 @@ prepare_new_databases(void)
247251
static void
248252
create_new_objects(void)
249253
{
254+
int dbnum;
255+
250256
/* -- NEW -- */
251257
start_postmaster(&new_cluster, false);
252258

253-
install_support_functions();
259+
prep_status("Adding support functions to new cluster");
260+
261+
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
262+
{
263+
DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
264+
265+
install_db_support_functions(new_db->db_name);
266+
}
267+
check_ok();
254268

255269
prep_status("Restoring database schema to new cluster");
256270
exec_prog(true,

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void check_hard_link(void);
324324

325325
/* function.c */
326326

327-
void install_support_functions(void);
327+
void install_db_support_functions(const char *db_name);
328328
void uninstall_support_functions(void);
329329
void get_loadable_libraries(void);
330330
void check_loadable_libraries(void);

contrib/pg_upgrade_support/pg_upgrade_support.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_oid;
2929
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid;
3030

3131
extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
32+
extern PGDLLIMPORT Oid binary_upgrade_next_pg_authid_oid;
3233

3334
Datum set_next_pg_type_oid(PG_FUNCTION_ARGS);
3435
Datum set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
@@ -39,6 +40,7 @@ Datum set_next_index_pg_class_oid(PG_FUNCTION_ARGS);
3940
Datum set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
4041

4142
Datum set_next_pg_enum_oid(PG_FUNCTION_ARGS);
43+
Datum set_next_pg_authid_oid(PG_FUNCTION_ARGS);
4244

4345
PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
4446
PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid);
@@ -49,6 +51,7 @@ PG_FUNCTION_INFO_V1(set_next_index_pg_class_oid);
4951
PG_FUNCTION_INFO_V1(set_next_toast_pg_class_oid);
5052

5153
PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
54+
PG_FUNCTION_INFO_V1(set_next_pg_authid_oid);
5255

5356

5457
Datum
@@ -120,3 +123,13 @@ set_next_pg_enum_oid(PG_FUNCTION_ARGS)
120123

121124
PG_RETURN_VOID();
122125
}
126+
127+
Datum
128+
set_next_pg_authid_oid(PG_FUNCTION_ARGS)
129+
{
130+
Oid authoid = PG_GETARG_OID(0);
131+
132+
binary_upgrade_next_pg_authid_oid = authoid;
133+
PG_RETURN_VOID();
134+
}
135+

src/backend/commands/user.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include "utils/syscache.h"
3636
#include "utils/tqual.h"
3737

38+
/* Potentially set by contrib/pg_upgrade_support functions */
39+
Oid binary_upgrade_next_pg_authid_oid = InvalidOid;
40+
3841

3942
/* GUC parameter */
4043
extern bool Password_encryption;
@@ -393,6 +396,16 @@ CreateRole(CreateRoleStmt *stmt)
393396

394397
tuple = heap_form_tuple(pg_authid_dsc, new_record, new_record_nulls);
395398

399+
/*
400+
* pg_largeobject_metadata contains pg_authid.oid's, so we
401+
* use the binary-upgrade override, if specified.
402+
*/
403+
if (OidIsValid(binary_upgrade_next_pg_authid_oid))
404+
{
405+
HeapTupleSetOid(tuple, binary_upgrade_next_pg_authid_oid);
406+
binary_upgrade_next_pg_authid_oid = InvalidOid;
407+
}
408+
396409
/*
397410
* Insert new record in the pg_authid table
398411
*/

src/bin/pg_dump/pg_dumpall.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ dumpRoles(PGconn *conn)
650650
{
651651
PQExpBuffer buf = createPQExpBuffer();
652652
PGresult *res;
653-
int i_rolname,
653+
int i_oid,
654+
i_rolname,
654655
i_rolsuper,
655656
i_rolinherit,
656657
i_rolcreaterole,
@@ -667,34 +668,34 @@ dumpRoles(PGconn *conn)
667668
/* note: rolconfig is dumped later */
668669
if (server_version >= 90100)
669670
printfPQExpBuffer(buf,
670-
"SELECT rolname, rolsuper, rolinherit, "
671+
"SELECT oid, rolname, rolsuper, rolinherit, "
671672
"rolcreaterole, rolcreatedb, rolcatupdate, "
672673
"rolcanlogin, rolconnlimit, rolpassword, "
673674
"rolvaliduntil, rolreplication, "
674675
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
675676
"FROM pg_authid "
676-
"ORDER BY 1");
677+
"ORDER BY 2");
677678
else if (server_version >= 80200)
678679
printfPQExpBuffer(buf,
679-
"SELECT rolname, rolsuper, rolinherit, "
680+
"SELECT oid, rolname, rolsuper, rolinherit, "
680681
"rolcreaterole, rolcreatedb, rolcatupdate, "
681682
"rolcanlogin, rolconnlimit, rolpassword, "
682683
"rolvaliduntil, false as rolreplication, "
683684
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
684685
"FROM pg_authid "
685-
"ORDER BY 1");
686+
"ORDER BY 2");
686687
else if (server_version >= 80100)
687688
printfPQExpBuffer(buf,
688-
"SELECT rolname, rolsuper, rolinherit, "
689+
"SELECT oid, rolname, rolsuper, rolinherit, "
689690
"rolcreaterole, rolcreatedb, rolcatupdate, "
690691
"rolcanlogin, rolconnlimit, rolpassword, "
691692
"rolvaliduntil, false as rolreplication, "
692693
"null as rolcomment "
693694
"FROM pg_authid "
694-
"ORDER BY 1");
695+
"ORDER BY 2");
695696
else
696697
printfPQExpBuffer(buf,
697-
"SELECT usename as rolname, "
698+
"SELECT 0, usename as rolname, "
698699
"usesuper as rolsuper, "
699700
"true as rolinherit, "
700701
"usesuper as rolcreaterole, "
@@ -708,7 +709,7 @@ dumpRoles(PGconn *conn)
708709
"null as rolcomment "
709710
"FROM pg_shadow "
710711
"UNION ALL "
711-
"SELECT groname as rolname, "
712+
"SELECT 0, groname as rolname, "
712713
"false as rolsuper, "
713714
"true as rolinherit, "
714715
"false as rolcreaterole, "
@@ -723,10 +724,11 @@ dumpRoles(PGconn *conn)
723724
"FROM pg_group "
724725
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
725726
" WHERE usename = groname) "
726-
"ORDER BY 1");
727+
"ORDER BY 2");
727728

728729
res = executeQuery(conn, buf->data);
729730

731+
i_oid = PQfnumber(res, "oid");
730732
i_rolname = PQfnumber(res, "rolname");
731733
i_rolsuper = PQfnumber(res, "rolsuper");
732734
i_rolinherit = PQfnumber(res, "rolinherit");
@@ -751,6 +753,16 @@ dumpRoles(PGconn *conn)
751753

752754
resetPQExpBuffer(buf);
753755

756+
if (binary_upgrade)
757+
{
758+
Oid auth_oid = atooid(PQgetvalue(res, i, i_oid));
759+
760+
appendPQExpBuffer(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n");
761+
appendPQExpBuffer(buf,
762+
"SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n",
763+
auth_oid);
764+
}
765+
754766
/*
755767
* We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
756768
* will acquire the right properties even if it already exists (ie, it

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy