Skip to content

Commit 508300e

Browse files
committed
Improve and fix some error handling for REINDEX INDEX/TABLE CONCURRENTLY
This improves the user experience when it comes to restrict several flavors of REINDEX CONCURRENTLY. First, for INDEX, remove a restriction on shared relations as we already check after catalog relations. Then, for TABLE, add a proper error message when attempting to run the command on system catalogs. The code path of CREATE INDEX CONCURRENTLY already complains about that, but if a REINDEX is issued then then the error generated is confusing. While on it, add more tests to check restrictions on catalog indexes and on toast table/index for catalogs. Some error messages are improved, with wording suggestion coming from Tom Lane. Reported-by: Tom Lane Author: Michael Paquier Reviewed-by: Tom Lane Discussion: https://postgr.es/m/23694.1556806002@sss.pgh.pa.us
1 parent 24c19e9 commit 508300e

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/backend/commands/indexcmds.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
27432743

27442744
MemoryContextSwitchTo(oldcontext);
27452745

2746+
/* A system catalog cannot be reindexed concurrently */
2747+
if (IsCatalogRelationOid(relationOid))
2748+
ereport(ERROR,
2749+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2750+
errmsg("cannot reindex a system catalog concurrently")));
2751+
27462752
/* Open relation to get its indexes */
27472753
heapRelation = table_open(relationOid, ShareUpdateExclusiveLock);
27482754

@@ -2756,13 +2762,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
27562762
if (!indexRelation->rd_index->indisvalid)
27572763
ereport(WARNING,
27582764
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2759-
errmsg("cannot reindex concurrently invalid index \"%s.%s\", skipping",
2765+
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
27602766
get_namespace_name(get_rel_namespace(cellOid)),
27612767
get_rel_name(cellOid))));
27622768
else if (indexRelation->rd_index->indisexclusion)
27632769
ereport(WARNING,
27642770
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2765-
errmsg("cannot reindex concurrently exclusion constraint index \"%s.%s\", skipping",
2771+
errmsg("cannot reindex exclusion constraint index \"%s.%s\" concurrently, skipping",
27662772
get_namespace_name(get_rel_namespace(cellOid)),
27672773
get_rel_name(cellOid))));
27682774
else
@@ -2802,7 +2808,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
28022808
if (!indexRelation->rd_index->indisvalid)
28032809
ereport(WARNING,
28042810
(errcode(ERRCODE_INDEX_CORRUPTED),
2805-
errmsg("cannot reindex concurrently invalid index \"%s.%s\", skipping",
2811+
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
28062812
get_namespace_name(get_rel_namespace(cellOid)),
28072813
get_rel_name(cellOid))));
28082814
else
@@ -2831,17 +2837,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
28312837
{
28322838
Oid heapId = IndexGetRelation(relationOid, false);
28332839

2834-
/* A shared relation cannot be reindexed concurrently */
2835-
if (IsSharedRelation(heapId))
2836-
ereport(ERROR,
2837-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2838-
errmsg("concurrent reindex is not supported for shared relations")));
2839-
28402840
/* A system catalog cannot be reindexed concurrently */
28412841
if (IsCatalogRelationOid(heapId))
28422842
ereport(ERROR,
28432843
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2844-
errmsg("concurrent reindex is not supported for catalog relations")));
2844+
errmsg("cannot reindex a system catalog concurrently")));
28452845

28462846
/* Save the list of relation OIDs in private context */
28472847
oldcontext = MemoryContextSwitchTo(private_context);
@@ -2869,7 +2869,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
28692869
/* Return error if type of relation is not supported */
28702870
ereport(ERROR,
28712871
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
2872-
errmsg("cannot reindex concurrently this type of relation")));
2872+
errmsg("cannot reindex this type of relation concurrently")));
28732873
break;
28742874
}
28752875

src/test/regress/expected/create_index.out

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ INSERT INTO concur_reindex_tab3 VALUES (3, '[1,2]');
19671967
REINDEX INDEX CONCURRENTLY concur_reindex_tab3_c2_excl; -- error
19681968
ERROR: concurrent index creation for exclusion constraints is not supported
19691969
REINDEX TABLE CONCURRENTLY concur_reindex_tab3; -- succeeds with warning
1970-
WARNING: cannot reindex concurrently exclusion constraint index "public.concur_reindex_tab3_c2_excl", skipping
1970+
WARNING: cannot reindex exclusion constraint index "public.concur_reindex_tab3_c2_excl" concurrently, skipping
19711971
INSERT INTO concur_reindex_tab3 VALUES (4, '[2,4]');
19721972
ERROR: conflicting key value violates exclusion constraint "concur_reindex_tab3_c2_excl"
19731973
DETAIL: Key (c2)=([2,5)) conflicts with existing key (c2)=([1,3)).
@@ -2092,10 +2092,15 @@ BEGIN;
20922092
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
20932093
ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block
20942094
COMMIT;
2095-
REINDEX TABLE CONCURRENTLY pg_database; -- no shared relation
2096-
ERROR: concurrent index creation on system catalog tables is not supported
2097-
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relations
2098-
ERROR: concurrent index creation on system catalog tables is not supported
2095+
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relation
2096+
ERROR: cannot reindex a system catalog concurrently
2097+
REINDEX INDEX CONCURRENTLY pg_class_oid_index; -- no catalog index
2098+
ERROR: cannot reindex a system catalog concurrently
2099+
-- These are the toast table and index of pg_authid.
2100+
REINDEX TABLE CONCURRENTLY pg_toast.pg_toast_1260; -- no catalog toast table
2101+
ERROR: cannot reindex a system catalog concurrently
2102+
REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
2103+
ERROR: cannot reindex a system catalog concurrently
20992104
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
21002105
ERROR: concurrent reindex of system catalogs is not supported
21012106
-- Warns about catalog relations
@@ -2144,7 +2149,7 @@ DROP INDEX concur_reindex_ind5_ccnew;
21442149
DELETE FROM concur_reindex_tab4 WHERE c1 = 1;
21452150
-- The invalid index is not processed when running REINDEX TABLE.
21462151
REINDEX TABLE CONCURRENTLY concur_reindex_tab4;
2147-
WARNING: cannot reindex concurrently invalid index "public.concur_reindex_ind5", skipping
2152+
WARNING: cannot reindex invalid index "public.concur_reindex_ind5" concurrently, skipping
21482153
NOTICE: table "concur_reindex_tab4" has no indexes
21492154
\d concur_reindex_tab4
21502155
Table "public.concur_reindex_tab4"

src/test/regress/sql/create_index.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,11 @@ DROP TABLE concur_reindex_part;
838838
BEGIN;
839839
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
840840
COMMIT;
841-
REINDEX TABLE CONCURRENTLY pg_database; -- no shared relation
842-
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relations
841+
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relation
842+
REINDEX INDEX CONCURRENTLY pg_class_oid_index; -- no catalog index
843+
-- These are the toast table and index of pg_authid.
844+
REINDEX TABLE CONCURRENTLY pg_toast.pg_toast_1260; -- no catalog toast table
845+
REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
843846
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
844847
-- Warns about catalog relations
845848
REINDEX SCHEMA CONCURRENTLY pg_catalog;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy