Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8d3d2a

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 thesame catversion (because of tablespace conflict), and a pre-9.0migration to 9.0 has not large object permissions to migrate.
1 parent2896c87 commitd8d3d2a

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-
*thetoast place holders between restoring these two parts of the
36+
*thesupport 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(constchar*db_name)
2323
{
24-
intdbnum;
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 cancreate the toast table
229-
*placeholder relfiles.
233+
* We have to create the databases first so we caninstall 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
staticvoid
248252
create_new_objects(void)
249253
{
254+
intdbnum;
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 @@ voidcheck_hard_link(void);
324324

325325
/* function.c */
326326

327-
voidinstall_support_functions(void);
327+
voidinstall_db_support_functions(constchar*db_name);
328328
voiduninstall_support_functions(void);
329329
voidget_loadable_libraries(void);
330330
voidcheck_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
externPGDLLIMPORTOidbinary_upgrade_next_toast_pg_class_oid;
3030

3131
externPGDLLIMPORTOidbinary_upgrade_next_pg_enum_oid;
32+
externPGDLLIMPORTOidbinary_upgrade_next_pg_authid_oid;
3233

3334
Datumset_next_pg_type_oid(PG_FUNCTION_ARGS);
3435
Datumset_next_array_pg_type_oid(PG_FUNCTION_ARGS);
@@ -39,6 +40,7 @@ Datumset_next_index_pg_class_oid(PG_FUNCTION_ARGS);
3940
Datumset_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
4041

4142
Datumset_next_pg_enum_oid(PG_FUNCTION_ARGS);
43+
Datumset_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+
Oidauthoid=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+
Oidbinary_upgrade_next_pg_authid_oid=InvalidOid;
40+
3841

3942
/* GUC parameter */
4043
externboolPassword_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
PQExpBufferbuf=createPQExpBuffer();
652652
PGresult*res;
653-
inti_rolname,
653+
inti_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+
"SELECToid,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 BY1");
677+
"ORDER BY2");
677678
elseif (server_version >=80200)
678679
printfPQExpBuffer(buf,
679-
"SELECT rolname, rolsuper, rolinherit, "
680+
"SELECToid,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 BY1");
686+
"ORDER BY2");
686687
elseif (server_version >=80100)
687688
printfPQExpBuffer(buf,
688-
"SELECT rolname, rolsuper, rolinherit, "
689+
"SELECToid,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 BY1");
695+
"ORDER BY2");
695696
else
696697
printfPQExpBuffer(buf,
697-
"SELECT usename as rolname, "
698+
"SELECT0,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+
"SELECT0,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 BY1");
727+
"ORDER BY2");
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+
Oidauth_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)

[8]ページ先頭

©2009-2025 Movatter.jp