12 #include "catalog/pg_authid_d.h"
54 for (
c = result; *
c !=
'\0';
c++)
71 "Performing Consistency Checks on Old Live Server\n"
72 "------------------------------------------------\n");
77 "Performing Consistency Checks\n"
78 "-----------------------------\n");
217 "If pg_upgrade fails after this point, you must re-initdb the\n"
218 "new cluster before continuing.\n");
257 "Optimizer statistics are not transferred by pg_upgrade.\n"
258 "Once you start the new server, consider running:\n"
261 if (deletion_script_file_name)
263 "Running this script will delete the old cluster's data files:\n"
265 deletion_script_file_name);
268 "Could not create a script to delete the old cluster's data files\n"
269 "because user-defined tablespaces or the new cluster's data directory\n"
270 "exist in the old cluster directory. The old cluster's contents must\n"
271 "be deleted manually.\n");
292 pg_fatal(
"This utility can only upgrade from PostgreSQL version 9.2 and later.\n");
296 pg_fatal(
"This utility can only upgrade to PostgreSQL version %s.\n",
305 pg_fatal(
"This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
310 pg_fatal(
"Old cluster data and binary directories are from different major versions.\n");
313 pg_fatal(
"New cluster data and binary directories are from different major versions.\n");
328 pg_fatal(
"When checking a live server, "
329 "the old and new port numbers must be different.\n");
343 pg_fatal(
"encodings for database \"%s\" do not match: old \"%s\", new \"%s\"\n",
348 pg_fatal(
"lc_collate values for database \"%s\" do not match: old \"%s\", new \"%s\"\n",
351 pg_fatal(
"lc_ctype values for database \"%s\" do not match: old \"%s\", new \"%s\"\n",
354 pg_fatal(
"locale providers for database \"%s\" do not match: old \"%s\", new \"%s\"\n",
361 pg_fatal(
"ICU locale values for database \"%s\" do not match: old \"%s\", new \"%s\"\n",
401 chara = strrchr(canona,
'.');
402 lena = chara ? (chara - canona) : strlen(canona);
405 charb = strrchr(canonb,
'.');
406 lenb = charb ? (charb - canonb) : strlen(canonb);
431 for (relnum = 0; relnum < rel_arr->
nrels;
435 if (strcmp(rel_arr->
rels[relnum].
nspname,
"pg_catalog") != 0)
436 pg_fatal(
"New cluster database \"%s\" is not empty: found relation \"%s.%s\"\n",
488 prep_status(
"Checking for new cluster tablespace directories");
498 if (
stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
499 pg_fatal(
"new cluster tablespace directory already exists: \"%s\"\n",
519 *deletion_script_file_name =
psprintf(
"%sdelete_old_cluster.%s",
532 "\nWARNING: new data directory should not be inside the old data directory, e.g. %s\n", old_cluster_pgdata);
535 unlink(*deletion_script_file_name);
536 pg_free(*deletion_script_file_name);
537 *deletion_script_file_name = NULL;
556 "\nWARNING: user-defined tablespace locations should not be inside the data directory, e.g. %s\n", old_tablespace_dir);
559 unlink(*deletion_script_file_name);
560 pg_free(*deletion_script_file_name);
561 *deletion_script_file_name = NULL;
566 prep_status(
"Creating script to delete old cluster");
568 if ((script =
fopen_priv(*deletion_script_file_name,
"w")) == NULL)
569 pg_fatal(
"could not open file \"%s\": %s\n",
570 *deletion_script_file_name,
strerror(errno));
574 fprintf(script,
"#!/bin/sh\n\n");
619 if (chmod(*deletion_script_file_name,
S_IRWXU) != 0)
620 pg_fatal(
"could not add execute permission to file \"%s\": %s\n",
621 *deletion_script_file_name,
strerror(errno));
640 prep_status(
"Checking database user is the install user");
644 "SELECT rolsuper, oid "
645 "FROM pg_catalog.pg_roles "
646 "WHERE rolname = current_user "
647 "AND rolname !~ '^pg_'");
656 pg_fatal(
"database user \"%s\" is not the install user\n",
663 "FROM pg_catalog.pg_roles "
664 "WHERE rolname !~ '^pg_'");
667 pg_fatal(
"could not determine the number of users\n");
675 pg_fatal(
"Only the install user can be defined in the new cluster.\n");
705 prep_status(
"Checking database connection settings");
707 snprintf(output_path,
sizeof(output_path),
"%s/%s",
709 "databases_with_datallowconn_false.txt");
715 "SELECT datname, datallowconn "
716 "FROM pg_catalog.pg_database");
719 i_datallowconn =
PQfnumber(dbres,
"datallowconn");
722 for (dbnum = 0; dbnum < ntups; dbnum++)
727 if (strcmp(
datname,
"template0") == 0)
731 pg_fatal(
"template0 must not allow connections, "
732 "i.e. its pg_database.datallowconn must be false\n");
743 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
744 pg_fatal(
"could not open file \"%s\": %s\n",
762 pg_fatal(
"All non-template0 databases must allow connections, i.e. their\n"
763 "pg_database.datallowconn must be true. Your installation contains\n"
764 "non-template0 databases with their pg_database.datallowconn set to\n"
765 "false. Consider allowing connection for all non-template0 databases\n"
766 "or drop the databases which do not allow connections. A list of\n"
767 "databases with the problem is in the file:\n"
768 " %s\n\n", output_path);
791 "FROM pg_catalog.pg_prepared_xacts");
796 pg_fatal(
"The source cluster contains prepared transactions\n");
798 pg_fatal(
"The target cluster contains prepared transactions\n");
824 prep_status(
"Checking for contrib/isn with bigint-passing mismatch");
834 snprintf(output_path,
sizeof(output_path),
"%s/%s",
836 "contrib_isn_and_int8_pass_by_value.txt");
838 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
841 bool db_used =
false;
851 "SELECT n.nspname, p.proname "
852 "FROM pg_catalog.pg_proc p, "
853 " pg_catalog.pg_namespace n "
854 "WHERE p.pronamespace = n.oid AND "
855 " p.probin = '$libdir/isn'");
860 for (rowno = 0; rowno < ntups; rowno++)
863 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
864 pg_fatal(
"could not open file \"%s\": %s\n",
887 pg_fatal(
"Your installation contains \"contrib/isn\" functions which rely on the\n"
888 "bigint data type. Your old and new clusters pass bigint values\n"
889 "differently so this cluster cannot currently be upgraded. You can\n"
890 "manually dump databases in the old cluster that use \"contrib/isn\"\n"
891 "facilities, drop them, perform the upgrade, and then restore them. A\n"
892 "list of the problem functions is in the file:\n"
893 " %s\n\n", output_path);
910 prep_status(
"Checking for user-defined postfix operators");
912 snprintf(output_path,
sizeof(output_path),
"%s/%s",
917 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
920 bool db_used =
false;
938 "SELECT o.oid AS oproid, "
939 " n.nspname AS oprnsp, "
941 " tn.nspname AS typnsp, "
943 "FROM pg_catalog.pg_operator o, "
944 " pg_catalog.pg_namespace n, "
945 " pg_catalog.pg_type t, "
946 " pg_catalog.pg_namespace tn "
947 "WHERE o.oprnamespace = n.oid AND "
948 " o.oprleft = t.oid AND "
949 " t.typnamespace = tn.oid AND "
950 " o.oprright = 0 AND "
958 for (rowno = 0; rowno < ntups; rowno++)
961 if (script == NULL &&
962 (script =
fopen_priv(output_path,
"w")) == NULL)
963 pg_fatal(
"could not open file \"%s\": %s\n",
970 fprintf(script,
" (oid=%s) %s.%s (%s.%s, NONE)\n",
989 pg_fatal(
"Your installation contains user-defined postfix operators, which are not\n"
990 "supported anymore. Consider dropping the postfix operators and replacing\n"
991 "them with prefix operators or function calls.\n"
992 "A list of user-defined postfix operators is in the file:\n"
993 " %s\n\n", output_path);
1006 FILE *script = NULL;
1012 snprintf(output_path,
sizeof(output_path),
"%s/%s",
1014 "tables_with_oids.txt");
1017 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
1020 bool db_used =
false;
1029 "SELECT n.nspname, c.relname "
1030 "FROM pg_catalog.pg_class c, "
1031 " pg_catalog.pg_namespace n "
1032 "WHERE c.relnamespace = n.oid AND "
1034 " n.nspname NOT IN ('pg_catalog')");
1039 for (rowno = 0; rowno < ntups; rowno++)
1042 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
1043 pg_fatal(
"could not open file \"%s\": %s\n",
1066 pg_fatal(
"Your installation contains tables declared WITH OIDS, which is not\n"
1067 "supported anymore. Consider removing the oid column using\n"
1068 " ALTER TABLE ... SET WITHOUT OIDS;\n"
1069 "A list of tables with the problem is in the file:\n"
1070 " %s\n\n", output_path);
1094 prep_status(
"Checking for system-defined composite types in user tables");
1096 snprintf(output_path,
sizeof(output_path),
"tables_using_composite.txt");
1109 firstUserOid = 16384;
1111 base_query =
psprintf(
"SELECT t.oid FROM pg_catalog.pg_type t "
1112 "LEFT JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid "
1113 " WHERE typtype = 'c' AND (t.oid < %u OR nspname = 'information_schema')",
1123 pg_fatal(
"Your installation contains system-defined composite type(s) in user tables.\n"
1124 "These type OIDs are not stable across PostgreSQL versions,\n"
1125 "so this cluster cannot currently be upgraded. You can\n"
1126 "drop the problem columns and restart the upgrade.\n"
1127 "A list of the problem columns is in the file:\n"
1128 " %s\n\n", output_path);
1151 prep_status(
"Checking for reg* data types in user tables");
1153 snprintf(output_path,
sizeof(output_path),
"tables_using_reg.txt");
1160 "SELECT oid FROM pg_catalog.pg_type t "
1161 "WHERE t.typnamespace = "
1162 " (SELECT oid FROM pg_catalog.pg_namespace "
1163 " WHERE nspname = 'pg_catalog') "
1164 " AND t.typname IN ( "
1168 " 'regdictionary', "
1182 pg_fatal(
"Your installation contains one of the reg* data types in user tables.\n"
1183 "These data types reference system OIDs that are not preserved by\n"
1184 "pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
1185 "drop the problem columns and restart the upgrade.\n"
1186 "A list of the problem columns is in the file:\n"
1187 " %s\n\n", output_path);
1204 prep_status(
"Checking for incompatible \"jsonb\" data type");
1206 snprintf(output_path,
sizeof(output_path),
"tables_using_jsonb.txt");
1211 pg_fatal(
"Your installation contains the \"jsonb\" data type in user tables.\n"
1212 "The internal format of \"jsonb\" changed during 9.4 beta so this\n"
1213 "cluster cannot currently be upgraded. You can\n"
1214 "drop the problem columns and restart the upgrade.\n"
1215 "A list of the problem columns is in the file:\n"
1216 " %s\n\n", output_path);
1233 prep_status(
"Checking for roles starting with \"pg_\"");
1237 "FROM pg_catalog.pg_roles "
1238 "WHERE rolname ~ '^pg_'");
1243 pg_fatal(
"The source cluster contains roles starting with \"pg_\"\n");
1245 pg_fatal(
"The target cluster contains roles starting with \"pg_\"\n");
1262 FILE *script = NULL;
1266 prep_status(
"Checking for user-defined encoding conversions");
1268 snprintf(output_path,
sizeof(output_path),
"%s/%s",
1270 "encoding_conversions.txt");
1273 for (dbnum = 0; dbnum <
cluster->dbarr.ndbs; dbnum++)
1276 bool db_used =
false;
1292 "SELECT c.oid as conoid, c.conname, n.nspname "
1293 "FROM pg_catalog.pg_conversion c, "
1294 " pg_catalog.pg_namespace n "
1295 "WHERE c.connamespace = n.oid AND "
1301 for (rowno = 0; rowno < ntups; rowno++)
1304 if (script == NULL &&
1305 (script =
fopen_priv(output_path,
"w")) == NULL)
1306 pg_fatal(
"could not open file \"%s\": %s\n",
1313 fprintf(script,
" (oid=%s) %s.%s\n",
1330 pg_fatal(
"Your installation contains user-defined encoding conversions.\n"
1331 "The conversion function parameters changed in PostgreSQL version 14\n"
1332 "so this cluster cannot currently be upgraded. You can remove the\n"
1333 "encoding conversions in the old cluster and restart the upgrade.\n"
1334 "A list of user-defined encoding conversions is in the file:\n"
1335 " %s\n\n", output_path);
1357 pg_fatal(
"failed to get the current locale\n");
1366 pg_fatal(
"failed to get system locale name for \"%s\"\n",
locale);
1372 pg_fatal(
"failed to restore old locale \"%s\"\n", save);
void output_check_banner(bool live_check)
void check_cluster_versions(void)
static char * get_canonical_locale_name(int category, const char *locale)
static void check_for_tables_with_oids(ClusterInfo *cluster)
static void check_for_pg_role_prefix(ClusterInfo *cluster)
static void check_locale_and_encoding(DbInfo *olddb, DbInfo *newdb)
void check_cluster_compatibility(bool live_check)
static void check_for_composite_data_type_usage(ClusterInfo *cluster)
void check_and_dump_old_cluster(bool live_check)
void issue_warnings_and_set_wal_level(void)
static char * fix_path_separator(char *path)
static void check_databases_are_compatible(void)
void check_new_cluster(void)
void report_clusters_compatible(void)
static void check_is_install_user(ClusterInfo *cluster)
void create_script_for_old_cluster_deletion(char **deletion_script_file_name)
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
static void check_new_cluster_is_empty(void)
static bool equivalent_locale(int category, const char *loca, const char *locb)
static void check_for_user_defined_postfix_ops(ClusterInfo *cluster)
static void check_for_new_tablespace_dir(ClusterInfo *new_cluster)
void output_completion_banner(char *deletion_script_file_name)
static void check_for_prepared_transactions(ClusterInfo *cluster)
static void check_proper_datallowconn(ClusterInfo *cluster)
static void check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
static void check_for_jsonb_9_4_usage(ClusterInfo *cluster)
static void check_for_reg_data_type_usage(ClusterInfo *cluster)
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
void get_control_data(ClusterInfo *cluster, bool live_check)
void check_control_data(ControlData *oldctrl, ControlData *newctrl)
static void PGresult * res
void generate_old_dump(void)
const char * pg_encoding_to_char(int encoding)
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)
char * pg_strdup(const char *in)
void check_file_clone(void)
void check_hard_link(void)
void check_loadable_libraries(void)
void get_loadable_libraries(void)
void get_db_and_rel_infos(ClusterInfo *cluster)
static void check_ok(void)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
static pgpid_t start_postmaster(void)
void init_tablespaces(void)
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 void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
#define fopen_priv(path, mode)
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
#define GET_MAJOR_VERSION(v)
void stop_postmaster(bool in_atexit)
void prep_status(const char *fmt,...) pg_attribute_printf(1
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
#define JSONB_FORMAT_CHANGE_CAT_VER
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
bool path_is_prefix_of_path(const char *path1, const char *path2)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
void appendShellString(PQExpBuffer buf, const char *str)
const char * tablespace_suffix
bool float8_pass_by_value
transferMode transfer_mode