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.
*
* This function splits pg_dumpall output into global values and
* database creation, and per-db schemas. This allows us to create
- * the toast place holders between restoring these two parts of the
+ * the support functions between restoring these two parts of the
* dump. We split on the first "\connect " after a CREATE ROLE
* username match; this is where the per-db restore starts.
*
/*
- * install_support_functions()
+ * install_db_support_functions()
*
* pg_upgrade requires some support functions that enable it to modify
* backend behavior.
*/
void
-install_support_functions(void)
+install_db_support_functions(const char *db_name)
{
- int dbnum;
-
- prep_status("Adding support functions to 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);
-
+ PGconn *conn = connectToServer(&new_cluster, db_name);
+
/* suppress NOTICE of dropped objects */
PQclear(executeQueryOrDie(conn,
"SET client_min_messages = warning;"));
"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;"));
PQfinish(conn);
- }
- check_ok();
}
" ON c.relnamespace = n.oid "
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
" ON c.reltablespace = t.oid "
- "WHERE (( n.nspname NOT IN ('pg_catalog', 'information_schema') "
+ "WHERE (( n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') "
" AND c.oid >= %u "
" ) OR ( "
" n.nspname = 'pg_catalog' "
set_frozenxids();
+ prep_status("Creating databases in the new cluster");
+
+ /* install support functions in the database used by GLOBALS_DUMP_FILE */
+ install_db_support_functions(os_info.user);
+
/*
- * We have to create the databases first so we can create the toast table
- * placeholder relfiles.
+ * We have to create the databases first so we can install support
+ * functions in all the other databases.
*/
- prep_status("Creating databases in the new cluster");
exec_prog(true,
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
/* --no-psqlrc prevents AUTOCOMMIT=off */
static void
create_new_objects(void)
{
+ int dbnum;
+
/* -- NEW -- */
start_postmaster(&new_cluster, false);
- install_support_functions();
+ prep_status("Adding support functions to new cluster");
+
+ for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
+ {
+ DbInfo *new_db = &new_cluster.dbarr.dbs[dbnum];
+
+ install_db_support_functions(new_db->db_name);
+ }
+ check_ok();
prep_status("Restoring database schema to new cluster");
exec_prog(true,
/* function.c */
-void install_support_functions(void);
+void install_db_support_functions(const char *db_name);
void uninstall_support_functions(void);
void get_loadable_libraries(void);
void check_loadable_libraries(void);
extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid;
extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
+extern PGDLLIMPORT Oid binary_upgrade_next_pg_authid_oid;
Datum set_next_pg_type_oid(PG_FUNCTION_ARGS);
Datum set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
Datum set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
Datum set_next_pg_enum_oid(PG_FUNCTION_ARGS);
+Datum set_next_pg_authid_oid(PG_FUNCTION_ARGS);
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_class_oid);
PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
+PG_FUNCTION_INFO_V1(set_next_pg_authid_oid);
Datum
PG_RETURN_VOID();
}
+
+Datum
+set_next_pg_authid_oid(PG_FUNCTION_ARGS)
+{
+ Oid authoid = PG_GETARG_OID(0);
+
+ binary_upgrade_next_pg_authid_oid = authoid;
+ PG_RETURN_VOID();
+}
+
#include "utils/syscache.h"
#include "utils/tqual.h"
+/* Potentially set by contrib/pg_upgrade_support functions */
+Oid binary_upgrade_next_pg_authid_oid = InvalidOid;
+
/* GUC parameter */
extern bool Password_encryption;
tuple = heap_form_tuple(pg_authid_dsc, new_record, new_record_nulls);
+ /*
+ * pg_largeobject_metadata contains pg_authid.oid's, so we
+ * use the binary-upgrade override, if specified.
+ */
+ if (OidIsValid(binary_upgrade_next_pg_authid_oid))
+ {
+ HeapTupleSetOid(tuple, binary_upgrade_next_pg_authid_oid);
+ binary_upgrade_next_pg_authid_oid = InvalidOid;
+ }
+
/*
* Insert new record in the pg_authid table
*/
{
PQExpBuffer buf = createPQExpBuffer();
PGresult *res;
- int i_rolname,
+ int i_oid,
+ i_rolname,
i_rolsuper,
i_rolinherit,
i_rolcreaterole,
/* note: rolconfig is dumped later */
if (server_version >= 90100)
printfPQExpBuffer(buf,
- "SELECT rolname, rolsuper, rolinherit, "
+ "SELECT oid, rolname, rolsuper, rolinherit, "
"rolcreaterole, rolcreatedb, rolcatupdate, "
"rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, rolreplication, "
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
"FROM pg_authid "
- "ORDER BY 1");
+ "ORDER BY 2");
else if (server_version >= 80200)
printfPQExpBuffer(buf,
- "SELECT rolname, rolsuper, rolinherit, "
+ "SELECT oid, rolname, rolsuper, rolinherit, "
"rolcreaterole, rolcreatedb, rolcatupdate, "
"rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, false as rolreplication, "
"pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment "
"FROM pg_authid "
- "ORDER BY 1");
+ "ORDER BY 2");
else if (server_version >= 80100)
printfPQExpBuffer(buf,
- "SELECT rolname, rolsuper, rolinherit, "
+ "SELECT oid, rolname, rolsuper, rolinherit, "
"rolcreaterole, rolcreatedb, rolcatupdate, "
"rolcanlogin, rolconnlimit, rolpassword, "
"rolvaliduntil, false as rolreplication, "
"null as rolcomment "
"FROM pg_authid "
- "ORDER BY 1");
+ "ORDER BY 2");
else
printfPQExpBuffer(buf,
- "SELECT usename as rolname, "
+ "SELECT 0, usename as rolname, "
"usesuper as rolsuper, "
"true as rolinherit, "
"usesuper as rolcreaterole, "
"null as rolcomment "
"FROM pg_shadow "
"UNION ALL "
- "SELECT groname as rolname, "
+ "SELECT 0, groname as rolname, "
"false as rolsuper, "
"true as rolinherit, "
"false as rolcreaterole, "
"FROM pg_group "
"WHERE NOT EXISTS (SELECT 1 FROM pg_shadow "
" WHERE usename = groname) "
- "ORDER BY 1");
+ "ORDER BY 2");
res = executeQuery(conn, buf->data);
+ i_oid = PQfnumber(res, "oid");
i_rolname = PQfnumber(res, "rolname");
i_rolsuper = PQfnumber(res, "rolsuper");
i_rolinherit = PQfnumber(res, "rolinherit");
resetPQExpBuffer(buf);
+ if (binary_upgrade)
+ {
+ Oid auth_oid = atooid(PQgetvalue(res, i, i_oid));
+
+ appendPQExpBuffer(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n");
+ appendPQExpBuffer(buf,
+ "SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n",
+ auth_oid);
+ }
+
/*
* We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
* will acquire the right properties even if it already exists (ie, it