Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f13100

Browse files
committed
pg_upgrade: have pg_upgrade fail for old 9.4 JSONB format
Backpatch through 9.4
1 parentf6b7d4f commit6f13100

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static void check_is_super_user(ClusterInfo *cluster);
2323
staticvoidcheck_for_prepared_transactions(ClusterInfo*cluster);
2424
staticvoidcheck_for_isn_and_int8_passing_mismatch(ClusterInfo*cluster);
2525
staticvoidcheck_for_reg_data_type_usage(ClusterInfo*cluster);
26+
staticvoidcheck_for_jsonb_9_4_usage(ClusterInfo*cluster);
2627
staticvoidget_bin_version(ClusterInfo*cluster);
2728
staticchar*get_canonical_locale_name(intcategory,constchar*locale);
2829

@@ -99,6 +100,10 @@ check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
99100
check_for_reg_data_type_usage(&old_cluster);
100101
check_for_isn_and_int8_passing_mismatch(&old_cluster);
101102

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+
102107
/* old = PG 8.3 checks? */
103108
if (GET_MAJOR_VERSION(old_cluster.major_version) <=803)
104109
{
@@ -964,6 +969,96 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
964969
}
965970

966971

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+
staticvoid
978+
check_for_jsonb_9_4_usage(ClusterInfo*cluster)
979+
{
980+
intdbnum;
981+
FILE*script=NULL;
982+
boolfound= false;
983+
charoutput_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+
booldb_used= false;
993+
intntups;
994+
introwno;
995+
inti_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+
"FROMpg_catalog.pg_class c, "
1009+
"pg_catalog.pg_namespace n, "
1010+
"pg_catalog.pg_attribute a "
1011+
"WHEREc.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+
9671062
staticvoid
9681063
get_bin_version(ClusterInfo*cluster)
9691064
{

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ extern char *output_files[];
107107
*/
108108
#defineVISIBILITY_MAP_CRASHSAFE_CAT_VER 201107031
109109

110+
/*
111+
* change in JSONB format during 9.4 beta
112+
*/
113+
#defineJSONB_FORMAT_CHANGE_CAT_VER 201409291
114+
110115
/*
111116
* pg_multixact format changed in 9.3 commit 0ac5ad5134f2769ccbaefec73844f85,
112117
* ("Improve concurrency of foreign key locking") which also updated catalog

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp