Skip to content

Commit 3ced32d

Browse files
committed
In pg_upgrade, disallow migration of 8.3 clusters using contrib/ltree
because its internal format was changed in 8.4. Backpatch to 9.0 and 9.1. Report by depesz, diagnosis by Tom.
1 parent 99155aa commit 3ced32d

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

contrib/pg_upgrade/check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ check_old_cluster(bool live_check, char **sequence_script_file_name)
8181
{
8282
old_8_3_check_for_name_data_type_usage(&old_cluster);
8383
old_8_3_check_for_tsquery_usage(&old_cluster);
84+
old_8_3_check_ltree_usage(&old_cluster);
8485
if (user_opts.check)
8586
{
8687
old_8_3_rebuild_tsvector_tables(&old_cluster, true);

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
411411

412412
void old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster);
413413
void old_8_3_check_for_tsquery_usage(ClusterInfo *cluster);
414+
void old_8_3_check_ltree_usage(ClusterInfo *cluster);
414415
void old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode);
415416
void old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode);
416417
void old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,

contrib/pg_upgrade/version_old_8_3.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,87 @@ old_8_3_check_for_tsquery_usage(ClusterInfo *cluster)
201201
}
202202

203203

204+
/*
205+
* old_8_3_check_ltree_usage()
206+
* 8.3 -> 8.4
207+
* The internal ltree structure was changed in 8.4 so upgrading is impossible.
208+
*/
209+
void
210+
old_8_3_check_ltree_usage(ClusterInfo *cluster)
211+
{
212+
int dbnum;
213+
FILE *script = NULL;
214+
bool found = false;
215+
char output_path[MAXPGPATH];
216+
217+
prep_status("Checking for contrib/ltree");
218+
219+
snprintf(output_path, sizeof(output_path), "%s/contrib_ltree.txt",
220+
os_info.cwd);
221+
222+
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
223+
{
224+
PGresult *res;
225+
bool db_used = false;
226+
int ntups;
227+
int rowno;
228+
int i_nspname,
229+
i_proname;
230+
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
231+
PGconn *conn = connectToServer(cluster, active_db->db_name);
232+
233+
/* Find any functions coming from contrib/ltree */
234+
res = executeQueryOrDie(conn,
235+
"SELECT n.nspname, p.proname "
236+
"FROM pg_catalog.pg_proc p, "
237+
" pg_catalog.pg_namespace n "
238+
"WHERE p.pronamespace = n.oid AND "
239+
" p.probin = '$libdir/ltree'");
240+
241+
ntups = PQntuples(res);
242+
i_nspname = PQfnumber(res, "nspname");
243+
i_proname = PQfnumber(res, "proname");
244+
for (rowno = 0; rowno < ntups; rowno++)
245+
{
246+
found = true;
247+
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
248+
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
249+
output_path, getErrorText(errno));
250+
if (!db_used)
251+
{
252+
fprintf(script, "Database: %s\n", active_db->db_name);
253+
db_used = true;
254+
}
255+
fprintf(script, " %s.%s\n",
256+
PQgetvalue(res, rowno, i_nspname),
257+
PQgetvalue(res, rowno, i_proname));
258+
}
259+
260+
PQclear(res);
261+
262+
PQfinish(conn);
263+
}
264+
265+
if (script)
266+
fclose(script);
267+
268+
if (found)
269+
{
270+
pg_log(PG_REPORT, "fatal\n");
271+
pg_log(PG_FATAL,
272+
"Your installation contains the \"ltree\" data type. This data type\n"
273+
"changed its internal storage format between your old and new clusters so this\n"
274+
"cluster cannot currently be upgraded. You can manually upgrade databases\n"
275+
"that use \"contrib/ltree\" facilities and remove \"contrib/ltree\" from the old\n"
276+
"cluster and restart the upgrade. A list of the problem functions is in the\n"
277+
"file:\n"
278+
" %s\n\n", output_path);
279+
}
280+
else
281+
check_ok();
282+
}
283+
284+
204285
/*
205286
* old_8_3_rebuild_tsvector_tables()
206287
* 8.3 -> 8.4

doc/src/sgml/pgupgrade.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ psql --username postgres --file script.sql postgres
487487
You must drop any such columns and upgrade them manually.
488488
</para>
489489

490+
<para>
491+
pg_upgrade will not work if the <filename>ltree</>
492+
contrib module is installed in a database.
493+
</para>
494+
490495
<para>
491496
pg_upgrade will require a table rebuild if:
492497
<itemizedlist>

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