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
This commit is contained in:
parent
24c19e9f66
commit
508300e2e1
@ -2743,6 +2743,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
|
|||||||
|
|
||||||
MemoryContextSwitchTo(oldcontext);
|
MemoryContextSwitchTo(oldcontext);
|
||||||
|
|
||||||
|
/* A system catalog cannot be reindexed concurrently */
|
||||||
|
if (IsCatalogRelationOid(relationOid))
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot reindex a system catalog concurrently")));
|
||||||
|
|
||||||
/* Open relation to get its indexes */
|
/* Open relation to get its indexes */
|
||||||
heapRelation = table_open(relationOid, ShareUpdateExclusiveLock);
|
heapRelation = table_open(relationOid, ShareUpdateExclusiveLock);
|
||||||
|
|
||||||
@ -2756,13 +2762,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
|
|||||||
if (!indexRelation->rd_index->indisvalid)
|
if (!indexRelation->rd_index->indisvalid)
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("cannot reindex concurrently invalid index \"%s.%s\", skipping",
|
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
|
||||||
get_namespace_name(get_rel_namespace(cellOid)),
|
get_namespace_name(get_rel_namespace(cellOid)),
|
||||||
get_rel_name(cellOid))));
|
get_rel_name(cellOid))));
|
||||||
else if (indexRelation->rd_index->indisexclusion)
|
else if (indexRelation->rd_index->indisexclusion)
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("cannot reindex concurrently exclusion constraint index \"%s.%s\", skipping",
|
errmsg("cannot reindex exclusion constraint index \"%s.%s\" concurrently, skipping",
|
||||||
get_namespace_name(get_rel_namespace(cellOid)),
|
get_namespace_name(get_rel_namespace(cellOid)),
|
||||||
get_rel_name(cellOid))));
|
get_rel_name(cellOid))));
|
||||||
else
|
else
|
||||||
@ -2802,7 +2808,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
|
|||||||
if (!indexRelation->rd_index->indisvalid)
|
if (!indexRelation->rd_index->indisvalid)
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||||
errmsg("cannot reindex concurrently invalid index \"%s.%s\", skipping",
|
errmsg("cannot reindex invalid index \"%s.%s\" concurrently, skipping",
|
||||||
get_namespace_name(get_rel_namespace(cellOid)),
|
get_namespace_name(get_rel_namespace(cellOid)),
|
||||||
get_rel_name(cellOid))));
|
get_rel_name(cellOid))));
|
||||||
else
|
else
|
||||||
@ -2831,17 +2837,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
|
|||||||
{
|
{
|
||||||
Oid heapId = IndexGetRelation(relationOid, false);
|
Oid heapId = IndexGetRelation(relationOid, false);
|
||||||
|
|
||||||
/* A shared relation cannot be reindexed concurrently */
|
|
||||||
if (IsSharedRelation(heapId))
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
||||||
errmsg("concurrent reindex is not supported for shared relations")));
|
|
||||||
|
|
||||||
/* A system catalog cannot be reindexed concurrently */
|
/* A system catalog cannot be reindexed concurrently */
|
||||||
if (IsCatalogRelationOid(heapId))
|
if (IsCatalogRelationOid(heapId))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("concurrent reindex is not supported for catalog relations")));
|
errmsg("cannot reindex a system catalog concurrently")));
|
||||||
|
|
||||||
/* Save the list of relation OIDs in private context */
|
/* Save the list of relation OIDs in private context */
|
||||||
oldcontext = MemoryContextSwitchTo(private_context);
|
oldcontext = MemoryContextSwitchTo(private_context);
|
||||||
@ -2869,7 +2869,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
|
|||||||
/* Return error if type of relation is not supported */
|
/* Return error if type of relation is not supported */
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||||
errmsg("cannot reindex concurrently this type of relation")));
|
errmsg("cannot reindex this type of relation concurrently")));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1967,7 +1967,7 @@ INSERT INTO concur_reindex_tab3 VALUES (3, '[1,2]');
|
|||||||
REINDEX INDEX CONCURRENTLY concur_reindex_tab3_c2_excl; -- error
|
REINDEX INDEX CONCURRENTLY concur_reindex_tab3_c2_excl; -- error
|
||||||
ERROR: concurrent index creation for exclusion constraints is not supported
|
ERROR: concurrent index creation for exclusion constraints is not supported
|
||||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab3; -- succeeds with warning
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab3; -- succeeds with warning
|
||||||
WARNING: cannot reindex concurrently exclusion constraint index "public.concur_reindex_tab3_c2_excl", skipping
|
WARNING: cannot reindex exclusion constraint index "public.concur_reindex_tab3_c2_excl" concurrently, skipping
|
||||||
INSERT INTO concur_reindex_tab3 VALUES (4, '[2,4]');
|
INSERT INTO concur_reindex_tab3 VALUES (4, '[2,4]');
|
||||||
ERROR: conflicting key value violates exclusion constraint "concur_reindex_tab3_c2_excl"
|
ERROR: conflicting key value violates exclusion constraint "concur_reindex_tab3_c2_excl"
|
||||||
DETAIL: Key (c2)=([2,5)) conflicts with existing key (c2)=([1,3)).
|
DETAIL: Key (c2)=([2,5)) conflicts with existing key (c2)=([1,3)).
|
||||||
@ -2092,10 +2092,15 @@ BEGIN;
|
|||||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
||||||
ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block
|
ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block
|
||||||
COMMIT;
|
COMMIT;
|
||||||
REINDEX TABLE CONCURRENTLY pg_database; -- no shared relation
|
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relation
|
||||||
ERROR: concurrent index creation on system catalog tables is not supported
|
ERROR: cannot reindex a system catalog concurrently
|
||||||
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relations
|
REINDEX INDEX CONCURRENTLY pg_class_oid_index; -- no catalog index
|
||||||
ERROR: concurrent index creation on system catalog tables is not supported
|
ERROR: cannot reindex a system catalog concurrently
|
||||||
|
-- These are the toast table and index of pg_authid.
|
||||||
|
REINDEX TABLE CONCURRENTLY pg_toast.pg_toast_1260; -- no catalog toast table
|
||||||
|
ERROR: cannot reindex a system catalog concurrently
|
||||||
|
REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
|
||||||
|
ERROR: cannot reindex a system catalog concurrently
|
||||||
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
|
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
|
||||||
ERROR: concurrent reindex of system catalogs is not supported
|
ERROR: concurrent reindex of system catalogs is not supported
|
||||||
-- Warns about catalog relations
|
-- Warns about catalog relations
|
||||||
@ -2144,7 +2149,7 @@ DROP INDEX concur_reindex_ind5_ccnew;
|
|||||||
DELETE FROM concur_reindex_tab4 WHERE c1 = 1;
|
DELETE FROM concur_reindex_tab4 WHERE c1 = 1;
|
||||||
-- The invalid index is not processed when running REINDEX TABLE.
|
-- The invalid index is not processed when running REINDEX TABLE.
|
||||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab4;
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab4;
|
||||||
WARNING: cannot reindex concurrently invalid index "public.concur_reindex_ind5", skipping
|
WARNING: cannot reindex invalid index "public.concur_reindex_ind5" concurrently, skipping
|
||||||
NOTICE: table "concur_reindex_tab4" has no indexes
|
NOTICE: table "concur_reindex_tab4" has no indexes
|
||||||
\d concur_reindex_tab4
|
\d concur_reindex_tab4
|
||||||
Table "public.concur_reindex_tab4"
|
Table "public.concur_reindex_tab4"
|
||||||
|
@ -838,8 +838,11 @@ DROP TABLE concur_reindex_part;
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
REINDEX TABLE CONCURRENTLY concur_reindex_tab;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
REINDEX TABLE CONCURRENTLY pg_database; -- no shared relation
|
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relation
|
||||||
REINDEX TABLE CONCURRENTLY pg_class; -- no catalog relations
|
REINDEX INDEX CONCURRENTLY pg_class_oid_index; -- no catalog index
|
||||||
|
-- These are the toast table and index of pg_authid.
|
||||||
|
REINDEX TABLE CONCURRENTLY pg_toast.pg_toast_1260; -- no catalog toast table
|
||||||
|
REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
|
||||||
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
|
REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
|
||||||
-- Warns about catalog relations
|
-- Warns about catalog relations
|
||||||
REINDEX SCHEMA CONCURRENTLY pg_catalog;
|
REINDEX SCHEMA CONCURRENTLY pg_catalog;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user