mirror of
https://github.com/postgres/postgres.git
synced 2025-06-19 04:21:08 +03:00
REINDEX CONCURRENTLY
This adds the CONCURRENTLY option to the REINDEX command. A REINDEX CONCURRENTLY on a specific index creates a new index (like CREATE INDEX CONCURRENTLY), then renames the old index away and the new index in place and adjusts the dependencies, and then drops the old index (like DROP INDEX CONCURRENTLY). The REINDEX command also has the capability to run its other variants (TABLE, DATABASE) with the CONCURRENTLY option (but not SYSTEM). The reindexdb command gets the --concurrently option. Author: Michael Paquier, Andreas Karlsson, Peter Eisentraut Reviewed-by: Andres Freund, Fujii Masao, Jim Nasby, Sergei Kornilov Discussion: https://www.postgresql.org/message-id/flat/60052986-956b-4478-45ed-8bd119e9b9cf%402ndquadrant.com#74948a1044c56c5e817a5050f554ddee
This commit is contained in:
@ -1299,6 +1299,7 @@ RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid, Oid oldRelOid,
|
||||
bool is_partition;
|
||||
Form_pg_class classform;
|
||||
LOCKMODE heap_lockmode;
|
||||
bool invalid_system_index = false;
|
||||
|
||||
state = (struct DropRelationCallbackState *) arg;
|
||||
relkind = state->relkind;
|
||||
@ -1361,7 +1362,36 @@ RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid, Oid oldRelOid,
|
||||
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(get_rel_relkind(relOid)),
|
||||
rel->relname);
|
||||
|
||||
if (!allowSystemTableMods && IsSystemClass(relOid, classform))
|
||||
/*
|
||||
* Check the case of a system index that might have been invalidated by a
|
||||
* failed concurrent process and allow its drop. For the time being, this
|
||||
* only concerns indexes of toast relations that became invalid during a
|
||||
* REINDEX CONCURRENTLY process.
|
||||
*/
|
||||
if (IsSystemClass(relOid, classform) && relkind == RELKIND_INDEX)
|
||||
{
|
||||
HeapTuple locTuple;
|
||||
Form_pg_index indexform;
|
||||
bool indisvalid;
|
||||
|
||||
locTuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(relOid));
|
||||
if (!HeapTupleIsValid(locTuple))
|
||||
{
|
||||
ReleaseSysCache(tuple);
|
||||
return;
|
||||
}
|
||||
|
||||
indexform = (Form_pg_index) GETSTRUCT(locTuple);
|
||||
indisvalid = indexform->indisvalid;
|
||||
ReleaseSysCache(locTuple);
|
||||
|
||||
/* Mark object as being an invalid index of system catalogs */
|
||||
if (!indisvalid)
|
||||
invalid_system_index = true;
|
||||
}
|
||||
|
||||
/* In the case of an invalid index, it is fine to bypass this check */
|
||||
if (!invalid_system_index && !allowSystemTableMods && IsSystemClass(relOid, classform))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("permission denied: \"%s\" is a system catalog",
|
||||
|
Reference in New Issue
Block a user