diff --git a/doc/src/sgml/ref/repack.sgml b/doc/src/sgml/ref/repack.sgml
index 3ba037848f6..346cba89c90 100644
--- a/doc/src/sgml/ref/repack.sgml
+++ b/doc/src/sgml/ref/repack.sgml
@@ -384,6 +384,12 @@ REPACK [ ( option [, ...] ) ] USING
on the table.
+
+ REPACK refuses to process a table on which an invalid
+ index exists. Such indexes must be dropped or reindexed by the user ahead
+ of time.
+
+
While REPACK is running, the is temporarily changed to pg_catalog,
diff --git a/src/backend/commands/repack.c b/src/backend/commands/repack.c
index 609e2c1d77e..33d243424a3 100644
--- a/src/backend/commands/repack.c
+++ b/src/backend/commands/repack.c
@@ -886,13 +886,15 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
/*
* check_index_requirements: verify index state on relation being processed
*
- * Throw an error if any !indisready indexes are found.
+ * Throw an error if any incompletely-built indexes are found.
*
* Indexes that are not ready for inserts, such as ones left behind by failed
- * CREATE INDEX CONCURRENTLY, are not maintained by DML. In some cases they
- * may fail to build altogether. Throwing an error here forces the user to
- * take action on these indexes separately from the table reconstruction,
- * which prevents perpetuating them for no reason.
+ * CREATE INDEX CONCURRENTLY, are not maintained by DML. Indexes that aren't
+ * marked valid could have been in the middle of validation when their build
+ * failed, and thus it's not certain that they could be built. In both cases,
+ * attempting to rebuild may fail altogether. Throwing an error here forces
+ * the user to take action on these indexes separately from the table
+ * reconstruction, which prevents perpetuating them for no reason.
*/
static void
check_index_requirements(Relation rel, RepackCommand cmd)
@@ -920,9 +922,8 @@ check_index_requirements(Relation rel, RepackCommand cmd)
{
Form_pg_index index = (Form_pg_index) GETSTRUCT(htup);
- if (!index->indisready)
+ if (!index->indisvalid)
{
- Assert(!index->indisvalid);
if (num_invalid_idxs == 0)
appendStringInfo(&dest, _("\"%s\""), get_rel_name(index->indexrelid));
else