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

Commitfb7890a

Browse files
committed
pg_upgrade: don't copy/link files for invalid indexes
Now that pg_dump no longer dumps invalid indexes, per commit683abc7, have pg_upgrade also skipthem. 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 parent01accb3 commitfb7890a

File tree

2 files changed

+7
-93
lines changed

2 files changed

+7
-93
lines changed

‎contrib/pg_upgrade/check.c‎

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static void check_locale_and_encoding(migratorContext *ctx, ControlData *oldctrl
1717
staticvoidcheck_for_isn_and_int8_passing_mismatch(migratorContext*ctx,
1818
ClusterwhichCluster);
1919
staticvoidcheck_for_reg_data_type_usage(migratorContext*ctx,ClusterwhichCluster);
20-
staticvoidcheck_for_invalid_indexes(migratorContext*ctx,ClusterwhichCluster);
2120

2221

2322
/*
@@ -97,7 +96,6 @@ check_old_cluster(migratorContext *ctx, bool live_check,
9796

9897
check_for_reg_data_type_usage(ctx,CLUSTER_OLD);
9998
check_for_isn_and_int8_passing_mismatch(ctx,CLUSTER_OLD);
100-
check_for_invalid_indexes(ctx,CLUSTER_OLD);
10199

102100
/* old = PG 8.3 checks? */
103101
if (GET_MAJOR_VERSION(ctx->old.major_version) <=803)
@@ -678,93 +676,3 @@ check_for_reg_data_type_usage(migratorContext *ctx, Cluster whichCluster)
678676
else
679677
check_ok(ctx);
680678
}
681-
682-
683-
/*
684-
* check_for_invalid_indexes()
685-
*
686-
*CREATE INDEX CONCURRENTLY can create invalid indexes if the index build
687-
*fails. These are dumped as valid indexes by pg_dump, but the
688-
*underlying files are still invalid indexes. This checks to make sure
689-
*no invalid indexes exist, either failed index builds or concurrent
690-
*indexes in the process of being created.
691-
*/
692-
staticvoid
693-
check_for_invalid_indexes(migratorContext*ctx,ClusterwhichCluster)
694-
{
695-
ClusterInfo*cluster= (whichCluster==CLUSTER_OLD) ?
696-
&ctx->old :&ctx->new;
697-
intdbnum;
698-
FILE*script=NULL;
699-
boolfound= false;
700-
charoutput_path[MAXPGPATH];
701-
702-
prep_status(ctx,"Checking for invalid indexes from concurrent index builds");
703-
704-
snprintf(output_path,sizeof(output_path),"invalid_indexes.txt");
705-
706-
for (dbnum=0;dbnum<cluster->dbarr.ndbs;dbnum++)
707-
{
708-
PGresult*res;
709-
booldb_used= false;
710-
intntups;
711-
introwno;
712-
inti_nspname,
713-
i_relname;
714-
DbInfo*active_db=&cluster->dbarr.dbs[dbnum];
715-
PGconn*conn=connectToServer(ctx,active_db->db_name,whichCluster);
716-
717-
res=executeQueryOrDie(ctx,conn,
718-
"SELECT n.nspname, c.relname "
719-
"FROMpg_catalog.pg_class c, "
720-
"pg_catalog.pg_namespace n, "
721-
"pg_catalog.pg_index i "
722-
"WHERE(i.indisvalid = false OR "
723-
" i.indisready = false) AND "
724-
"i.indexrelid = c.oid AND "
725-
"c.relnamespace = n.oid AND "
726-
/* we do not migrate these, so skip them */
727-
" n.nspname != 'pg_catalog' AND "
728-
"n.nspname != 'information_schema' AND "
729-
/* indexes do not have toast tables */
730-
"n.nspname != 'pg_toast'");
731-
732-
ntups=PQntuples(res);
733-
i_nspname=PQfnumber(res,"nspname");
734-
i_relname=PQfnumber(res,"relname");
735-
for (rowno=0;rowno<ntups;rowno++)
736-
{
737-
found= true;
738-
if (script==NULL&& (script=fopen(output_path,"w"))==NULL)
739-
pg_log(ctx,PG_FATAL,"Could not create necessary file: %s\n",output_path);
740-
if (!db_used)
741-
{
742-
fprintf(script,"Database: %s\n",active_db->db_name);
743-
db_used= true;
744-
}
745-
fprintf(script," %s.%s\n",
746-
PQgetvalue(res,rowno,i_nspname),
747-
PQgetvalue(res,rowno,i_relname));
748-
}
749-
750-
PQclear(res);
751-
752-
PQfinish(conn);
753-
}
754-
755-
if (script)
756-
fclose(script);
757-
758-
if (found)
759-
{
760-
pg_log(ctx,PG_REPORT,"fatal\n");
761-
pg_log(ctx,PG_FATAL,
762-
"Your installation contains invalid indexes due to failed or\n"
763-
"currently running CREATE INDEX CONCURRENTLY operations. You\n"
764-
"cannot upgrade until these indexes are valid or removed. A\n"
765-
"list of the problem indexes is in the file:\n"
766-
" %s\n\n",output_path);
767-
}
768-
else
769-
check_ok(ctx);
770-
}

‎contrib/pg_upgrade/info.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
325325
"FROM pg_catalog.pg_class c JOIN "
326326
"pg_catalog.pg_namespace n "
327327
"ON c.relnamespace = n.oid "
328+
" LEFT OUTER JOIN pg_catalog.pg_index i "
329+
" ON c.oid = i.indexrelid "
328330
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
329331
"ON c.reltablespace = t.oid "
330332
"WHERE (( "
@@ -338,7 +340,11 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
338340
"n.nspname = 'pg_catalog' "
339341
"AND relname IN "
340342
" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
341-
"AND relkind IN ('r','t', 'i'%s)"
343+
"AND relkind IN ('r','t', 'i'%s) "
344+
/* pg_dump only dumps valid indexes; testing indisready is
345+
* necessary in 9.2, and harmless in earlier/later versions. */
346+
" AND i.indisvalid IS DISTINCT FROM false AND "
347+
" i.indisready IS DISTINCT FROM false "
342348
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
343349
"c.reltoastrelid, c.reltablespace, t.spclocation, "
344350
"n.nspname "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp