Skip to content

Commit bb797b6

Browse files
committed
pg_upgrade: error out on 'line' data type usage
The data type internal format changed in 9.4. Also mention this in the 9.4 release notes.
1 parent b23b0f5 commit bb797b6

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

contrib/pg_upgrade/check.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
122122
old_8_3_create_sequence_script(&old_cluster);
123123
}
124124

125+
/* Pre-PG 9.4 had a different 'line' data type internal format */
126+
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 904)
127+
old_9_3_check_for_line_data_type_usage(&old_cluster);
128+
125129
/* Pre-PG 9.0 had no large object permissions */
126130
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
127131
new_9_0_populate_pg_largeobject_metadata(&old_cluster, true);
@@ -914,8 +918,7 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
914918
" 'pg_catalog.regconfig'::pg_catalog.regtype, "
915919
" 'pg_catalog.regdictionary'::pg_catalog.regtype) AND "
916920
" c.relnamespace = n.oid AND "
917-
" n.nspname != 'pg_catalog' AND "
918-
" n.nspname != 'information_schema'");
921+
" n.nspname NOT IN ('pg_catalog', 'information_schema')");
919922

920923
ntups = PQntuples(res);
921924
i_nspname = PQfnumber(res, "nspname");

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ void pg_putenv(const char *var, const char *val);
470470

471471
void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
472472
bool check_mode);
473+
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
473474

474475
/* version_old_8_3.c */
475476

contrib/pg_upgrade/version.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,92 @@ new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
8787
else
8888
check_ok();
8989
}
90+
91+
92+
/*
93+
* old_9_3_check_for_line_data_type_usage()
94+
* 9.3 -> 9.4
95+
* Fully implement the 'line' data type in 9.4, which previously returned
96+
* "not enabled" by default and was only functionally enabled with a
97+
* compile-time switch; 9.4 "line" has different binary and text
98+
* representation formats; checks tables and indexes.
99+
*/
100+
void
101+
old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
102+
{
103+
int dbnum;
104+
FILE *script = NULL;
105+
bool found = false;
106+
char output_path[MAXPGPATH];
107+
108+
prep_status("Checking for invalid \"line\" user columns");
109+
110+
snprintf(output_path, sizeof(output_path), "tables_using_line.txt");
111+
112+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
113+
{
114+
PGresult *res;
115+
bool db_used = false;
116+
int ntups;
117+
int rowno;
118+
int i_nspname,
119+
i_relname,
120+
i_attname;
121+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
122+
PGconn *conn = connectToServer(cluster, active_db->db_name);
123+
124+
res = executeQueryOrDie(conn,
125+
"SELECT n.nspname, c.relname, a.attname "
126+
"FROM pg_catalog.pg_class c, "
127+
" pg_catalog.pg_namespace n, "
128+
" pg_catalog.pg_attribute a "
129+
"WHERE c.oid = a.attrelid AND "
130+
" NOT a.attisdropped AND "
131+
" a.atttypid = 'pg_catalog.line'::pg_catalog.regtype AND "
132+
" c.relnamespace = n.oid AND "
133+
/* exclude possible orphaned temp tables */
134+
" n.nspname !~ '^pg_temp_' AND "
135+
" n.nspname !~ '^pg_toast_temp_' AND "
136+
" n.nspname NOT IN ('pg_catalog', 'information_schema')");
137+
138+
ntups = PQntuples(res);
139+
i_nspname = PQfnumber(res, "nspname");
140+
i_relname = PQfnumber(res, "relname");
141+
i_attname = PQfnumber(res, "attname");
142+
for (rowno = 0; rowno < ntups; rowno++)
143+
{
144+
found = true;
145+
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
146+
pg_fatal("could not open file \"%s\": %s\n", output_path, getErrorText(errno));
147+
if (!db_used)
148+
{
149+
fprintf(script, "Database: %s\n", active_db->db_name);
150+
db_used = true;
151+
}
152+
fprintf(script, " %s.%s.%s\n",
153+
PQgetvalue(res, rowno, i_nspname),
154+
PQgetvalue(res, rowno, i_relname),
155+
PQgetvalue(res, rowno, i_attname));
156+
}
157+
158+
PQclear(res);
159+
160+
PQfinish(conn);
161+
}
162+
163+
if (script)
164+
fclose(script);
165+
166+
if (found)
167+
{
168+
pg_log(PG_REPORT, "fatal\n");
169+
pg_fatal("Your installation contains the \"line\" data type in user tables. This\n"
170+
"data type changed its internal and input/output format between your old\n"
171+
"and new clusters so this cluster cannot currently be upgraded. You can\n"
172+
"remove the problem tables and restart the upgrade. A list of the problem\n"
173+
"columns is in the file:\n"
174+
" %s\n\n", output_path);
175+
}
176+
else
177+
check_ok();
178+
}

doc/src/sgml/release-9.4.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@
12621262
<para>
12631263
The line <emphasis>segment</> data type (<link
12641264
linkend="datatype-lseg"><type>LSEG</></link>) has always been
1265-
fully supported.
1265+
fully supported. The previous <type>line</> data type (enabled
1266+
only via a compile-time option) is not binary or dump-compatible.
12661267
</para>
12671268
</listitem>
12681269

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy