/* *DataTypesUsageChecks-definitionsofdatatypechecksfortheoldcluster *inordertodetermineifanupgradecanbeperformed.Seethecommenton *data_types_usage_checksbelowforamoredetaileddescription.
*/ typedefstruct
{ /* Status line to print to the user */ constchar *status; /* Filename to store report to */ constchar *report_filename; /* Query to extract the oid of the datatype */ constchar *base_query; /* Text to store to report in case of error */ constchar *report_text; /* The latest version where the check applies */ int threshold_version; /* A function pointer for determining if the check applies */
DataTypesUsageVersionCheck version_hook;
} DataTypesUsageChecks;
/*-- *Datatypeusagechecks.Eachcheckforproblematicdatatypeusageis *definedinthisarraywithmetadata,SQLqueryforfindingthedatatype *andfunctionalityfordecidingifthecheckisapplicabletotheversion *oftheoldcluster.Thestructmembersaredescribedindetailbelow: * *statusAonelinestringwhichcanbeprintedtotheuserto *informaboutprogress.Shouldnotendwithnewline. *report_filenameThefilenameinwhichthelistofproblemsdetectedby *thecheckwillbeprinted. *base_queryAquerywhichextractstheOidofthedatatypechecked *for. *report_textThetextwhichwillbeprintedtotheusertoexplain *whatthecheckdid,andwhyitfailed.Thetextshould *endwithanewline,anddoesnotneedtorefertothe *report_filenameasthatisautomaticallyappendedto *thereportwiththepathtothelogfolder. *threshold_versionThemajorversionofPostgreSQLforwhichtorunthe *check.Ifftheoldclusterislessthan,orequalto, *thethresholdversionthenthecheckwillbeexecuted. *Iftheoldversionisgreaterthanthethresholdthen *thecheckisskipped.Ifthethreshold_versionisset *toALL_VERSIONSthenitwillberununconditionally, *ifsettoMANUAL_CHECKthentheversion_hookfunction *willbeexecutedinordertodeterminewhetherornot *torun. *version_hookAfunctionpointertoaversioncheckfunctionoftype *DataTypesUsageVersionCheckwhichisusedtodetermine *ifthecheckisapplicabletotheoldcluster.Ifthe *version_hookreturnstruethenthecheckwillberun, *elseitwillbeskipped.Thefunctionwillonlybe *executediffthreshold_versionissettoMANUAL_CHECK.
*/ static DataTypesUsageChecks data_types_usage_checks[] =
{ /* *Lookforcompositetypesthatweremadeduringinitdb*or*belongto *information_schema;that'simportantincaseinformation_schemawas *droppedandreloaded. * *ThecutoffOIDhereshouldmatchthesourcecluster'svalueof *FirstNormalObjectId.WehardcodeitratherthanusingthatC#define *because,ifthat#defineiseverchanged,ourownversion'svalueis *NOTwhattouse.Eventuallywemayneedatestonthesourcecluster's *versiontoselectthecorrectvalue.
*/
{
.status = gettext_noop("Checking for system-defined composite types in user tables"),
.report_filename = "tables_using_composite.txt",
.base_query = "SELECT t.oid FROM pg_catalog.pg_type t " "LEFT JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid " " WHERE typtype = 'c' AND (t.oid < 16384 OR nspname = 'information_schema')",
.report_text =
gettext_noop("Your installation contains system-defined composite types in user tables.\n" "These type OIDs are not stable across PostgreSQL versions,\n" "so this cluster cannot currently be upgraded. You can drop the\n" "problem columns and restart the upgrade.\n"),
.threshold_version = ALL_VERSIONS
},
/* *9.3->9.4Fullyimplementthe'line'datatypein9.4,which *previouslyreturned"notenabled"bydefaultandwasonlyfunctionally *enabledwithacompile-timeswitch;asof9.4"line"hasadifferent *on-diskrepresentationformat.
*/
{
.status = gettext_noop("Checking for incompatible \"line\" data type"),
.report_filename = "tables_using_line.txt",
.base_query = "SELECT 'pg_catalog.line'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"line\" data type in user tables.\n" "This data type changed its internal and input/output format\n" "between your old and new versions so this\n" "cluster cannot currently be upgraded. You can\n" "drop the problem columns and restart the upgrade.\n"),
.threshold_version = 903
},
/* *pg_upgradeonlypreservesthesesystemvalues:pg_class.oidpg_type.oid *pg_enum.oid * *Manyofthereg*datatypesreferencesystemcataloginfothatisnot *preserved,andhencethesedatatypescannotbeusedinusertables *upgradedbypg_upgrade.
*/
{
.status = gettext_noop("Checking for reg* data types in user tables"),
.report_filename = "tables_using_reg.txt",
/* *Note:olderserverswillnothaveallofthesereg*types,sowe *havetowritethequerylikethisratherthandependingoncaststo *regtype.
*/
.base_query = "SELECT oid FROM pg_catalog.pg_type t " "WHERE t.typnamespace = " " (SELECT oid FROM pg_catalog.pg_namespace " " WHERE nspname = 'pg_catalog') " " AND t.typname IN ( " /* pg_class.oid is preserved, so 'regclass' is OK */ " 'regcollation', " " 'regconfig', " " 'regdictionary', " " 'regnamespace', " " 'regoper', " " 'regoperator', " " 'regproc', " " 'regprocedure' " /* pg_authid.oid is preserved, so 'regrole' is OK */ /* pg_type.oid is (mostly) preserved, so 'regtype' is OK */ " )",
.report_text =
gettext_noop("Your installation contains one of the reg* data types in user tables.\n" "These data types reference system OIDs that are not preserved by\n" "pg_upgrade, so this cluster cannot currently be upgraded. You can\n" "drop the problem columns and restart the upgrade.\n"),
.threshold_version = ALL_VERSIONS
},
/* *PG16increasedthesizeofthe'aclitem'type,whichbreaksthe *on-diskformatforexistingdata.
*/
{
.status = gettext_noop("Checking for incompatible \"aclitem\" data type"),
.report_filename = "tables_using_aclitem.txt",
.base_query = "SELECT 'pg_catalog.aclitem'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"aclitem\" data type in user tables.\n" "The internal format of \"aclitem\" changed in PostgreSQL version 16\n" "so this cluster cannot currently be upgraded. You can drop the\n" "problem columns and restart the upgrade.\n"),
.threshold_version = 1500
},
/* *It'snolongerallowedtocreatetablesorviewswith"unknown"-type *columns.Wedonotcomplainaboutviewswithsuchcolumns,because *theyshouldgetsilentlyconvertedto"text"columnsduringtheDDL *dumpandreload;itseemsunlikelytobeworthmakingusersdothatby *hand.However,ifthere'satablewithsuchacolumn,theDDLreload *willfail,soweshouldpre-detectthatratherthanfailing *mid-upgrade.Worse,ifthere'samatviewwithsuchacolumn,theDDL *reloadwillsilentlychangeitto"text"whichwon'tmatchtheon-disk *storage(whichislike"cstring").Sowe*must*rejectthat.
*/
{
.status = gettext_noop("Checking for invalid \"unknown\" user columns"),
.report_filename = "tables_using_unknown.txt",
.base_query = "SELECT 'pg_catalog.unknown'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"unknown\" data type in user tables.\n" "This data type is no longer allowed in tables, so this cluster\n" "cannot currently be upgraded. You can drop the problem columns\n" "and restart the upgrade.\n"),
.threshold_version = 906
},
/* *PG12changedthe'sql_identifier'typestoragetobebasedonname, *notvarchar,whichbreakson-diskformatforexistingdata.Soweneed *topreventupgradewhenusedinuserobjects(tables,indexes,...).In *12,thesql_identifierdatatypewasswitchedfromnametovarchar, *whichdoesaffectthestorage(nameisby-ref,butnotvarlena).This *meansusertablesusingsql_identifierforcolumnsarebrokenbecause *theon-diskformatisdifferent.
*/
{
.status = gettext_noop("Checking for invalid \"sql_identifier\" user columns"),
.report_filename = "tables_using_sql_identifier.txt",
.base_query = "SELECT 'information_schema.sql_identifier'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"sql_identifier\" data type in user tables.\n" "The on-disk format for this data type has changed, so this\n" "cluster cannot currently be upgraded. You can drop the problem\n" "columns and restart the upgrade.\n"),
.threshold_version = 1100
},
/* *JSONBchangeditsstorageformatduring9.4beta,socheckforit.
*/
{
.status = gettext_noop("Checking for incompatible \"jsonb\" data type in user tables"),
.report_filename = "tables_using_jsonb.txt",
.base_query = "SELECT 'pg_catalog.jsonb'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"jsonb\" data type in user tables.\n" "The internal format of \"jsonb\" changed during 9.4 beta so this\n" "cluster cannot currently be upgraded. You can drop the problem \n" "columns and restart the upgrade.\n"),
.threshold_version = MANUAL_CHECK,
.version_hook = jsonb_9_4_check_applicable
},
/* *PG12removedtypesabstime,reltime,tinterval.
*/
{
.status = gettext_noop("Checking for removed \"abstime\" data type in user tables"),
.report_filename = "tables_using_abstime.txt",
.base_query = "SELECT 'pg_catalog.abstime'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"abstime\" data type in user tables.\n" "The \"abstime\" type has been removed in PostgreSQL version 12,\n" "so this cluster cannot currently be upgraded. You can drop the\n" "problem columns, or change them to another data type, and restart\n" "the upgrade.\n"),
.threshold_version = 1100
},
{
.status = gettext_noop("Checking for removed \"reltime\" data type in user tables"),
.report_filename = "tables_using_reltime.txt",
.base_query = "SELECT 'pg_catalog.reltime'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"reltime\" data type in user tables.\n" "The \"reltime\" type has been removed in PostgreSQL version 12,\n" "so this cluster cannot currently be upgraded. You can drop the\n" "problem columns, or change them to another data type, and restart\n" "the upgrade.\n"),
.threshold_version = 1100
},
{
.status = gettext_noop("Checking for removed \"tinterval\" data type in user tables"),
.report_filename = "tables_using_tinterval.txt",
.base_query = "SELECT 'pg_catalog.tinterval'::pg_catalog.regtype AS oid",
.report_text =
gettext_noop("Your installation contains the \"tinterval\" data type in user tables.\n" "The \"tinterval\" type has been removed in PostgreSQL version 12,\n" "so this cluster cannot currently be upgraded. You can drop the\n" "problem columns, or change them to another data type, and restart\n" "the upgrade.\n"),
.threshold_version = 1100
},
/* End of checks marker, must remain last */
{
NULL, NULL, NULL, NULL, 0, NULL
}
};
/* *Privatestateforcheck_for_data_types_usage()'sUpgradeTask.
*/ struct data_type_check_state
{
DataTypesUsageChecks *check; /* the check for this step */ bool result; /* true if check failed for any database */
PQExpBuffer *report; /* buffer for report on failed checks */
};
return psprintf("WITH RECURSIVE oids AS ( " /* start with the type(s) returned by base_query */ " %s " " UNION ALL " " SELECT * FROM ( " /* inner WITH because we can only reference the CTE once */ " WITH x AS (SELECT oid FROM oids) " /* domains on any type selected so far */ " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typbasetype = x.oid AND typtype = 'd' " " UNION ALL " /* arrays over any type selected so far */ " SELECT t.oid FROM pg_catalog.pg_type t, x WHERE typelem = x.oid AND typtype = 'b' " " UNION ALL " /* composite types containing any type selected so far */ " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_class c, pg_catalog.pg_attribute a, x " " WHERE t.typtype = 'c' AND " " t.oid = c.reltype AND " " c.oid = a.attrelid AND " " NOT a.attisdropped AND " " a.atttypid = x.oid " " UNION ALL " /* ranges containing any type selected so far */ " SELECT t.oid FROM pg_catalog.pg_type t, pg_catalog.pg_range r, x " " WHERE t.typtype = 'r' AND r.rngtypid = t.oid AND r.rngsubtype = x.oid" " ) foo " ") " /* now look for stored columns of any such type */ "SELECT n.nspname, c.relname, a.attname " "FROM pg_catalog.pg_class c, " " pg_catalog.pg_namespace n, " " pg_catalog.pg_attribute a " "WHERE c.oid = a.attrelid AND " " NOT a.attisdropped AND " " a.atttypid IN (SELECT oid FROM oids) AND " " c.relkind IN ("
CppAsString2(RELKIND_RELATION) ", "
CppAsString2(RELKIND_MATVIEW) ", "
CppAsString2(RELKIND_INDEX) ") AND " " c.relnamespace = n.oid AND " /* exclude possible orphaned temp tables */ " n.nspname !~ '^pg_temp_' AND " " n.nspname !~ '^pg_toast_temp_' AND " /* exclude system catalogs, too */ " n.nspname NOT IN ('pg_catalog', 'information_schema')",
check->base_query);
}
/* *Ifthisisthefirsttimeweseeanerrorforthecheckinquestion *thenprintastatusmessageofthefailure.
*/ if (!state->result)
{
pg_log(PG_REPORT, "failed check: %s", _(state->check->status));
appendPQExpBuffer(*state->report, "\n%s\n%s\n %s\n",
_(state->check->report_text),
_("A list of the problem columns is in the file:"),
output_path);
}
state->result = true;
if ((script = fopen_priv(output_path, "a")) == NULL)
pg_fatal("could not open file \"%s\": %m", output_path);
fprintf(script, "In database: %s\n", dbinfo->db_name);
/* Gather number of checks to perform */ while (tmp->status != NULL)
{
n_data_types_usage_checks++;
tmp++;
}
/* Allocate memory for queries and for task states */
queries = pg_malloc0(sizeof(char *) * n_data_types_usage_checks);
states = pg_malloc0(sizeof(struct data_type_check_state) * n_data_types_usage_checks);
for (int i = 0; i < n_data_types_usage_checks; i++)
{
DataTypesUsageChecks *check = &data_types_usage_checks[i];
if (check->threshold_version == MANUAL_CHECK)
{
Assert(check->version_hook);
/* *Pre-PG14alloweduserdefinedpostfixoperators,whicharenot *supportedanymore.Verifytherearenone,iffapplicable.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1300)
check_for_user_defined_postfix_ops(&old_cluster);
/* *PG14changedpolymorphicfunctionsfromanyarrayto *anycompatiblearray.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1300)
check_for_incompatible_polymorphics(&old_cluster);
/* *Pre-PG12allowedtablestobedeclaredWITHOIDS,whichisnot *supportedanymore.Verifytherearenone,iffapplicable.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1100)
check_for_tables_with_oids(&old_cluster);
/* *Pre-PG18allowedchildtablestoomitnot-nullconstraintsthattheir *parentscolumnshave,butschemarestorefailsforthem.Verifythere *arenone,iffapplicable.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1800)
check_for_not_null_inheritance(&old_cluster);
/* *Pre-PG10allowedtableswith'unknown'typecolumnsandnonWALlogged *hashindexes
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
{ if (user_opts.check)
old_9_6_invalidate_hash_indexes(&old_cluster, true);
}
/* 9.5 and below should not have roles starting with pg_ */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 905)
check_for_pg_role_prefix(&old_cluster);
/* *Whilenotacheckoption,wedothisnowbecausethisistheonlytime *theoldserverisrunning.
*/ if (!user_opts.check)
generate_old_dump();
if (!user_opts.live_check)
stop_postmaster(false);
}
switch (user_opts.transfer_mode)
{ case TRANSFER_MODE_CLONE:
check_file_clone(); break; case TRANSFER_MODE_COPY: break; case TRANSFER_MODE_COPY_FILE_RANGE:
check_copy_file_range(); break; case TRANSFER_MODE_LINK:
check_hard_link(TRANSFER_MODE_LINK); break; case TRANSFER_MODE_SWAP:
/* *Thereareafewknownissueswithusing--swaptoupgradefrom *versionsolderthan10.Forexample,thesequencetupleformat *changedinv10,andthevisibilitymapformatchangedin9.6. *Whilesuchproblemsarenotinsurmountable(andwemayhaveto *dealwithsimilarproblemsinthefuture,anyway),itdoesn't *seemworththeefforttosupportswapmodeforupgradesfrom *long-unsupportedversions.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) < 1000)
pg_fatal("Swap mode can only upgrade clusters from PostgreSQL version %s and later.", "10");
break;
}
check_is_install_user(&new_cluster);
check_for_prepared_transactions(&new_cluster);
check_for_new_tablespace_dir();
check_new_cluster_logical_replication_slots();
check_new_cluster_subscription_configuration();
}
void
report_clusters_compatible(void)
{ if (user_opts.check)
{
pg_log(PG_REPORT, "\n*Clusters are compatible*"); /* stops new cluster */
stop_postmaster(false);
cleanup_output_dirs(); exit(0);
}
pg_log(PG_REPORT, "\n" "If pg_upgrade fails after this point, you must re-initdb the\n" "new cluster before continuing.");
}
/* Reindex hash indexes for old < 10.0 */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 906)
old_9_6_invalidate_hash_indexes(&new_cluster, false);
pg_log(PG_REPORT, "Some statistics are not transferred by pg_upgrade.\n" "Once you start the new server, consider running these two commands:\n" " %s/vacuumdb %s--all --analyze-in-stages --missing-stats-only\n" " %s/vacuumdb %s--all --analyze-only",
new_cluster.bindir, user_specification.data,
new_cluster.bindir, user_specification.data);
if (deletion_script_file_name)
pg_log(PG_REPORT, "Running this script will delete the old cluster's data files:\n" " %s",
deletion_script_file_name); else
pg_log(PG_REPORT, "Could not create a script to delete the old cluster's data files\n" "because user-defined tablespaces or the new cluster's data directory\n" "exist in the old cluster directory. The old cluster's contents must\n" "be deleted manually.");
if (GET_MAJOR_VERSION(old_cluster.major_version) < 902)
pg_fatal("This utility can only upgrade from PostgreSQL version %s and later.", "9.2");
/* Only current PG version is supported as a target */ if (GET_MAJOR_VERSION(new_cluster.major_version) != GET_MAJOR_VERSION(PG_VERSION_NUM))
pg_fatal("This utility can only upgrade to PostgreSQL version %s.",
PG_MAJORVERSION);
/* *Wecan'tallowdowngradingbecauseweusethetargetpg_dump,and *pg_dumpcannotoperateonnewerdatabaseversions,onlycurrentand *olderversions.
*/ if (old_cluster.major_version > new_cluster.major_version)
pg_fatal("This utility cannot be used to downgrade to older major PostgreSQL versions.");
/* Ensure binaries match the designated data directories */ if (GET_MAJOR_VERSION(old_cluster.major_version) !=
GET_MAJOR_VERSION(old_cluster.bin_version))
pg_fatal("Old cluster data and binary directories are from different major versions."); if (GET_MAJOR_VERSION(new_cluster.major_version) !=
GET_MAJOR_VERSION(new_cluster.bin_version))
pg_fatal("New cluster data and binary directories are from different major versions.");
/* *Sincefromversion18,newlycreateddatabaseclustersalwayshave *'signed'defaultchar-signedness,itmakeslesssensetouse *--set-char-signednessoptionforupgradingfromversion18orlater. *Userswhowanttochangethedefaultcharsignednessofthenew *cluster,theycanusepg_resetwalmanuallybeforetheupgrade.
*/ if (GET_MAJOR_VERSION(old_cluster.major_version) >= 1800 &&
user_opts.char_signedness != -1)
pg_fatal("The option %s cannot be used for upgrades from PostgreSQL %s and later.", "--set-char-signedness", "18");
check_ok();
}
void
check_cluster_compatibility(void)
{ /* get/check pg_control data of servers */
get_control_data(&old_cluster);
get_control_data(&new_cluster);
check_control_data(&old_cluster.controldata, &new_cluster.controldata);
if (user_opts.live_check && old_cluster.port == new_cluster.port)
pg_fatal("When checking a live server, " "the old and new port numbers must be different.");
}
staticvoid
check_new_cluster_is_empty(void)
{ int dbnum;
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
{ int relnum;
RelInfoArr *rel_arr = &new_cluster.dbarr.dbs[dbnum].rel_arr;
for (relnum = 0; relnum < rel_arr->nrels;
relnum++)
{ /* pg_largeobject and its index should be skipped */ if (strcmp(rel_arr->rels[relnum].nspname, "pg_catalog") != 0)
pg_fatal("New cluster database \"%s\" is not empty: found relation \"%s.%s\"",
new_cluster.dbarr.dbs[dbnum].db_name,
rel_arr->rels[relnum].nspname,
rel_arr->rels[relnum].relname);
}
}
}
/* Some people put the new data directory inside the old one. */ if (path_is_prefix_of_path(old_cluster_pgdata, new_cluster_pgdata))
{
pg_log(PG_WARNING, "\nWARNING: new data directory should not be inside the old data directory, i.e. %s", old_cluster_pgdata);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
pg_free(*deletion_script_file_name);
*deletion_script_file_name = NULL; return;
}
strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
canonicalize_path(old_tablespace_dir); if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
{ /* reproduce warning from CREATE TABLESPACE that is in the log */
pg_log(PG_WARNING, "\nWARNING: user-defined tablespace locations should not be inside the data directory, i.e. %s", old_tablespace_dir);
/* Unlink file in case it is left over from a previous run. */
unlink(*deletion_script_file_name);
pg_free(*deletion_script_file_name);
*deletion_script_file_name = NULL; return;
}
}
prep_status("Creating script to delete old cluster");
if ((script = fopen_priv(*deletion_script_file_name, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m",
*deletion_script_file_name);
prep_status("Checking database user is the install user");
/* Can't use pg_authid because only superusers can view it. */
res = executeQueryOrDie(conn, "SELECT rolsuper, oid " "FROM pg_catalog.pg_roles " "WHERE rolname = current_user " "AND rolname !~ '^pg_'");
/* *Weonlyallowtheinstalluserinthenewcluster(seecommentbelow) *andwepreservepg_authid.oid,sothismustbetheinstalluserinthe *oldclustertoo.
*/ if (PQntuples(res) != 1 ||
atooid(PQgetvalue(res, 0, 1)) != BOOTSTRAP_SUPERUSERID)
pg_fatal("database user \"%s\" is not the install user",
os_info.user);
if (PQntuples(res) != 1)
pg_fatal("could not determine the number of users");
/* *Weonlyallowtheinstalluserinthenewclusterbecauseotherdefined *usersmightmatchusersdefinedintheoldclusterandgeneratean *errorduringpg_dumprestore.
*/ if (cluster == &new_cluster && strcmp(PQgetvalue(res, 0, 0), "1") != 0)
pg_fatal("Only the install user can be defined in the new cluster.");
PQclear(res);
PQfinish(conn);
check_ok();
}
/* *check_for_connection_status * *Ensurethatallnon-template0databasesallowconnectionssincethey *otherwisewon'tberestored;andthattemplate0explicitlydoesn'tallow *connectionssinceitwouldmakepg_dumpall--globalsrestorefail.
*/ staticvoid
check_for_connection_status(ClusterInfo *cluster)
{ int dbnum;
PGconn *conn_template1;
PGresult *dbres; int ntups; int i_datname; int i_datallowconn; int i_datconnlimit;
FILE *script = NULL; char output_path[MAXPGPATH];
if (strcmp(datname, "template0") == 0)
{ /* avoid restore failure when pg_dumpall tries to create template0 */ if (strcmp(datallowconn, "t") == 0)
pg_fatal("template0 must not allow connections, " "i.e. its pg_database.datallowconn must be false");
} else
{ /* *Avoiddatallowconn==falsedatabasesfrombeingskippedon *restore,andensurethatnodatabasesaremarkedinvalidwith *datconnlimit==-2.
*/ if ((strcmp(datallowconn, "f") == 0) || strcmp(datconnlimit, "-2") == 0)
{ if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m", output_path);
fprintf(script, "%s\n", datname);
}
}
}
PQclear(dbres);
PQfinish(conn_template1);
if (script)
{
fclose(script);
pg_log(PG_REPORT, "fatal");
pg_fatal("All non-template0 databases must allow connections, i.e. their\n" "pg_database.datallowconn must be true and pg_database.datconnlimit\n" "must not be -2. Your installation contains non-template0 databases\n" "which cannot be connected to. Consider allowing connection for all\n" "non-template0 databases or drop the databases which do not allow\n" "connections. A list of databases with the problem is in the file:\n" " %s", output_path);
} else
check_ok();
}
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains \"contrib/isn\" functions which rely on the\n" "bigint data type. Your old and new clusters pass bigint values\n" "differently so this cluster cannot currently be upgraded. You can\n" "manually dump databases in the old cluster that use \"contrib/isn\"\n" "facilities, drop them, perform the upgrade, and then restore them. A\n" "list of the problem functions is in the file:\n" " %s", report.path);
} else
check_ok();
}
/* *Callbackfunctionforprocessingresultofqueryfor *check_for_user_defined_postfix_ops()'sUpgradeTask.Ifthequeryreturned *anyrows(i.e.,thecheckfailed),writethedetailstothereportfile.
*/ staticvoid
process_user_defined_postfix_ops(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg; int ntups = PQntuples(res); int i_oproid = PQfnumber(res, "oproid"); int i_oprnsp = PQfnumber(res, "oprnsp"); int i_oprname = PQfnumber(res, "oprname"); int i_typnsp = PQfnumber(res, "typnsp"); int i_typname = PQfnumber(res, "typname");
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains user-defined postfix operators, which are not\n" "supported anymore. Consider dropping the postfix operators and replacing\n" "them with prefix operators or function calls.\n" "A list of user-defined postfix operators is in the file:\n" " %s", report.path);
} else
check_ok();
}
/* Aggregate transition functions */
query = psprintf("SELECT 'aggregate' AS objkind, p.oid::regprocedure::text AS objname " "FROM pg_proc AS p " "JOIN pg_aggregate AS a ON a.aggfnoid=p.oid " "JOIN pg_proc AS transfn ON transfn.oid=a.aggtransfn " "WHERE p.oid >= 16384 " "AND a.aggtransfn = ANY(ARRAY[%s]::regprocedure[]) " "AND a.aggtranstype = ANY(ARRAY['anyarray', 'anyelement']::regtype[]) "
/* Aggregate final functions */ "UNION ALL " "SELECT 'aggregate' AS objkind, p.oid::regprocedure::text AS objname " "FROM pg_proc AS p " "JOIN pg_aggregate AS a ON a.aggfnoid=p.oid " "JOIN pg_proc AS finalfn ON finalfn.oid=a.aggfinalfn " "WHERE p.oid >= 16384 " "AND a.aggfinalfn = ANY(ARRAY[%s]::regprocedure[]) " "AND a.aggtranstype = ANY(ARRAY['anyarray', 'anyelement']::regtype[]) "
/* Operators */ "UNION ALL " "SELECT 'operator' AS objkind, op.oid::regoperator::text AS objname " "FROM pg_operator AS op " "WHERE op.oid >= 16384 " "AND oprcode = ANY(ARRAY[%s]::regprocedure[]) " "AND oprleft = ANY(ARRAY['anyarray', 'anyelement']::regtype[])",
old_polymorphics.data,
old_polymorphics.data,
old_polymorphics.data);
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains user-defined objects that refer to internal\n" "polymorphic functions with arguments of type \"anyarray\" or \"anyelement\".\n" "These user-defined objects must be dropped before upgrading and restored\n" "afterwards, changing them to refer to the new corresponding functions with\n" "arguments of type \"anycompatiblearray\" and \"anycompatible\".\n" "A list of the problematic objects is in the file:\n" " %s", report.path);
} else
check_ok();
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains tables declared WITH OIDS, which is not\n" "supported anymore. Consider removing the oid column using\n" " ALTER TABLE ... SET WITHOUT OIDS;\n" "A list of tables with the problem is in the file:\n" " %s", report.path);
} else
check_ok();
}
/* *Callbackfunctionforprocessingresultsofqueryfor *check_for_not_null_inheritance.
*/ staticvoid
process_inconsistent_notnull(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg; int ntups = PQntuples(res); int i_nspname = PQfnumber(res, "nspname"); int i_relname = PQfnumber(res, "relname"); int i_attname = PQfnumber(res, "attname");
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains inconsistent NOT NULL constraints.\n" "If the parent column(s) are NOT NULL, then the child column must\n" "also be marked NOT NULL, or the upgrade will fail.\n" "You can fix this by running\n" " ALTER TABLE tablename ALTER column SET NOT NULL;\n" "on each column listed in the file:\n" " %s", report.path);
} else
check_ok();
}
/* *check_for_pg_role_prefix() * *Versionsolderthan9.6shouldnothaveanypg_*roles
*/ staticvoid
check_for_pg_role_prefix(ClusterInfo *cluster)
{
PGresult *res;
PGconn *conn = connectToServer(cluster, "template1"); int ntups; int i_roloid; int i_rolname;
FILE *script = NULL; char output_path[MAXPGPATH];
prep_status("Checking for roles starting with \"pg_\"");
if (script)
{
fclose(script);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains roles starting with \"pg_\".\n" "\"pg_\" is a reserved prefix for system roles. The cluster\n" "cannot be upgraded until these roles are renamed.\n" "A list of roles starting with \"pg_\" is in the file:\n" " %s", output_path);
} else
check_ok();
}
/* *Callbackfunctionforprocessingresultsofqueryfor *check_for_user_defined_encoding_conversions()'sUpgradeTask.Ifthequery *returnedanyrows(i.e.,thecheckfailed),writethedetailstothereport *file.
*/ staticvoid
process_user_defined_encoding_conversions(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg; int ntups = PQntuples(res); int i_conoid = PQfnumber(res, "conoid"); int i_conname = PQfnumber(res, "conname"); int i_nspname = PQfnumber(res, "nspname");
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains user-defined encoding conversions.\n" "The conversion function parameters changed in PostgreSQL version 14\n" "so this cluster cannot currently be upgraded. You can remove the\n" "encoding conversions in the old cluster and restart the upgrade.\n" "A list of user-defined encoding conversions is in the file:\n" " %s", report.path);
} else
check_ok();
}
/* *Callbackfunctionforprocessingresultsofqueryfor *check_for_unicode_update()'sUpgradeTask.Ifthequeryreturnedanyrows *(i.e.,thecheckfailed),writethedetailstothereportfile.
*/ staticvoid
process_unicode_update(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg; int ntups = PQntuples(res); int i_reloid = PQfnumber(res, "reloid"); int i_nspname = PQfnumber(res, "nspname"); int i_relname = PQfnumber(res, "relname");
if (ntups == 0) return;
if (report->file == NULL &&
(report->file = fopen_priv(report->path, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m", report->path);
fprintf(report->file, "In database: %s\n", dbinfo->db_name);
query = /* collations that use built-in Unicode for character semantics */ "WITH collations(collid) AS ( " " SELECT oid FROM pg_collation " " WHERE collprovider='b' AND colllocale IN ('C.UTF-8','PG_UNICODE_FAST') " /* include default collation, if appropriate */ " UNION " " SELECT 'pg_catalog.default'::regcollation FROM pg_database " " WHERE datname = current_database() AND " " datlocprovider='b' AND datlocale IN ('C.UTF-8','PG_UNICODE_FAST') " "), " /* functions that use built-in Unicode */ "functions(procid) AS ( " " SELECT proc.oid FROM pg_proc proc " " WHERE proname IN ('normalize','unicode_assigned','unicode_version','is_normalized') AND " " pronamespace='pg_catalog'::regnamespace " "), " /* operators that use the input collation for character semantics */ "coll_operators(operid, procid, collid) AS ( " " SELECT oper.oid, oper.oprcode, collid FROM pg_operator oper, collations " " WHERE oprname IN ('~', '~*', '!~', '!~*', '~~*', '!~~*') AND " " oprnamespace='pg_catalog'::regnamespace AND " " oprright='pg_catalog.text'::pg_catalog.regtype " "), " /* functions that use the input collation for character semantics */ "coll_functions(procid, collid) AS ( " " SELECT proc.oid, collid FROM pg_proc proc, collations " " WHERE pronamespace='pg_catalog'::regnamespace AND " " ((proname IN ('lower','initcap','upper','casefold') AND " " pronargs = 1 AND " " proargtypes[0] = 'pg_catalog.text'::pg_catalog.regtype) OR " " (proname = 'substring' AND pronargs = 2 AND " " proargtypes[0] = 'pg_catalog.text'::pg_catalog.regtype AND " " proargtypes[1] = 'pg_catalog.text'::pg_catalog.regtype) OR " " proname LIKE 'regexp_%') " /* include functions behind the operators listed above */ " UNION " " SELECT procid, collid FROM coll_operators " "), "
/* *Matchthepatternsagainstexpressionsusedforrelationcontents.
*/ "SELECT reloid, relkind, nspname, relname " " FROM ( " " SELECT conrelid " " FROM pg_constraint, patterns WHERE conbin::text ~ p " " UNION " " SELECT indexrelid " " FROM pg_index, patterns WHERE indexprs::text ~ p OR indpred::text ~ p " " UNION " " SELECT partrelid " " FROM pg_partitioned_table, patterns WHERE partexprs::text ~ p " " UNION " " SELECT ev_class " " FROM pg_rewrite, pg_class, patterns " " WHERE ev_class = pg_class.oid AND relkind = 'm' AND ev_action::text ~ p" " ) s(reloid), pg_class c, pg_namespace n, pg_database d " " WHERE s.reloid = c.oid AND c.relnamespace = n.oid AND " " d.datname = current_database() AND " " d.encoding = pg_char_to_encoding('UTF8');";
if (report.file)
{
fclose(report.file);
report_status(PG_WARNING, "warning");
pg_log(PG_WARNING, "Your installation contains relations that might be affected by a new version of Unicode.\n" "A list of potentially-affected relations is in the file:\n" " %s", report.path);
} else
check_ok();
}
/* *check_new_cluster_logical_replication_slots() * *Verifythattherearenologicalreplicationslotsonthenewclusterand *thattheparametersettingsnecessaryforcreatingslotsaresufficient.
*/ staticvoid
check_new_cluster_logical_replication_slots(void)
{
PGresult *res;
PGconn *conn; int nslots_on_old; int nslots_on_new; int max_replication_slots; char *wal_level;
/* Logical slots can be migrated since PG17. */ if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1600) return;
if (nslots_on_old > max_replication_slots)
pg_fatal("\"max_replication_slots\" (%d) must be greater than or equal to the number of " "logical replication slots (%d) on the old cluster",
max_replication_slots, nslots_on_old);
res = executeQueryOrDie(conn, "SELECT setting FROM pg_settings " "WHERE name = 'max_active_replication_origins';");
if (PQntuples(res) != 1)
pg_fatal("could not determine parameter settings on new cluster");
max_active_replication_origins = atoi(PQgetvalue(res, 0, 0)); if (old_cluster.nsubs > max_active_replication_origins)
pg_fatal("\"max_active_replication_origins\" (%d) must be greater than or equal to the number of " "subscriptions (%d) on the old cluster",
max_active_replication_origins, old_cluster.nsubs);
/* Is the slot usable? */ if (slot->invalid)
{ if (script == NULL &&
(script = fopen_priv(output_path, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m", output_path);
fprintf(script, "The slot \"%s\" is invalid\n",
slot->slotname);
continue;
}
/* *Doadditionalchecktoensurethatalllogicalreplication *slotshaveconsumedalltheWALbeforeshutdown. * *Note:Thiscanbesatisfiedonlywhentheoldclusterhasbeen *shutdown,soweskipthisforlivechecks.
*/ if (!user_opts.live_check && !slot->caught_up)
{ if (script == NULL &&
(script = fopen_priv(output_path, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m", output_path);
fprintf(script, "The slot \"%s\" has not consumed the WAL yet\n",
slot->slotname);
}
}
}
if (script)
{
fclose(script);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains logical replication slots that cannot be upgraded.\n" "You can remove invalid slots and/or consume the pending WAL for other slots,\n" "and then restart the upgrade.\n" "A list of the problematic slots is in the file:\n" " %s", output_path);
}
check_ok();
}
/* *Callbackfunctionforprocessingresultsofqueryfor *check_old_cluster_subscription_state()'sUpgradeTask.Ifthequeryreturned *anyrows(i.e.,thecheckfailed),writethedetailstothereportfile.
*/ staticvoid
process_old_sub_state_check(DbInfo *dbinfo, PGresult *res, void *arg)
{
UpgradeTaskReport *report = (UpgradeTaskReport *) arg; int ntups = PQntuples(res); int i_srsubstate = PQfnumber(res, "srsubstate"); int i_subname = PQfnumber(res, "subname"); int i_nspname = PQfnumber(res, "nspname"); int i_relname = PQfnumber(res, "relname");
if (report->file == NULL &&
(report->file = fopen_priv(report->path, "w")) == NULL)
pg_fatal("could not open file \"%s\": %m", report->path);
for (int i = 0; i < ntups; i++)
fprintf(report->file, "The table sync state \"%s\" is not allowed for database:\"%s\" subscription:\"%s\" schema:\"%s\" relation:\"%s\"\n",
PQgetvalue(res, i, i_srsubstate),
dbinfo->db_name,
PQgetvalue(res, i, i_subname),
PQgetvalue(res, i, i_nspname),
PQgetvalue(res, i, i_relname));
}
if (report.file)
{
fclose(report.file);
pg_log(PG_REPORT, "fatal");
pg_fatal("Your installation contains subscriptions without origin or having relations not in i (initialize) or r (ready) state.\n" "You can allow the initial sync to finish for all relations and then restart the upgrade.\n" "A list of the problematic subscriptions is in the file:\n" " %s", report.path);
} else
check_ok();
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.59 Sekunden
(vorverarbeitet am 2026-08-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.