12#include "catalog/pg_authid_d.h"
13#include "catalog/pg_class_d.h"
62#define ALL_VERSIONS -1
112 .report_filename =
"tables_using_composite.txt",
114 "SELECT t.oid FROM pg_catalog.pg_type t "
115 "LEFT JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid "
116 " WHERE typtype = 'c' AND (t.oid < 16384 OR nspname = 'information_schema')",
118 gettext_noop(
"Your installation contains system-defined composite types in user tables.\n"
119 "These type OIDs are not stable across PostgreSQL versions,\n"
120 "so this cluster cannot currently be upgraded. You can drop the\n"
121 "problem columns and restart the upgrade.\n"),
132 .status =
gettext_noop(
"Checking for incompatible \"line\" data type"),
133 .report_filename =
"tables_using_line.txt",
135 "SELECT 'pg_catalog.line'::pg_catalog.regtype AS oid",
137 gettext_noop(
"Your installation contains the \"line\" data type in user tables.\n"
138 "This data type changed its internal and input/output format\n"
139 "between your old and new versions so this\n"
140 "cluster cannot currently be upgraded. You can\n"
141 "drop the problem columns and restart the upgrade.\n"),
142 .threshold_version = 903
154 .status =
gettext_noop(
"Checking for reg* data types in user tables"),
155 .report_filename =
"tables_using_reg.txt",
163 "SELECT oid FROM pg_catalog.pg_type t "
164 "WHERE t.typnamespace = "
165 " (SELECT oid FROM pg_catalog.pg_namespace "
166 " WHERE nspname = 'pg_catalog') "
167 " AND t.typname IN ( "
181 gettext_noop(
"Your installation contains one of the reg* data types in user tables.\n"
182 "These data types reference system OIDs that are not preserved by\n"
183 "pg_upgrade, so this cluster cannot currently be upgraded. You can\n"
184 "drop the problem columns and restart the upgrade.\n"),
193 .status =
gettext_noop(
"Checking for incompatible \"aclitem\" data type"),
194 .report_filename =
"tables_using_aclitem.txt",
196 "SELECT 'pg_catalog.aclitem'::pg_catalog.regtype AS oid",
198 gettext_noop(
"Your installation contains the \"aclitem\" data type in user tables.\n"
199 "The internal format of \"aclitem\" changed in PostgreSQL version 16\n"
200 "so this cluster cannot currently be upgraded. You can drop the\n"
201 "problem columns and restart the upgrade.\n"),
202 .threshold_version = 1500
217 .status =
gettext_noop(
"Checking for invalid \"unknown\" user columns"),
218 .report_filename =
"tables_using_unknown.txt",
220 "SELECT 'pg_catalog.unknown'::pg_catalog.regtype AS oid",
222 gettext_noop(
"Your installation contains the \"unknown\" data type in user tables.\n"
223 "This data type is no longer allowed in tables, so this cluster\n"
224 "cannot currently be upgraded. You can drop the problem columns\n"
225 "and restart the upgrade.\n"),
226 .threshold_version = 906
239 .status =
gettext_noop(
"Checking for invalid \"sql_identifier\" user columns"),
240 .report_filename =
"tables_using_sql_identifier.txt",
242 "SELECT 'information_schema.sql_identifier'::pg_catalog.regtype AS oid",
244 gettext_noop(
"Your installation contains the \"sql_identifier\" data type in user tables.\n"
245 "The on-disk format for this data type has changed, so this\n"
246 "cluster cannot currently be upgraded. You can drop the problem\n"
247 "columns and restart the upgrade.\n"),
248 .threshold_version = 1100
255 .status =
gettext_noop(
"Checking for incompatible \"jsonb\" data type in user tables"),
256 .report_filename =
"tables_using_jsonb.txt",
258 "SELECT 'pg_catalog.jsonb'::pg_catalog.regtype AS oid",
260 gettext_noop(
"Your installation contains the \"jsonb\" data type in user tables.\n"
261 "The internal format of \"jsonb\" changed during 9.4 beta so this\n"
262 "cluster cannot currently be upgraded. You can drop the problem \n"
263 "columns and restart the upgrade.\n"),
272 .status =
gettext_noop(
"Checking for removed \"abstime\" data type in user tables"),
273 .report_filename =
"tables_using_abstime.txt",
275 "SELECT 'pg_catalog.abstime'::pg_catalog.regtype AS oid",
277 gettext_noop(
"Your installation contains the \"abstime\" data type in user tables.\n"
278 "The \"abstime\" type has been removed in PostgreSQL version 12,\n"
279 "so this cluster cannot currently be upgraded. You can drop the\n"
280 "problem columns, or change them to another data type, and restart\n"
282 .threshold_version = 1100
285 .status =
gettext_noop(
"Checking for removed \"reltime\" data type in user tables"),
286 .report_filename =
"tables_using_reltime.txt",
288 "SELECT 'pg_catalog.reltime'::pg_catalog.regtype AS oid",
290 gettext_noop(
"Your installation contains the \"reltime\" data type in user tables.\n"
291 "The \"reltime\" type has been removed in PostgreSQL version 12,\n"
292 "so this cluster cannot currently be upgraded. You can drop the\n"
293 "problem columns, or change them to another data type, and restart\n"
295 .threshold_version = 1100
298 .status =
gettext_noop(
"Checking for removed \"tinterval\" data type in user tables"),
299 .report_filename =
"tables_using_tinterval.txt",
301 "SELECT 'pg_catalog.tinterval'::pg_catalog.regtype AS oid",
303 gettext_noop(
"Your installation contains the \"tinterval\" data type in user tables.\n"
304 "The \"tinterval\" type has been removed in PostgreSQL version 12,\n"
305 "so this cluster cannot currently be upgraded. You can drop the\n"
306 "problem columns, or change them to another data type, and restart\n"
308 .threshold_version = 1100
313 NULL, NULL, NULL, NULL, 0, NULL
336 return psprintf(
"WITH RECURSIVE oids AS ( "
342 " WITH x AS (SELECT oid FROM oids) "
344 " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typbasetype = x.oid AND typtype = 'd' "
347 " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typelem = x.oid AND typtype = 'b' "
350 " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_class c, pg_catalog.pg_attribute a, x "
351 " WHERE t.typtype = 'c' AND "
352 " t.oid = c.reltype AND "
353 " c.oid = a.attrelid AND "
354 " NOT a.attisdropped AND "
355 " a.atttypid = x.oid "
358 " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x "
359 " WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid"
363 "SELECT n.nspname, c.relname, a.attname "
364 "FROM pg_catalog.pg_class c, "
365 " pg_catalog.pg_namespace n, "
366 " pg_catalog.pg_attribute a "
367 "WHERE c.oid = a.attrelid AND "
368 " NOT a.attisdropped AND "
369 " a.atttypid IN (SELECT oid FROM oids) AND "
374 " c.relnamespace = n.oid AND "
376 " n.nspname !~ '^pg_temp_' AND "
377 " n.nspname !~ '^pg_toast_temp_' AND "
379 " n.nspname NOT IN ('pg_catalog', 'information_schema')",
394 int i_nspname =
PQfnumber(res,
"nspname");
395 int i_relname =
PQfnumber(res,
"relname");
396 int i_attname =
PQfnumber(res,
"attname");
404 snprintf(output_path,
sizeof(output_path),
"%s/%s",
406 state->check->report_filename);
412 if (*
state->report == NULL)
423 _(
state->check->report_text),
424 _(
"A list of the problem columns is in the file:"),
427 state->result =
true;
429 if ((script =
fopen_priv(output_path,
"a")) == NULL)
430 pg_fatal(
"could not open file \"%s\": %m", output_path);
434 for (
int rowno = 0; rowno < ntups; rowno++)
467 int n_data_types_usage_checks = 0;
469 char **queries = NULL;
475 while (tmp->
status != NULL)
477 n_data_types_usage_checks++;
482 queries =
pg_malloc0(
sizeof(
char *) * n_data_types_usage_checks);
485 for (
int i = 0;
i < n_data_types_usage_checks;
i++)
530 for (
int i = 0;
i < n_data_types_usage_checks;
i++)
575 "Performing Consistency Checks on Old Live Server\n"
576 "------------------------------------------------");
581 "Performing Consistency Checks\n"
582 "-----------------------------");
745 pg_fatal(
"Swap mode can only upgrade clusters from PostgreSQL version %s and later.",
777 "If pg_upgrade fails after this point, you must re-initdb the\n"
778 "new cluster before continuing.");
817 "Some optimizer statistics may not have been transferred by pg_upgrade.\n"
818 "Once you start the new server, consider running:\n"
819 " %s/vacuumdb %s--all --analyze-in-stages --missing-stats-only",
new_cluster.
bindir, user_specification.
data);
821 if (deletion_script_file_name)
823 "Running this script will delete the old cluster's data files:\n"
825 deletion_script_file_name);
828 "Could not create a script to delete the old cluster's data files\n"
829 "because user-defined tablespaces or the new cluster's data directory\n"
830 "exist in the old cluster directory. The old cluster's contents must\n"
831 "be deleted manually.");
852 pg_fatal(
"This utility can only upgrade from PostgreSQL version %s and later.",
857 pg_fatal(
"This utility can only upgrade to PostgreSQL version %s.",
866 pg_fatal(
"This utility cannot be used to downgrade to older major PostgreSQL versions.");
871 pg_fatal(
"Old cluster data and binary directories are from different major versions.");
874 pg_fatal(
"New cluster data and binary directories are from different major versions.");
885 pg_fatal(
"%s option cannot be used to upgrade from PostgreSQL %s and later.",
886 "--set-char-signedness",
"18");
901 pg_fatal(
"When checking a live server, "
902 "the old and new port numbers must be different.");
916 for (relnum = 0; relnum < rel_arr->
nrels;
920 if (strcmp(rel_arr->
rels[relnum].
nspname,
"pg_catalog") != 0)
921 pg_fatal(
"New cluster database \"%s\" is not empty: found relation \"%s.%s\"",
944 prep_status(
"Checking for new cluster tablespace directories");
954 if (
stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
955 pg_fatal(
"new cluster tablespace directory already exists: \"%s\"",
974 char *old_tblspc_suffix;
976 *deletion_script_file_name =
psprintf(
"%sdelete_old_cluster.%s",
989 "\nWARNING: new data directory should not be inside the old data directory, i.e. %s", old_cluster_pgdata);
992 unlink(*deletion_script_file_name);
993 pg_free(*deletion_script_file_name);
994 *deletion_script_file_name = NULL;
1013 "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
1016 unlink(*deletion_script_file_name);
1017 pg_free(*deletion_script_file_name);
1018 *deletion_script_file_name = NULL;
1023 prep_status(
"Creating script to delete old cluster");
1025 if ((script =
fopen_priv(*deletion_script_file_name,
"w")) == NULL)
1026 pg_fatal(
"could not open file \"%s\": %m",
1027 *deletion_script_file_name);
1031 fprintf(script,
"#!/bin/sh\n\n");
1045 pfree(old_tblspc_suffix);
1050 if (chmod(*deletion_script_file_name,
S_IRWXU) != 0)
1051 pg_fatal(
"could not add execute permission to file \"%s\": %m",
1052 *deletion_script_file_name);
1071 prep_status(
"Checking database user is the install user");
1075 "SELECT rolsuper, oid "
1076 "FROM pg_catalog.pg_roles "
1077 "WHERE rolname = current_user "
1078 "AND rolname !~ '^pg_'");
1087 pg_fatal(
"database user \"%s\" is not the install user",
1094 "FROM pg_catalog.pg_roles "
1095 "WHERE rolname !~ '^pg_'");
1098 pg_fatal(
"could not determine the number of users");
1106 pg_fatal(
"Only the install user can be defined in the new cluster.");
1133 FILE *script = NULL;
1136 prep_status(
"Checking database connection settings");
1138 snprintf(output_path,
sizeof(output_path),
"%s/%s",
1140 "databases_cannot_connect_to.txt");
1146 "SELECT datname, datallowconn, datconnlimit "
1147 "FROM pg_catalog.pg_database");
1149 i_datname =
PQfnumber(dbres,
"datname");
1150 i_datallowconn =
PQfnumber(dbres,
"datallowconn");
1151 i_datconnlimit =
PQfnumber(dbres,
"datconnlimit");
1154 for (dbnum = 0; dbnum < ntups; dbnum++)
1160 if (strcmp(
datname,
"template0") == 0)
1164 pg_fatal(
"template0 must not allow connections, "
1165 "i.e. its pg_database.datallowconn must be false");
1176 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
1177 pg_fatal(
"could not open file \"%s\": %m", output_path);
1192 pg_fatal(
"All non-template0 databases must allow connections, i.e. their\n"
1193 "pg_database.datallowconn must be true and pg_database.datconnlimit\n"
1194 "must not be -2. Your installation contains non-template0 databases\n"
1195 "which cannot be connected to. Consider allowing connection for all\n"
1196 "non-template0 databases or drop the databases which do not allow\n"
1197 "connections. A list of databases with the problem is in the file:\n"
1198 " %s", output_path);
1217 prep_status(
"Checking for prepared transactions");
1221 "FROM pg_catalog.pg_prepared_xacts");
1226 pg_fatal(
"The source cluster contains prepared transactions");
1228 pg_fatal(
"The target cluster contains prepared transactions");
1248 int i_nspname =
PQfnumber(res,
"nspname");
1249 int i_proname =
PQfnumber(res,
"proname");
1258 if (report->
file == NULL &&
1260 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1264 for (
int rowno = 0; rowno < ntups; rowno++)
1282 const char *query =
"SELECT n.nspname, p.proname "
1283 "FROM pg_catalog.pg_proc p, "
1284 " pg_catalog.pg_namespace n "
1285 "WHERE p.pronamespace = n.oid AND "
1286 " p.probin = '$libdir/isn'";
1288 prep_status(
"Checking for contrib/isn with bigint-passing mismatch");
1301 "contrib_isn_and_int8_pass_by_value.txt");
1311 fclose(report.
file);
1313 pg_fatal(
"Your installation contains \"contrib/isn\" functions which rely on the\n"
1314 "bigint data type. Your old and new clusters pass bigint values\n"
1315 "differently so this cluster cannot currently be upgraded. You can\n"
1316 "manually dump databases in the old cluster that use \"contrib/isn\"\n"
1317 "facilities, drop them, perform the upgrade, and then restore them. A\n"
1318 "list of the problem functions is in the file:\n"
1319 " %s", report.
path);
1335 int i_oproid =
PQfnumber(res,
"oproid");
1336 int i_oprnsp =
PQfnumber(res,
"oprnsp");
1337 int i_oprname =
PQfnumber(res,
"oprname");
1338 int i_typnsp =
PQfnumber(res,
"typnsp");
1339 int i_typname =
PQfnumber(res,
"typname");
1347 if (report->
file == NULL &&
1349 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1353 for (
int rowno = 0; rowno < ntups; rowno++)
1354 fprintf(report->
file,
" (oid=%s) %s.%s (%s.%s, NONE)\n",
1378 query =
"SELECT o.oid AS oproid, "
1379 " n.nspname AS oprnsp, "
1381 " tn.nspname AS typnsp, "
1383 "FROM pg_catalog.pg_operator o, "
1384 " pg_catalog.pg_namespace n, "
1385 " pg_catalog.pg_type t, "
1386 " pg_catalog.pg_namespace tn "
1387 "WHERE o.oprnamespace = n.oid AND "
1388 " o.oprleft = t.oid AND "
1389 " t.typnamespace = tn.oid AND "
1390 " o.oprright = 0 AND "
1393 prep_status(
"Checking for user-defined postfix operators");
1407 fclose(report.
file);
1409 pg_fatal(
"Your installation contains user-defined postfix operators, which are not\n"
1410 "supported anymore. Consider dropping the postfix operators and replacing\n"
1411 "them with prefix operators or function calls.\n"
1412 "A list of user-defined postfix operators is in the file:\n"
1413 " %s", report.
path);
1429 int i_objkind =
PQfnumber(res,
"objkind");
1430 int i_objname =
PQfnumber(res,
"objname");
1438 if (report->
file == NULL &&
1440 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1444 for (
int rowno = 0; rowno < ntups; rowno++)
1464 prep_status(
"Checking for incompatible polymorphic functions");
1469 "incompatible_polymorphics.txt");
1475 "'array_append(anyarray,anyelement)'"
1476 ", 'array_cat(anyarray,anyarray)'"
1477 ", 'array_prepend(anyelement,anyarray)'");
1481 ", 'array_remove(anyarray,anyelement)'"
1482 ", 'array_replace(anyarray,anyelement,anyelement)'");
1486 ", 'array_position(anyarray,anyelement)'"
1487 ", 'array_position(anyarray,anyelement,integer)'"
1488 ", 'array_positions(anyarray,anyelement)'"
1489 ", 'width_bucket(anyelement,anyarray)'");
1499 query =
psprintf(
"SELECT 'aggregate' AS objkind, p.oid::regprocedure::text AS objname "
1500 "FROM pg_proc AS p "
1501 "JOIN pg_aggregate AS a ON a.aggfnoid=p.oid "
1502 "JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn "
1503 "WHERE p.oid >= 16384 "
1504 "AND a.aggtransfn = ANY(ARRAY[%s]::regprocedure[]) "
1505 "AND a.aggtranstype = ANY(ARRAY['anyarray', 'anyelement']::regtype[]) "
1509 "SELECT 'aggregate' AS objkind, p.oid::regprocedure::text AS objname "
1510 "FROM pg_proc AS p "
1511 "JOIN pg_aggregate AS a ON a.aggfnoid=p.oid "
1512 "JOIN pg_proc AS finalfn ON finalfn.oid=a.aggfinalfn "
1513 "WHERE p.oid >= 16384 "
1514 "AND a.aggfinalfn = ANY(ARRAY[%s]::regprocedure[]) "
1515 "AND a.aggtranstype = ANY(ARRAY['anyarray', 'anyelement']::regtype[]) "
1519 "SELECT 'operator' AS objkind, op.oid::regoperator::text AS objname "
1520 "FROM pg_operator AS op "
1521 "WHERE op.oid >= 16384 "
1522 "AND oprcode = ANY(ARRAY[%s]::regprocedure[]) "
1523 "AND oprleft = ANY(ARRAY['anyarray', 'anyelement']::regtype[])",
1524 old_polymorphics.
data,
1525 old_polymorphics.
data,
1526 old_polymorphics.
data);
1535 fclose(report.
file);
1537 pg_fatal(
"Your installation contains user-defined objects that refer to internal\n"
1538 "polymorphic functions with arguments of type \"anyarray\" or \"anyelement\".\n"
1539 "These user-defined objects must be dropped before upgrading and restored\n"
1540 "afterwards, changing them to refer to the new corresponding functions with\n"
1541 "arguments of type \"anycompatiblearray\" and \"anycompatible\".\n"
1542 "A list of the problematic objects is in the file:\n"
1543 " %s", report.
path);
1562 int i_nspname =
PQfnumber(res,
"nspname");
1563 int i_relname =
PQfnumber(res,
"relname");
1570 if (report->
file == NULL &&
1572 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1576 for (
int rowno = 0; rowno < ntups; rowno++)
1590 const char *query =
"SELECT n.nspname, c.relname "
1591 "FROM pg_catalog.pg_class c, "
1592 " pg_catalog.pg_namespace n "
1593 "WHERE c.relnamespace = n.oid AND "
1595 " n.nspname NOT IN ('pg_catalog')";
1602 "tables_with_oids.txt");
1611 fclose(report.
file);
1613 pg_fatal(
"Your installation contains tables declared WITH OIDS, which is not\n"
1614 "supported anymore. Consider removing the oid column using\n"
1615 " ALTER TABLE ... SET WITHOUT OIDS;\n"
1616 "A list of tables with the problem is in the file:\n"
1617 " %s", report.
path);
1637 FILE *script = NULL;
1640 prep_status(
"Checking for roles starting with \"pg_\"");
1642 snprintf(output_path,
sizeof(output_path),
"%s/%s",
1644 "pg_role_prefix.txt");
1647 "SELECT oid AS roloid, rolname "
1648 "FROM pg_catalog.pg_roles "
1649 "WHERE rolname ~ '^pg_'");
1654 for (
int rowno = 0; rowno < ntups; rowno++)
1656 if (script == NULL && (script =
fopen_priv(output_path,
"w")) == NULL)
1657 pg_fatal(
"could not open file \"%s\": %m", output_path);
1658 fprintf(script,
"%s (oid=%s)\n",
1671 pg_fatal(
"Your installation contains roles starting with \"pg_\".\n"
1672 "\"pg_\" is a reserved prefix for system roles. The cluster\n"
1673 "cannot be upgraded until these roles are renamed.\n"
1674 "A list of roles starting with \"pg_\" is in the file:\n"
1675 " %s", output_path);
1692 int i_conoid =
PQfnumber(res,
"conoid");
1693 int i_conname =
PQfnumber(res,
"conname");
1694 int i_nspname =
PQfnumber(res,
"nspname");
1702 if (report->
file == NULL &&
1704 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1708 for (
int rowno = 0; rowno < ntups; rowno++)
1725 prep_status(
"Checking for user-defined encoding conversions");
1730 "encoding_conversions.txt");
1738 query =
"SELECT c.oid as conoid, c.conname, n.nspname "
1739 "FROM pg_catalog.pg_conversion c, "
1740 " pg_catalog.pg_namespace n "
1741 "WHERE c.connamespace = n.oid AND "
1752 fclose(report.
file);
1754 pg_fatal(
"Your installation contains user-defined encoding conversions.\n"
1755 "The conversion function parameters changed in PostgreSQL version 14\n"
1756 "so this cluster cannot currently be upgraded. You can remove the\n"
1757 "encoding conversions in the old cluster and restart the upgrade.\n"
1758 "A list of user-defined encoding conversions is in the file:\n"
1759 " %s", report.
path);
1775 int i_reloid =
PQfnumber(res,
"reloid");
1776 int i_nspname =
PQfnumber(res,
"nspname");
1777 int i_relname =
PQfnumber(res,
"relname");
1782 if (report->
file == NULL &&
1784 pg_fatal(
"could not open file \"%s\": %m", report->
path);
1788 for (
int rowno = 0; rowno < ntups; rowno++)
1804 char *old_unicode_version;
1805 bool unicode_updated;
1814 return unicode_updated;
1839 prep_status(
"Checking for objects affected by Unicode update");
1850 "unicode_dependent_rels.txt");
1854 "WITH collations(collid) AS ( "
1855 " SELECT oid FROM pg_collation "
1856 " WHERE collprovider='b' AND colllocale IN ('C.UTF-8','PG_UNICODE_FAST') "
1859 " SELECT 'pg_catalog.default'::regcollation FROM pg_database "
1860 " WHERE datname = current_database() AND "
1861 " datlocprovider='b' AND datlocale IN ('C.UTF-8','PG_UNICODE_FAST') "
1864 "functions(procid) AS ( "
1865 " SELECT proc.oid FROM pg_proc proc "
1866 " WHERE proname IN ('normalize','unicode_assigned','unicode_version','is_normalized') AND "
1867 " pronamespace='pg_catalog'::regnamespace "
1870 "coll_operators(operid, procid, collid) AS ( "
1871 " SELECT oper.oid, oper.oprcode, collid FROM pg_operator oper, collations "
1872 " WHERE oprname IN ('~', '~*', '!~', '!~*', '~~*', '!~~*') AND "
1873 " oprnamespace='pg_catalog'::regnamespace AND "
1874 " oprright='text'::regtype "
1877 "coll_functions(procid, collid) AS ( "
1878 " SELECT proc.oid, collid FROM pg_proc proc, collations "
1879 " WHERE proname IN ('lower','initcap','upper') AND "
1880 " pronamespace='pg_catalog'::regnamespace AND "
1881 " proargtypes[0] = 'text'::regtype "
1884 " SELECT procid, collid FROM coll_operators "
1892 " SELECT '{FUNCEXPR :funcid ' || procid::text || '[ }]' FROM functions "
1894 " SELECT '{OPEXPR :opno ' || operid::text || ' (:\\w+ \\w+ )*' || "
1895 " ':inputcollid ' || collid::text || '[ }]' FROM coll_operators "
1897 " SELECT '{FUNCEXPR :funcid ' || procid::text || ' (:\\w+ \\w+ )*' || "
1898 " ':inputcollid ' || collid::text || '[ }]' FROM coll_functions "
1904 "SELECT reloid, relkind, nspname, relname "
1907 " FROM pg_constraint, patterns WHERE conbin::text ~ p "
1909 " SELECT indexrelid "
1910 " FROM pg_index, patterns WHERE indexprs::text ~ p OR indpred::text ~ p "
1912 " SELECT partrelid "
1913 " FROM pg_partitioned_table, patterns WHERE partexprs::text ~ p "
1916 " FROM pg_rewrite, pg_class, patterns "
1917 " WHERE ev_class = pg_class.oid AND relkind = 'm' AND ev_action::text ~ p"
1918 " ) s(reloid), pg_class c, pg_namespace n, pg_database d "
1919 " WHERE s.reloid = c.oid AND c.relnamespace = n.oid AND "
1920 " d.datname = current_database() AND "
1921 " d.encoding = pg_char_to_encoding('UTF8');";
1932 fclose(report.
file);
1934 pg_log(
PG_WARNING,
"Your installation contains relations that may be affected by a new version of Unicode.\n"
1935 "A list of potentially-affected relations is in the file:\n"
1936 " %s", report.
path);
1965 if (nslots_on_old == 0)
1970 prep_status(
"Checking for new cluster logical replication slots");
1973 "FROM pg_catalog.pg_replication_slots "
1974 "WHERE slot_type = 'logical' AND "
1975 "temporary IS FALSE;");
1978 pg_fatal(
"could not count the number of logical replication slots");
1983 pg_fatal(
"expected 0 logical replication slots but found %d",
1989 "WHERE name IN ('wal_level', 'max_replication_slots') "
1990 "ORDER BY name DESC;");
1993 pg_fatal(
"could not determine parameter settings on new cluster");
1998 pg_fatal(
"\"wal_level\" must be \"logical\" but is set to \"%s\"",
2004 pg_fatal(
"\"max_replication_slots\" (%d) must be greater than or equal to the number of "
2005 "logical replication slots (%d) on the old cluster",
2036 prep_status(
"Checking for new cluster configuration for subscriptions");
2041 "WHERE name = 'max_active_replication_origins';");
2044 pg_fatal(
"could not determine parameter settings on new cluster");
2048 pg_fatal(
"\"max_active_replication_origins\" (%d) must be greater than or equal to the number of "
2049 "subscriptions (%d) on the old cluster",
2068 FILE *script = NULL;
2070 prep_status(
"Checking for valid logical replication slots");
2072 snprintf(output_path,
sizeof(output_path),
"%s/%s",
2074 "invalid_logical_slots.txt");
2080 for (
int slotnum = 0; slotnum < slot_arr->
nslots; slotnum++)
2087 if (script == NULL &&
2088 (script =
fopen_priv(output_path,
"w")) == NULL)
2089 pg_fatal(
"could not open file \"%s\": %m", output_path);
2091 fprintf(script,
"The slot \"%s\" is invalid\n",
2106 if (script == NULL &&
2107 (script =
fopen_priv(output_path,
"w")) == NULL)
2108 pg_fatal(
"could not open file \"%s\": %m", output_path);
2111 "The slot \"%s\" has not consumed the WAL yet\n",
2122 pg_fatal(
"Your installation contains logical replication slots that cannot be upgraded.\n"
2123 "You can remove invalid slots and/or consume the pending WAL for other slots,\n"
2124 "and then restart the upgrade.\n"
2125 "A list of the problematic slots is in the file:\n"
2126 " %s", output_path);
2142 int i_srsubstate =
PQfnumber(res,
"srsubstate");
2143 int i_subname =
PQfnumber(res,
"subname");
2144 int i_nspname =
PQfnumber(res,
"nspname");
2145 int i_relname =
PQfnumber(res,
"relname");
2152 if (report->
file == NULL &&
2154 pg_fatal(
"could not open file \"%s\": %m", report->
path);
2156 for (
int i = 0;
i < ntups;
i++)
2157 fprintf(report->
file,
"The table sync state \"%s\" is not allowed for database:\"%s\" subscription:\"%s\" schema:\"%s\" relation:\"%s\"\n",
2187 "subs_invalid.txt");
2195 "SELECT d.datname, s.subname "
2196 "FROM pg_catalog.pg_subscription s "
2197 "LEFT OUTER JOIN pg_catalog.pg_replication_origin o "
2198 " ON o.roname = 'pg_' || s.oid "
2199 "INNER JOIN pg_catalog.pg_database d "
2200 " ON d.oid = s.subdbid "
2201 "WHERE o.roname IS NULL;");
2203 for (
int i = 0;
i < ntup;
i++)
2205 if (report.
file == NULL &&
2207 pg_fatal(
"could not open file \"%s\": %m", report.
path);
2208 fprintf(report.
file,
"The replication origin is missing for database:\"%s\" subscription:\"%s\"\n",
2243 query =
"SELECT r.srsubstate, s.subname, n.nspname, c.relname "
2244 "FROM pg_catalog.pg_subscription_rel r "
2245 "LEFT JOIN pg_catalog.pg_subscription s"
2246 " ON r.srsubid = s.oid "
2247 "LEFT JOIN pg_catalog.pg_class c"
2248 " ON r.srrelid = c.oid "
2249 "LEFT JOIN pg_catalog.pg_namespace n"
2250 " ON c.relnamespace = n.oid "
2251 "WHERE r.srsubstate NOT IN ('i', 'r') "
2252 "ORDER BY s.subname";
2262 fclose(report.
file);
2264 pg_fatal(
"Your installation contains subscriptions without origin or having relations not in i (initialize) or r (ready) state.\n"
2265 "You can allow the initial sync to finish for all relations and then restart the upgrade.\n"
2266 "A list of the problematic subscriptions is in the file:\n"
2267 " %s", report.
path);
#define AssertVariableIsOfType(varname, typename)
void check_cluster_versions(void)
static void check_for_tables_with_oids(ClusterInfo *cluster)
static void check_for_pg_role_prefix(ClusterInfo *cluster)
static void process_old_sub_state_check(DbInfo *dbinfo, PGresult *res, void *arg)
static void check_for_data_types_usage(ClusterInfo *cluster)
static bool unicode_version_changed(ClusterInfo *cluster)
static char * data_type_check_query(int checknum)
static void process_incompat_polymorphics(DbInfo *dbinfo, PGresult *res, void *arg)
static DataTypesUsageChecks data_types_usage_checks[]
static void process_with_oids_check(DbInfo *dbinfo, PGresult *res, void *arg)
static void check_new_cluster_logical_replication_slots(void)
static void check_old_cluster_subscription_state(void)
void issue_warnings_and_set_wal_level(void)
static void process_unicode_update(DbInfo *dbinfo, PGresult *res, void *arg)
static void check_for_unicode_update(ClusterInfo *cluster)
void check_cluster_compatibility(void)
void check_new_cluster(void)
void report_clusters_compatible(void)
static void check_is_install_user(ClusterInfo *cluster)
static void check_new_cluster_subscription_configuration(void)
void create_script_for_old_cluster_deletion(char **deletion_script_file_name)
static void check_for_connection_status(ClusterInfo *cluster)
static void process_user_defined_encoding_conversions(DbInfo *dbinfo, PGresult *res, void *arg)
static void process_data_type_check(DbInfo *dbinfo, PGresult *res, void *arg)
void check_and_dump_old_cluster(void)
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
static char * fix_path_separator(char *path)
static void check_new_cluster_is_empty(void)
static void check_old_cluster_for_valid_slots(void)
static void process_isn_and_int8_passing_mismatch(DbInfo *dbinfo, PGresult *res, void *arg)
static void check_for_user_defined_postfix_ops(ClusterInfo *cluster)
void output_completion_banner(char *deletion_script_file_name)
static void check_for_prepared_transactions(ClusterInfo *cluster)
static void check_for_new_tablespace_dir(void)
static void check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
static void check_for_incompatible_polymorphics(ClusterInfo *cluster)
void output_check_banner(void)
static void process_user_defined_postfix_ops(DbInfo *dbinfo, PGresult *res, void *arg)
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
void get_control_data(ClusterInfo *cluster)
void check_control_data(ControlData *oldctrl, ControlData *newctrl)
#define fprintf(file, fmt, msg)
void generate_old_dump(void)
void PQfinish(PGconn *conn)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
void PQclear(PGresult *res)
int PQntuples(const PGresult *res)
int PQfnumber(const PGresult *res, const char *field_name)
char * pg_strdup(const char *in)
void * pg_malloc0(size_t size)
void check_file_clone(void)
void check_hard_link(transferMode transfer_mode)
void check_copy_file_range(void)
void check_loadable_libraries(void)
void get_loadable_libraries(void)
Assert(PointerIsAligned(start, uint64))
void get_subscription_count(ClusterInfo *cluster)
int count_old_cluster_logical_slots(void)
void get_db_rel_and_slot_infos(ClusterInfo *cluster)
static void check_ok(void)
void pfree(void *pointer)
int max_active_replication_origins
static pid_t start_postmaster(void)
UpgradeTask * upgrade_task_create(void)
void init_tablespaces(void)
bool(* DataTypesUsageVersionCheck)(ClusterInfo *cluster)
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
bool jsonb_9_4_check_applicable(ClusterInfo *cluster)
void upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster)
void cleanup_output_dirs(void)
void report_extension_updates(ClusterInfo *cluster)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ TRANSFER_MODE_COPY_FILE_RANGE
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
void upgrade_task_free(UpgradeTask *task)
#define fopen_priv(path, mode)
void(* UpgradeTaskProcessCB)(DbInfo *dbinfo, PGresult *res, void *arg)
#define GET_MAJOR_VERSION(v)
void stop_postmaster(bool in_atexit)
void prep_status(const char *fmt,...) pg_attribute_printf(1
void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
void upgrade_task_add_step(UpgradeTask *task, const char *query, UpgradeTaskProcessCB process_cb, bool free_result, void *arg)
bool path_is_prefix_of_path(const char *path1, const char *path2)
void canonicalize_path(char *path)
size_t strlcpy(char *dst, const char *src, size_t siz)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
int max_replication_slots
void appendShellString(PQExpBuffer buf, const char *str)
const char * tablespace_suffix
bool float8_pass_by_value
DataTypesUsageVersionCheck version_hook
const char * report_filename
LogicalSlotInfoArr slot_arr
transferMode transfer_mode
DataTypesUsageChecks * check
#define PG_UNICODE_VERSION