Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 203d8ae

Browse files
committed
pg_upgrade: don't copy/link files for invalid indexes
Now that pg_dump no longer dumps invalid indexes, per commit 683abc7, have pg_upgrade also skip them. Previously pg_upgrade threw an error if invalid indexes existed. Backpatch to 9.2, 9.1, and 9.0 (where pg_upgrade was added to git)
1 parent 22f7b96 commit 203d8ae

File tree

2 files changed

+6
-91
lines changed

2 files changed

+6
-91
lines changed

contrib/pg_upgrade/check.c

-91
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ static void check_is_super_user(ClusterInfo *cluster);
2020
static void check_for_prepared_transactions(ClusterInfo *cluster);
2121
static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster);
2222
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
23-
static void check_for_invalid_indexes(ClusterInfo *cluster);
2423
static void get_bin_version(ClusterInfo *cluster);
2524
static char *get_canonical_locale_name(int category, const char *locale);
2625

@@ -97,7 +96,6 @@ check_and_dump_old_cluster(bool live_check, char **sequence_script_file_name)
9796
check_is_super_user(&old_cluster);
9897
check_for_prepared_transactions(&old_cluster);
9998
check_for_reg_data_type_usage(&old_cluster);
100-
check_for_invalid_indexes(&old_cluster);
10199
check_for_isn_and_int8_passing_mismatch(&old_cluster);
102100

103101
/* old = PG 8.3 checks? */
@@ -956,95 +954,6 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
956954
}
957955

958956

959-
/*
960-
* check_for_invalid_indexes()
961-
*
962-
* CREATE INDEX CONCURRENTLY can create invalid indexes if the index build
963-
* fails. These are dumped as valid indexes by pg_dump, but the
964-
* underlying files are still invalid indexes. This checks to make sure
965-
* no invalid indexes exist, either failed index builds or concurrent
966-
* indexes in the process of being created.
967-
*/
968-
static void
969-
check_for_invalid_indexes(ClusterInfo *cluster)
970-
{
971-
int dbnum;
972-
FILE *script = NULL;
973-
bool found = false;
974-
char output_path[MAXPGPATH];
975-
976-
prep_status("Checking for invalid indexes from concurrent index builds");
977-
978-
snprintf(output_path, sizeof(output_path), "invalid_indexes.txt");
979-
980-
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
981-
{
982-
PGresult *res;
983-
bool db_used = false;
984-
int ntups;
985-
int rowno;
986-
int i_nspname,
987-
i_relname;
988-
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
989-
PGconn *conn = connectToServer(cluster, active_db->db_name);
990-
991-
res = executeQueryOrDie(conn,
992-
"SELECT n.nspname, c.relname "
993-
"FROM pg_catalog.pg_class c, "
994-
" pg_catalog.pg_namespace n, "
995-
" pg_catalog.pg_index i "
996-
"WHERE (i.indisvalid = false OR "
997-
" i.indisready = false) AND "
998-
" i.indexrelid = c.oid AND "
999-
" c.relnamespace = n.oid AND "
1000-
/* we do not migrate these, so skip them */
1001-
" n.nspname != 'pg_catalog' AND "
1002-
" n.nspname != 'information_schema' AND "
1003-
/* indexes do not have toast tables */
1004-
" n.nspname != 'pg_toast'");
1005-
1006-
ntups = PQntuples(res);
1007-
i_nspname = PQfnumber(res, "nspname");
1008-
i_relname = PQfnumber(res, "relname");
1009-
for (rowno = 0; rowno < ntups; rowno++)
1010-
{
1011-
found = true;
1012-
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
1013-
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
1014-
output_path, getErrorText(errno));
1015-
if (!db_used)
1016-
{
1017-
fprintf(script, "Database: %s\n", active_db->db_name);
1018-
db_used = true;
1019-
}
1020-
fprintf(script, " %s.%s\n",
1021-
PQgetvalue(res, rowno, i_nspname),
1022-
PQgetvalue(res, rowno, i_relname));
1023-
}
1024-
1025-
PQclear(res);
1026-
1027-
PQfinish(conn);
1028-
}
1029-
1030-
if (script)
1031-
fclose(script);
1032-
1033-
if (found)
1034-
{
1035-
pg_log(PG_REPORT, "fatal\n");
1036-
pg_log(PG_FATAL,
1037-
"Your installation contains invalid indexes due to failed or\n"
1038-
"currently running CREATE INDEX CONCURRENTLY operations. You\n"
1039-
"cannot upgrade until these indexes are valid or removed. A\n"
1040-
"list of the problem indexes is in the file:\n"
1041-
" %s\n\n", output_path);
1042-
}
1043-
else
1044-
check_ok();
1045-
}
1046-
1047-
1048957
static void
1049958
get_bin_version(ClusterInfo *cluster)
1050959
{

contrib/pg_upgrade/info.c

+6
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,13 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
282282
"CREATE TEMPORARY TABLE info_rels (reloid) AS SELECT c.oid "
283283
"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
284284
" ON c.relnamespace = n.oid "
285+
"LEFT OUTER JOIN pg_catalog.pg_index i "
286+
" ON c.oid = i.indexrelid "
285287
"WHERE relkind IN ('r', 'm', 'i'%s) AND "
288+
/* pg_dump only dumps valid indexes; testing indisready is
289+
* necessary in 9.2, and harmless in earlier/later versions. */
290+
" i.indisvalid IS DISTINCT FROM false AND "
291+
" i.indisready IS DISTINCT FROM false AND "
286292
/* exclude possible orphaned temp tables */
287293
" ((n.nspname !~ '^pg_temp_' AND "
288294
" n.nspname !~ '^pg_toast_temp_' AND "

0 commit comments

Comments
 (0)