Skip to content

Commit 427869d

Browse files
authored
Merge pull request #1158 from jiaoshuntian/master_fix_upgrade
Fix the issue where upgrading from PostgreSQL to IvorySQL fails.
2 parents 8cc4944 + 468f90c commit 427869d

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6905,6 +6905,28 @@ getPackages(Archive *fout, int *numPkgs)
69056905
int i_rolname;
69066906
int i_pkgacl;
69076907
int i_acldefault;
6908+
6909+
6910+
/*
6911+
* Check if pg_package table exists. This is needed for pg_upgrade from
6912+
* PostgreSQL to IvorySQL, where the source database is PostgreSQL which
6913+
* doesn't have pg_package table.
6914+
*/
6915+
res = ExecuteSqlQuery(fout,
6916+
"SELECT 1 FROM pg_catalog.pg_class c "
6917+
"JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid "
6918+
"WHERE n.nspname = 'pg_catalog' AND c.relname = 'pg_package'",
6919+
PGRES_TUPLES_OK);
6920+
if (PQntuples(res) == 0)
6921+
{
6922+
/* pg_package table doesn't exist, return empty result */
6923+
PQclear(res);
6924+
destroyPQExpBuffer(query);
6925+
*numPkgs = 0;
6926+
return (PkgInfo *) pg_malloc0(sizeof(PkgInfo));
6927+
}
6928+
PQclear(res);
6929+
69086930
appendPQExpBuffer(query,
69096931
"SELECT p.tableoid, p.pkgname, p.oid, p.pkgnamespace,"
69106932
"p.pkgowner,"
@@ -7142,12 +7164,31 @@ getTables(Archive *fout, int *numTables)
71427164
"d.refobjsubid AS owning_col, "
71437165
"tsp.spcname AS reltablespace, ");
71447166

7145-
if (fout->remoteVersion < 170000)
7146-
appendPQExpBufferStr(query,
7147-
"false AS relhasrowid, ");
7148-
else
7149-
appendPQExpBufferStr(query,
7150-
"c.relhasrowid, ");
7167+
/*
7168+
* Check if relhasrowid column exists. This column is IvorySQL-specific
7169+
* for Oracle ROWID compatibility, and doesn't exist in native PostgreSQL.
7170+
* We need to check at runtime rather than relying on remoteVersion because
7171+
* when upgrading from PostgreSQL to IvorySQL, the source database is
7172+
* PostgreSQL which may have the same version number but lacks this column.
7173+
*/
7174+
{
7175+
PGresult *res_rowid;
7176+
bool relhasrowid_exists = false;
7177+
7178+
res_rowid = ExecuteSqlQuery(fout,
7179+
"SELECT 1 FROM pg_catalog.pg_attribute "
7180+
"WHERE attrelid = 'pg_class'::regclass "
7181+
"AND attname = 'relhasrowid' "
7182+
"AND attnum > 0 LIMIT 1",
7183+
PGRES_TUPLES_OK);
7184+
relhasrowid_exists = (PQntuples(res_rowid) > 0);
7185+
PQclear(res_rowid);
7186+
7187+
if (relhasrowid_exists)
7188+
appendPQExpBufferStr(query, "c.relhasrowid, ");
7189+
else
7190+
appendPQExpBufferStr(query, "false AS relhasrowid, ");
7191+
}
71517192

71527193
if (fout->remoteVersion >= 120000)
71537194
appendPQExpBufferStr(query,
@@ -9232,13 +9273,31 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
92329273
appendPQExpBufferStr(q,
92339274
"'' AS attcompression,\n");
92349275

9235-
if (fout->remoteVersion >= 170000)
9236-
appendPQExpBuffer(q,
9237-
"a.attisinvisible,\n");
9238-
else
9239-
appendPQExpBuffer(q,
9240-
"'f' AS attisinvisible,\n");
9276+
/*
9277+
* Check if attisinvisible column exists. This column is IvorySQL-specific
9278+
* for Oracle compatibility, and doesn't exist in native PostgreSQL.
9279+
* We need to check at runtime rather than relying on remoteVersion because
9280+
* when upgrading from PostgreSQL to IvorySQL, the source database is
9281+
* PostgreSQL which may have the same version number but lacks this column.
9282+
*/
9283+
{
9284+
PGresult *res_invisible;
9285+
bool attisinvisible_exists = false;
92419286

9287+
res_invisible = ExecuteSqlQuery(fout,
9288+
"SELECT 1 FROM pg_catalog.pg_attribute "
9289+
"WHERE attrelid = 'pg_attribute'::regclass "
9290+
"AND attname = 'attisinvisible' "
9291+
"AND attnum > 0 LIMIT 1",
9292+
PGRES_TUPLES_OK);
9293+
attisinvisible_exists = (PQntuples(res_invisible) > 0);
9294+
PQclear(res_invisible);
9295+
9296+
if (attisinvisible_exists)
9297+
appendPQExpBufferStr(q, "a.attisinvisible,\n");
9298+
else
9299+
appendPQExpBufferStr(q, "'f' AS attisinvisible,\n");
9300+
}
92429301

92439302
if (fout->remoteVersion >= 100000)
92449303
appendPQExpBufferStr(q,

src/bin/pg_upgrade/controldata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ get_control_data(ClusterInfo *cluster)
624624
(!got_large_object &&
625625
cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER) ||
626626
!got_date_is_int || !got_data_checksum_version ||
627-
!got_database_mode_is_oracle ||
627+
//!got_database_mode_is_oracle ||
628628
(!got_default_char_signedness &&
629629
cluster->controldata.cat_ver >= DEFAULT_CHAR_SIGNEDNESS_CAT_VER))
630630
{
@@ -767,8 +767,8 @@ check_control_data(ControlData *oldctrl,
767767
else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
768768
pg_fatal("old and new cluster pg_controldata checksum versions do not match");
769769

770-
if (oldctrl->database_mode_is_oracle != newctrl->database_mode_is_oracle)
771-
pg_fatal("old and new pg_controldata database mode do not match\n");
770+
// if (oldctrl->database_mode_is_oracle != newctrl->database_mode_is_oracle)
771+
// pg_fatal("old and new pg_controldata database mode do not match\n");
772772
}
773773

774774

src/bin/pg_upgrade/option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ parseCommandLine(int argc, char *argv[])
115115
if (os_user_effective_id == 0)
116116
pg_fatal("%s: cannot be run as root", os_info.progname);
117117

118-
while ((option = getopt_long(argc, argv, "b:B:cd:D:j:kNo:O:p:P:q:Q:rs:U:v",
119-
long_options, &optindex)) != -1)
118+
while ((option = getopt_long(argc, argv, "b:B:cd:D:gj:kNo:O:p:P:q:Q:rs:U:v",
119+
long_options, &optindex)) != -1)
120120
{
121121
switch (option)
122122
{

0 commit comments

Comments
 (0)