postgresql/src/include/commands
Peter Eisentraut 1b5d797cd4 Lower lock level for renaming indexes
Change lock level for renaming index (either ALTER INDEX or implicitly
via some other commands) from AccessExclusiveLock to
ShareUpdateExclusiveLock.

One reason we need a strong lock for relation renaming is that the
name change causes a rebuild of the relcache entry.  Concurrent
sessions that have the relation open might not be able to handle the
relcache entry changing underneath them.  Therefore, we need to lock
the relation in a way that no one can have the relation open
concurrently.  But for indexes, the relcache handles reloads specially
in RelationReloadIndexInfo() in a way that keeps changes in the
relcache entry to a minimum.  As long as no one keeps pointers to
rd_amcache and rd_options around across possible relcache flushes,
which is the case, this ought to be safe.

We also want to use a self-exclusive lock for correctness, so that
concurrent DDL doesn't overwrite the rename if they start updating
while still seeing the old version.  Therefore, we use
ShareUpdateExclusiveLock, which is already used by other DDL commands
that want to operate in a concurrent manner.

The reason this is interesting at all is that renaming an index is a
typical part of a concurrent reindexing workflow (CREATE INDEX
CONCURRENTLY new + DROP INDEX CONCURRENTLY old + rename back).  And
indeed a future built-in REINDEX CONCURRENTLY might rely on the ability
to do concurrent renames as well.

Reviewed-by: Andrey Klychkov <aaklychkov@mail.ru>
Reviewed-by: Fabrízio de Royes Mello <fabriziomello@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/1531767486.432607658@f357.i.mail.ru
2018-11-14 17:09:54 +01:00
..
alter.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
async.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
cluster.h Refactor cluster_rel() to handle more options 2018-07-24 11:37:32 +09:00
collationcmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
comment.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
conversioncmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
copy.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
createas.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
dbcommands.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
dbcommands_xlog.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
defrem.h Fully enforce uniqueness of constraint names. 2018-09-04 13:45:35 -04:00
discard.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
event_trigger.h Replace GrantObjectType with ObjectType 2018-01-19 14:01:14 -05:00
explain.h Fix issues around EXPLAIN with JIT. 2018-10-03 12:48:37 -07:00
extension.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
lockcmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
matview.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
policy.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
portalcmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
prepare.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
proclang.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
progress.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
publicationcmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
schemacmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
seclabel.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
sequence.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
subscriptioncmds.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
tablecmds.h Lower lock level for renaming indexes 2018-11-14 17:09:54 +01:00
tablespace.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
trigger.h Allow using the updated tuple while moving it to a different partition. 2018-07-12 12:51:39 +05:30
typecmds.h Relax transactional restrictions on ALTER TYPE ... ADD VALUE (redux). 2018-10-09 12:51:01 +13:00
user.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
vacuum.h Refactor relation opening for VACUUM and ANALYZE 2018-10-02 08:53:38 +09:00
variable.h Turn transaction_isolation into GUC enum 2018-10-09 21:26:00 +02:00
view.h Update copyright for 2018 2018-01-02 23:30:12 -05:00