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", 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),
"%s/%s",
188 "tables_using_line.txt");
193 pg_fatal(
"Your installation contains the \"line\" data type in user tables.\n"
194 "This data type changed its internal and input/output format\n"
195 "between your old and new versions so this\n"
196 "cluster cannot currently be upgraded. You can\n"
197 "drop the problem columns and restart the upgrade.\n"
198 "A list of the problem columns is in the file:\n"
224 prep_status(
"Checking for invalid \"unknown\" user columns");
226 snprintf(output_path,
sizeof(output_path),
"%s/%s",
228 "tables_using_unknown.txt");
233 pg_fatal(
"Your installation contains the \"unknown\" data type in user tables.\n"
234 "This data type is no longer allowed in tables, so this\n"
235 "cluster cannot currently be upgraded. You can\n"
236 "drop the problem columns and restart the upgrade.\n"
237 "A list of the problem columns is in the file:\n"
255 char *output_path =
"reindex_hash.sql";
259 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
262 bool db_used =
false;
272 "SELECT n.nspname, c.relname "
273 "FROM pg_catalog.pg_class c, "
274 " pg_catalog.pg_index i, "
275 " pg_catalog.pg_am a, "
276 " pg_catalog.pg_namespace n "
277 "WHERE i.indexrelid = c.oid AND "
278 " c.relam = a.oid AND "
279 " c.relnamespace = n.oid AND "
286 for (rowno = 0; rowno < ntups; rowno++)
291 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
292 pg_fatal(
"could not open file \"%s\": %s", output_path,
300 fputs(connectbuf.
data, script);
304 fprintf(script,
"REINDEX INDEX %s.%s;\n",
312 if (!check_mode && db_used)
316 "UPDATE pg_catalog.pg_index i "
317 "SET indisvalid = false "
318 "FROM pg_catalog.pg_class c, "
319 " pg_catalog.pg_am a, "
320 " pg_catalog.pg_namespace n "
321 "WHERE i.indexrelid = c.oid AND "
322 " c.relam = a.oid AND "
323 " c.relnamespace = n.oid AND "
324 " a.amname = 'hash'"));
338 "Your installation contains hash indexes. These indexes have different\n"
339 "internal formats between your old and new clusters, so they must be\n"
340 "reindexed with the REINDEX command. After upgrading, you will be given\n"
341 "REINDEX instructions.");
344 "Your installation contains hash indexes. These indexes have different\n"
345 "internal formats between your old and new clusters, so they must be\n"
346 "reindexed with the REINDEX command. The file\n"
348 "when executed by psql by the database superuser will recreate all invalid\n"
349 "indexes; until then, none of these indexes will be used.",
369 prep_status(
"Checking for invalid \"sql_identifier\" user columns");
371 snprintf(output_path,
sizeof(output_path),
"%s/%s",
373 "tables_using_sql_identifier.txt");
379 pg_fatal(
"Your installation contains the \"sql_identifier\" data type in user tables.\n"
380 "The on-disk format for this data type has changed, so this\n"
381 "cluster cannot currently be upgraded. You can\n"
382 "drop the problem columns and restart the upgrade.\n"
383 "A list of the problem columns is in the file:\n"
400 char *output_path =
"update_extensions.sql";
404 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
407 bool db_used =
false;
417 "FROM pg_available_extensions "
418 "WHERE installed_version != default_version"
423 for (rowno = 0; rowno < ntups; rowno++)
425 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
426 pg_fatal(
"could not open file \"%s\": %s", output_path,
434 fputs(connectbuf.
data, script);
438 fprintf(script,
"ALTER EXTENSION %s UPDATE;\n",
452 "Your installation contains extensions that should be updated\n"
453 "with the ALTER EXTENSION command. The file\n"
455 "when executed by psql by the database superuser will update\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)
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)