Skip to content

Commit c04e74d

Browse files
authored
Merge pull request #1157 from jiaoshuntian/ivy5_fix_upgrade
Fix the issue where upgrading from PostgreSQL to IvorySQL fails.
2 parents 91b43c3 + 2bd8e68 commit c04e74d

3 files changed

Lines changed: 76 additions & 17 deletions

File tree

src/bin/pg_dump/pg_dump.c

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6958,6 +6958,28 @@ getPackages(Archive *fout, int *numPkgs)
69586958
int i_rolname;
69596959
int i_pkgacl;
69606960
int i_acldefault;
6961+
6962+
6963+
/*
6964+
* Check if pg_package table exists. This is needed for pg_upgrade from
6965+
* PostgreSQL to IvorySQL, where the source database is PostgreSQL which
6966+
* doesn't have pg_package table.
6967+
*/
6968+
res = ExecuteSqlQuery(fout,
6969+
"SELECT 1 FROM pg_catalog.pg_class c "
6970+
"JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid "
6971+
"WHERE n.nspname = 'pg_catalog' AND c.relname = 'pg_package'",
6972+
PGRES_TUPLES_OK);
6973+
if (PQntuples(res) == 0)
6974+
{
6975+
/* pg_package table doesn't exist, return empty result */
6976+
PQclear(res);
6977+
destroyPQExpBuffer(query);
6978+
*numPkgs = 0;
6979+
return (PkgInfo *) pg_malloc0(sizeof(PkgInfo));
6980+
}
6981+
PQclear(res);
6982+
69616983
appendPQExpBuffer(query,
69626984
"SELECT p.tableoid, p.pkgname, p.oid, p.pkgnamespace,"
69636985
"p.pkgowner,"
@@ -7195,12 +7217,31 @@ getTables(Archive *fout, int *numTables)
71957217
"d.refobjsubid AS owning_col, "
71967218
"tsp.spcname AS reltablespace, ");
71977219

7198-
if (fout->remoteVersion < 180000)
7199-
appendPQExpBufferStr(query,
7200-
"false AS relhasrowid, ");
7201-
else
7202-
appendPQExpBufferStr(query,
7203-
"c.relhasrowid, ");
7220+
/*
7221+
* Check if relhasrowid column exists. This column is IvorySQL-specific
7222+
* for Oracle ROWID compatibility, and doesn't exist in native PostgreSQL.
7223+
* We need to check at runtime rather than relying on remoteVersion because
7224+
* when upgrading from PostgreSQL to IvorySQL, the source database is
7225+
* PostgreSQL which may have the same version number but lacks this column.
7226+
*/
7227+
{
7228+
PGresult *res_rowid;
7229+
bool relhasrowid_exists = false;
7230+
7231+
res_rowid = ExecuteSqlQuery(fout,
7232+
"SELECT 1 FROM pg_catalog.pg_attribute "
7233+
"WHERE attrelid = 'pg_class'::regclass "
7234+
"AND attname = 'relhasrowid' "
7235+
"AND attnum > 0 LIMIT 1",
7236+
PGRES_TUPLES_OK);
7237+
relhasrowid_exists = (PQntuples(res_rowid) > 0);
7238+
PQclear(res_rowid);
7239+
7240+
if (relhasrowid_exists)
7241+
appendPQExpBufferStr(query, "c.relhasrowid, ");
7242+
else
7243+
appendPQExpBufferStr(query, "false AS relhasrowid, ");
7244+
}
72047245

72057246
if (fout->remoteVersion >= 120000)
72067247
appendPQExpBufferStr(query,
@@ -9309,13 +9350,31 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
93099350
appendPQExpBufferStr(q,
93109351
"'' AS attcompression,\n");
93119352

9312-
if (fout->remoteVersion >= 170000)
9313-
appendPQExpBuffer(q,
9314-
"a.attisinvisible,\n");
9315-
else
9316-
appendPQExpBuffer(q,
9317-
"'f' AS attisinvisible,\n");
9353+
/*
9354+
* Check if attisinvisible column exists. This column is IvorySQL-specific
9355+
* for Oracle compatibility, and doesn't exist in native PostgreSQL.
9356+
* We need to check at runtime rather than relying on remoteVersion because
9357+
* when upgrading from PostgreSQL to IvorySQL, the source database is
9358+
* PostgreSQL which may have the same version number but lacks this column.
9359+
*/
9360+
{
9361+
PGresult *res_invisible;
9362+
bool attisinvisible_exists = false;
93189363

9364+
res_invisible = ExecuteSqlQuery(fout,
9365+
"SELECT 1 FROM pg_catalog.pg_attribute "
9366+
"WHERE attrelid = 'pg_attribute'::regclass "
9367+
"AND attname = 'attisinvisible' "
9368+
"AND attnum > 0 LIMIT 1",
9369+
PGRES_TUPLES_OK);
9370+
attisinvisible_exists = (PQntuples(res_invisible) > 0);
9371+
PQclear(res_invisible);
9372+
9373+
if (attisinvisible_exists)
9374+
appendPQExpBufferStr(q, "a.attisinvisible,\n");
9375+
else
9376+
appendPQExpBufferStr(q, "'f' AS attisinvisible,\n");
9377+
}
93199378

93209379
if (fout->remoteVersion >= 100000)
93219380
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)