@@ -23,6 +23,7 @@ static void check_is_super_user(ClusterInfo *cluster);
23
23
static void check_for_prepared_transactions (ClusterInfo * cluster );
24
24
static void check_for_isn_and_int8_passing_mismatch (ClusterInfo * cluster );
25
25
static void check_for_reg_data_type_usage (ClusterInfo * cluster );
26
+ static void check_for_jsonb_9_4_usage (ClusterInfo * cluster );
26
27
static void get_bin_version (ClusterInfo * cluster );
27
28
static char * get_canonical_locale_name (int category , const char * locale );
28
29
@@ -99,6 +100,10 @@ check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
99
100
check_for_reg_data_type_usage (& old_cluster );
100
101
check_for_isn_and_int8_passing_mismatch (& old_cluster );
101
102
103
+ if (GET_MAJOR_VERSION (old_cluster .major_version ) == 904 &&
104
+ old_cluster .controldata .cat_ver < JSONB_FORMAT_CHANGE_CAT_VER )
105
+ check_for_jsonb_9_4_usage (& old_cluster );
106
+
102
107
/* old = PG 8.3 checks? */
103
108
if (GET_MAJOR_VERSION (old_cluster .major_version ) <= 803 )
104
109
{
@@ -964,6 +969,96 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
964
969
}
965
970
966
971
972
+ /*
973
+ * check_for_jsonb_9_4_usage()
974
+ *
975
+ * JSONB changed its storage format during 9.4 beta, so check for it.
976
+ */
977
+ static void
978
+ check_for_jsonb_9_4_usage (ClusterInfo * cluster )
979
+ {
980
+ int dbnum ;
981
+ FILE * script = NULL ;
982
+ bool found = false;
983
+ char output_path [MAXPGPATH ];
984
+
985
+ prep_status ("Checking for JSONB user data types" );
986
+
987
+ snprintf (output_path , sizeof (output_path ), "tables_using_jsonb.txt" );
988
+
989
+ for (dbnum = 0 ; dbnum < cluster -> dbarr .ndbs ; dbnum ++ )
990
+ {
991
+ PGresult * res ;
992
+ bool db_used = false;
993
+ int ntups ;
994
+ int rowno ;
995
+ int i_nspname ,
996
+ i_relname ,
997
+ i_attname ;
998
+ DbInfo * active_db = & cluster -> dbarr .dbs [dbnum ];
999
+ PGconn * conn = connectToServer (cluster , active_db -> db_name );
1000
+
1001
+ /*
1002
+ * While several relkinds don't store any data, e.g. views, they can
1003
+ * be used to define data types of other columns, so we check all
1004
+ * relkinds.
1005
+ */
1006
+ res = executeQueryOrDie (conn ,
1007
+ "SELECT n.nspname, c.relname, a.attname "
1008
+ "FROM pg_catalog.pg_class c, "
1009
+ " pg_catalog.pg_namespace n, "
1010
+ " pg_catalog.pg_attribute a "
1011
+ "WHERE c.oid = a.attrelid AND "
1012
+ " NOT a.attisdropped AND "
1013
+ " a.atttypid = 'pg_catalog.jsonb'::pg_catalog.regtype AND "
1014
+ " c.relnamespace = n.oid AND "
1015
+ /* exclude possible orphaned temp tables */
1016
+ " n.nspname !~ '^pg_temp_' AND "
1017
+ " n.nspname NOT IN ('pg_catalog', 'information_schema')" );
1018
+
1019
+ ntups = PQntuples (res );
1020
+ i_nspname = PQfnumber (res , "nspname" );
1021
+ i_relname = PQfnumber (res , "relname" );
1022
+ i_attname = PQfnumber (res , "attname" );
1023
+ for (rowno = 0 ; rowno < ntups ; rowno ++ )
1024
+ {
1025
+ found = true;
1026
+ if (script == NULL && (script = fopen_priv (output_path , "w" )) == NULL )
1027
+ pg_fatal ("Could not open file \"%s\": %s\n" ,
1028
+ output_path , getErrorText (errno ));
1029
+ if (!db_used )
1030
+ {
1031
+ fprintf (script , "Database: %s\n" , active_db -> db_name );
1032
+ db_used = true;
1033
+ }
1034
+ fprintf (script , " %s.%s.%s\n" ,
1035
+ PQgetvalue (res , rowno , i_nspname ),
1036
+ PQgetvalue (res , rowno , i_relname ),
1037
+ PQgetvalue (res , rowno , i_attname ));
1038
+ }
1039
+
1040
+ PQclear (res );
1041
+
1042
+ PQfinish (conn );
1043
+ }
1044
+
1045
+ if (script )
1046
+ fclose (script );
1047
+
1048
+ if (found )
1049
+ {
1050
+ pg_log (PG_REPORT , "fatal\n" );
1051
+ pg_fatal ("Your installation contains one of the JSONB data types in user tables.\n"
1052
+ "The internal format of JSONB changed during 9.4 beta so this cluster cannot currently\n"
1053
+ "be upgraded. You can remove the problem tables and restart the upgrade. A list\n"
1054
+ "of the problem columns is in the file:\n"
1055
+ " %s\n\n" , output_path );
1056
+ }
1057
+ else
1058
+ check_ok ();
1059
+ }
1060
+
1061
+
967
1062
static void
968
1063
get_bin_version (ClusterInfo * cluster )
969
1064
{
0 commit comments