Skip to content

Commit af9f6cd

Browse files
committed
pg_upgrade: check for types removed in pg12
Commit cda6a8d removed a few datatypes, but didn't update pg_upgrade --check to throw error if these types are used. So the users find that pg_upgrade --check tells them that everything is fine, only to fail when the real upgrade is attempted. Reviewed-by: Tristan Partin <tristan@neon.tech> Reviewed-by: Suraj Kharage <suraj.kharage@enterprisedb.com> Discussion: https://postgr.es/m/202309201654.ng4ksea25mti@alvherre.pgsql
1 parent 82314db commit af9f6cd

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
2626
static void check_for_tables_with_oids(ClusterInfo *cluster);
2727
static void check_for_composite_data_type_usage(ClusterInfo *cluster);
2828
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
29+
static void check_for_removed_data_type_usage(ClusterInfo *cluster,
30+
const char *version,
31+
const char *datatype);
2932
static void check_for_jsonb_9_4_usage(ClusterInfo *cluster);
3033
static void check_for_pg_role_prefix(ClusterInfo *cluster);
3134
static void check_for_new_tablespace_dir(ClusterInfo *new_cluster);
@@ -104,6 +107,16 @@ check_and_dump_old_cluster(bool live_check)
104107
check_for_reg_data_type_usage(&old_cluster);
105108
check_for_isn_and_int8_passing_mismatch(&old_cluster);
106109

110+
/*
111+
* PG 12 removed types abstime, reltime, tinterval.
112+
*/
113+
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1100)
114+
{
115+
check_for_removed_data_type_usage(&old_cluster, "12", "abstime");
116+
check_for_removed_data_type_usage(&old_cluster, "12", "reltime");
117+
check_for_removed_data_type_usage(&old_cluster, "12", "tinterval");
118+
}
119+
107120
/*
108121
* Pre-PG 12 allowed tables to be declared WITH OIDS, which is not
109122
* supported anymore. Verify there are none, iff applicable.
@@ -1121,6 +1134,40 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
11211134
check_ok();
11221135
}
11231136

1137+
/*
1138+
* check_for_removed_data_type_usage
1139+
*
1140+
* Check for in-core data types that have been removed. Callers know
1141+
* the exact list.
1142+
*/
1143+
static void
1144+
check_for_removed_data_type_usage(ClusterInfo *cluster, const char *version,
1145+
const char *datatype)
1146+
{
1147+
char output_path[MAXPGPATH];
1148+
char typename[NAMEDATALEN];
1149+
1150+
prep_status("Checking for removed \"%s\" data type in user tables",
1151+
datatype);
1152+
1153+
snprintf(output_path, sizeof(output_path), "tables_using_%s.txt",
1154+
datatype);
1155+
snprintf(typename, sizeof(typename), "pg_catalog.%s", datatype);
1156+
1157+
if (check_for_data_type_usage(cluster, typename, output_path))
1158+
{
1159+
pg_log(PG_REPORT, "fatal");
1160+
pg_fatal("Your installation contains the \"%s\" data type in user tables.\n"
1161+
"The \"%s\" type has been removed in PostgreSQL version %s,\n"
1162+
"so this cluster cannot currently be upgraded. You can drop the\n"
1163+
"problem columns, or change them to another data type, and restart\n"
1164+
"the upgrade. A list of the problem columns is in the file:\n"
1165+
" %s\n\n", datatype, datatype, version, output_path);
1166+
}
1167+
else
1168+
check_ok();
1169+
}
1170+
11241171

11251172
/*
11261173
* check_for_jsonb_9_4_usage()

0 commit comments

Comments
 (0)