72
68
end_progress_output();
78
* It is possible for there to be a mismatch in the need for TOAST tables
79
* between the old and new servers, e.g. some pre-9.1 tables didn't need
80
* TOAST tables but will need them in 9.1+. (There are also opposite cases,
81
* but these are handled by setting binary_upgrade_next_toast_pg_class_oid.)
83
* We can't allow the TOAST table to be created by pg_dump with a
84
* pg_dump-assigned oid because it might conflict with a later table that
85
* uses that oid, causing a "file exists" error for pg_class conflicts, and
86
* a "duplicate oid" error for pg_type conflicts. (TOAST tables need pg_type
89
* Therefore, a backend in binary-upgrade mode will not create a TOAST
90
* table unless an OID as passed in via pg_upgrade_support functions.
91
* This function is called after the restore and uses ALTER TABLE to
92
* auto-create any needed TOAST tables which will not conflict with
96
optionally_create_toast_tables(void)
100
prep_status("Creating newly-required TOAST tables");
102
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
109
DbInfo *active_db = &new_cluster.dbarr.dbs[dbnum];
110
PGconn *conn = connectToServer(&new_cluster, active_db->db_name);
112
res = executeQueryOrDie(conn,
113
"SELECT n.nspname, c.relname "
114
"FROM pg_catalog.pg_class c, "
115
" pg_catalog.pg_namespace n "
116
"WHERE c.relnamespace = n.oid AND "
117
" n.nspname NOT IN ('pg_catalog', 'information_schema') AND "
118
"c.relkind IN ('r', 'm') AND "
119
"c.reltoastrelid = 0");
121
ntups = PQntuples(res);
122
i_nspname = PQfnumber(res, "nspname");
123
i_relname = PQfnumber(res, "relname");
124
for (rowno = 0; rowno < ntups; rowno++)
126
/* enable auto-oid-numbered TOAST creation if needed */
127
PQclear(executeQueryOrDie(conn, "SELECT binary_upgrade.set_next_toast_pg_class_oid('%d'::pg_catalog.oid);",
128
OPTIONALLY_CREATE_TOAST_OID));
130
/* dummy command that also triggers check for required TOAST table */
131
PQclear(executeQueryOrDie(conn, "ALTER TABLE %s.%s RESET (binary_upgrade_dummy_option);",
132
quote_identifier(PQgetvalue(res, rowno, i_nspname)),
133
quote_identifier(PQgetvalue(res, rowno, i_relname))));