12 #include "catalog/pg_class_d.h"
32 const char *base_query,
33 const char *output_path)
39 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
60 "WITH RECURSIVE oids AS ( "
66 " WITH x AS (SELECT oid FROM oids) "
68 " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typbasetype = x.oid AND typtype = 'd' "
71 " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typelem = x.oid AND typtype = 'b' "
74 " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_class c, pg_catalog.pg_attribute a, x "
75 " WHERE t.typtype = 'c' AND "
76 " t.oid = c.reltype AND "
77 " c.oid = a.attrelid AND "
78 " NOT a.attisdropped AND "
79 " a.atttypid = x.oid "
82 " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x "
83 " WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid"
87 "SELECT n.nspname, c.relname, a.attname "
88 "FROM pg_catalog.pg_class c, "
89 " pg_catalog.pg_namespace n, "
90 " pg_catalog.pg_attribute a "
91 "WHERE c.oid = a.attrelid AND "
92 " NOT a.attisdropped AND "
93 " a.atttypid IN (SELECT oid FROM oids) AND "
98 " c.relnamespace = n.oid AND "
100 " n.nspname !~ '^pg_temp_' AND "
101 " n.nspname !~ '^pg_toast_temp_' AND "
103 " n.nspname NOT IN ('pg_catalog', 'information_schema')",
112 for (rowno = 0; rowno < ntups; rowno++)
115 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
116 pg_fatal(
"could not open file \"%s\": %s\n", output_path,
154 const char *type_name,
155 const char *output_path)
160 base_query =
psprintf(
"SELECT '%s'::pg_catalog.regtype AS oid",
184 prep_status(
"Checking for incompatible \"line\" data type");
186 snprintf(output_path,
sizeof(output_path),
"tables_using_line.txt");
191 pg_fatal(
"Your installation contains the \"line\" data type in user tables.\n"
192 "This data type changed its internal and input/output format\n"
193 "between your old and new versions so this\n"
194 "cluster cannot currently be upgraded. You can\n"
195 "drop the problem columns and restart the upgrade.\n"
196 "A list of the problem columns is in the file:\n"
197 " %s\n\n", output_path);
222 prep_status(
"Checking for invalid \"unknown\" user columns");
224 snprintf(output_path,
sizeof(output_path),
"tables_using_unknown.txt");
229 pg_fatal(
"Your installation contains the \"unknown\" data type in user tables.\n"
230 "This data type is no longer allowed in tables, so this\n"
231 "cluster cannot currently be upgraded. You can\n"
232 "drop the problem columns and restart the upgrade.\n"
233 "A list of the problem columns is in the file:\n"
234 " %s\n\n", output_path);
251 char *output_path =
"reindex_hash.sql";
255 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
258 bool db_used =
false;
268 "SELECT n.nspname, c.relname "
269 "FROM pg_catalog.pg_class c, "
270 " pg_catalog.pg_index i, "
271 " pg_catalog.pg_am a, "
272 " pg_catalog.pg_namespace n "
273 "WHERE i.indexrelid = c.oid AND "
274 " c.relam = a.oid AND "
275 " c.relnamespace = n.oid AND "
282 for (rowno = 0; rowno < ntups; rowno++)
287 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
288 pg_fatal(
"could not open file \"%s\": %s\n", output_path,
296 fputs(connectbuf.
data, script);
300 fprintf(script,
"REINDEX INDEX %s.%s;\n",
308 if (!check_mode && db_used)
312 "UPDATE pg_catalog.pg_index i "
313 "SET indisvalid = false "
314 "FROM pg_catalog.pg_class c, "
315 " pg_catalog.pg_am a, "
316 " pg_catalog.pg_namespace n "
317 "WHERE i.indexrelid = c.oid AND "
318 " c.relam = a.oid AND "
319 " c.relnamespace = n.oid AND "
320 " a.amname = 'hash'"));
334 "Your installation contains hash indexes. These indexes have different\n"
335 "internal formats between your old and new clusters, so they must be\n"
336 "reindexed with the REINDEX command. After upgrading, you will be given\n"
337 "REINDEX instructions.\n\n");
340 "Your installation contains hash indexes. These indexes have different\n"
341 "internal formats between your old and new clusters, so they must be\n"
342 "reindexed with the REINDEX command. The file\n"
344 "when executed by psql by the database superuser will recreate all invalid\n"
345 "indexes; until then, none of these indexes will be used.\n\n",
365 prep_status(
"Checking for invalid \"sql_identifier\" user columns");
367 snprintf(output_path,
sizeof(output_path),
"tables_using_sql_identifier.txt");
373 pg_fatal(
"Your installation contains the \"sql_identifier\" data type in user tables.\n"
374 "The on-disk format for this data type has changed, so this\n"
375 "cluster cannot currently be upgraded. You can\n"
376 "drop the problem columns and restart the upgrade.\n"
377 "A list of the problem columns is in the file:\n"
378 " %s\n\n", output_path);
395 char *output_path =
"update_extensions.sql";
399 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
402 bool db_used =
false;
412 "FROM pg_available_extensions "
413 "WHERE installed_version != default_version"
418 for (rowno = 0; rowno < ntups; rowno++)
422 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
423 pg_fatal(
"could not open file \"%s\": %s\n", output_path,
431 fputs(connectbuf.
data, script);
435 fprintf(script,
"ALTER EXTENSION %s UPDATE;\n",
451 "Your installation contains extensions that should be updated\n"
452 "with the ALTER EXTENSION command. The file\n"
454 "when executed by psql by the database superuser will update\n"
455 "these extensions.\n\n",
bool check_for_data_types_usage(ClusterInfo *cluster, const char *base_query, const char *output_path)
void old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster)
bool check_for_data_type_usage(ClusterInfo *cluster, const char *type_name, const char *output_path)
void report_extension_updates(ClusterInfo *cluster)
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
static void PGresult * res
void PQfinish(PGconn *conn)
void PQclear(PGresult *res)
int PQntuples(const PGresult *res)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
int PQfnumber(const PGresult *res, const char *field_name)
static void check_ok(void)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
#define fopen_priv(path, mode)
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
void prep_status(const char *fmt,...) pg_attribute_printf(1
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
const char * quote_identifier(const char *ident)
void appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)