44 * server checks and output routines
55 *
66 * Copyright (c) 2010, PostgreSQL Global Development Group
7- * $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.13 2010/07/25 03:28:32 momjian Exp $
7+ * $PostgreSQL: pgsql/contrib/pg_upgrade/check.c,v 1.14 2010/07/25 03:47:29 momjian Exp $
88 */
99
1010#include "pg_upgrade.h"
@@ -14,6 +14,8 @@ static void set_locale_and_encoding(migratorContext *ctx, Cluster whichCluster);
1414static void check_new_db_is_empty (migratorContext * ctx );
1515static void check_locale_and_encoding (migratorContext * ctx , ControlData * oldctrl ,
1616 ControlData * newctrl );
17+ static void check_for_isn_and_int8_passing_mismatch (migratorContext * ctx ,
18+ Cluster whichCluster );
1719static void check_for_reg_data_type_usage (migratorContext * ctx , Cluster whichCluster );
1820
1921
@@ -63,11 +65,11 @@ check_old_cluster(migratorContext *ctx, bool live_check,
6365 */
6466
6567 check_for_reg_data_type_usage (ctx , CLUSTER_OLD );
68+ check_for_isn_and_int8_passing_mismatch (ctx , CLUSTER_OLD );
6669
6770 /* old = PG 8.3 checks? */
6871 if (GET_MAJOR_VERSION (ctx -> old .major_version ) <= 803 )
6972 {
70- old_8_3_check_for_isn_and_int8_passing_mismatch (ctx , CLUSTER_OLD );
7173 old_8_3_check_for_name_data_type_usage (ctx , CLUSTER_OLD );
7274 old_8_3_check_for_tsquery_usage (ctx , CLUSTER_OLD );
7375 if (ctx -> check )
@@ -443,6 +445,98 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
443445}
444446
445447
448+ /*
449+ * check_for_isn_and_int8_passing_mismatch()
450+ *
451+ * /contrib/isn relies on data type int8, and in 8.4 int8 can now be passed
452+ * by value. The schema dumps the CREATE TYPE PASSEDBYVALUE setting so
453+ * it must match for the old and new servers.
454+ */
455+ void
456+ check_for_isn_and_int8_passing_mismatch (migratorContext * ctx , Cluster whichCluster )
457+ {
458+ ClusterInfo * active_cluster = (whichCluster == CLUSTER_OLD ) ?
459+ & ctx -> old : & ctx -> new ;
460+ int dbnum ;
461+ FILE * script = NULL ;
462+ bool found = false;
463+ char output_path [MAXPGPATH ];
464+
465+ prep_status (ctx , "Checking for /contrib/isn with bigint-passing mismatch" );
466+
467+ if (ctx -> old .controldata .float8_pass_by_value ==
468+ ctx -> new .controldata .float8_pass_by_value )
469+ {
470+ /* no mismatch */
471+ check_ok (ctx );
472+ return ;
473+ }
474+
475+ snprintf (output_path , sizeof (output_path ), "%s/contrib_isn_and_int8_pass_by_value.txt" ,
476+ ctx -> cwd );
477+
478+ for (dbnum = 0 ; dbnum < active_cluster -> dbarr .ndbs ; dbnum ++ )
479+ {
480+ PGresult * res ;
481+ bool db_used = false;
482+ int ntups ;
483+ int rowno ;
484+ int i_nspname ,
485+ i_proname ;
486+ DbInfo * active_db = & active_cluster -> dbarr .dbs [dbnum ];
487+ PGconn * conn = connectToServer (ctx , active_db -> db_name , whichCluster );
488+
489+ /* Find any functions coming from contrib/isn */
490+ res = executeQueryOrDie (ctx , conn ,
491+ "SELECT n.nspname, p.proname "
492+ "FROM pg_catalog.pg_proc p, "
493+ " pg_catalog.pg_namespace n "
494+ "WHERE p.pronamespace = n.oid AND "
495+ " p.probin = '$libdir/isn'" );
496+
497+ ntups = PQntuples (res );
498+ i_nspname = PQfnumber (res , "nspname" );
499+ i_proname = PQfnumber (res , "proname" );
500+ for (rowno = 0 ; rowno < ntups ; rowno ++ )
501+ {
502+ found = true;
503+ if (script == NULL && (script = fopen (output_path , "w" )) == NULL )
504+ pg_log (ctx , PG_FATAL , "Could not create necessary file: %s\n" , output_path );
505+ if (!db_used )
506+ {
507+ fprintf (script , "Database: %s\n" , active_db -> db_name );
508+ db_used = true;
509+ }
510+ fprintf (script , " %s.%s\n" ,
511+ PQgetvalue (res , rowno , i_nspname ),
512+ PQgetvalue (res , rowno , i_proname ));
513+ }
514+
515+ PQclear (res );
516+
517+ PQfinish (conn );
518+ }
519+
520+ if (found )
521+ {
522+ fclose (script );
523+ pg_log (ctx , PG_REPORT , "fatal\n" );
524+ pg_log (ctx , PG_FATAL ,
525+ "| Your installation contains \"/contrib/isn\" functions\n"
526+ "| which rely on the bigint data type. Your old and\n"
527+ "| new clusters pass bigint values differently so this\n"
528+ "| cluster cannot currently be upgraded. You can\n"
529+ "| manually migrate data that use \"/contrib/isn\"\n"
530+ "| facilities and remove \"/contrib/isn\" from the\n"
531+ "| old cluster and restart the migration. A list\n"
532+ "| of the problem functions is in the file:\n"
533+ "| \t%s\n\n" , output_path );
534+ }
535+ else
536+ check_ok (ctx );
537+ }
538+
539+
446540/*
447541 * check_for_reg_data_type_usage()
448542 * pg_upgrade only preserves these system values:
0 commit comments