This mode guarantees that the holder is the only transaction accessing the table in any way.Īcquired by the DROP TABLE, TRUNCATE, REINDEX, CLUSTER, VACUUM FULL, and REFRESH MATERIALIZED VIEW (without CONCURRENTLY) commands. ACCESS EXCLUSIVE ( AccessExclusiveLock)Ĭonflicts with locks of all modes ( ACCESS SHARE, ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE). This mode allows only concurrent ACCESS SHARE locks, i.e., only reads from the table can proceed in parallel with a transaction holding this lock mode.Īcquired by REFRESH MATERIALIZED VIEW CONCURRENTLY. EXCLUSIVE ( ExclusiveLock)Ĭonflicts with the ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.Īcquired by CREATE TRIGGER and some forms of ALTER TABLE. SHARE ROW EXCLUSIVE ( ShareRowExclusiveLock)Ĭonflicts with the ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode protects a table against concurrent data changes.Īcquired by CREATE INDEX (without CONCURRENTLY). SHARE ( ShareLock)Ĭonflicts with the ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode protects a table against concurrent schema changes and VACUUM runs.Īcquired by VACUUM (without FULL), ANALYZE, CREATE INDEX CONCURRENTLY, CREATE STATISTICS, COMMENT ON, REINDEX CONCURRENTLY, and certain ALTER INDEX and ALTER TABLE variants (for full details see the documentation of these commands). SHARE UPDATE EXCLUSIVE ( ShareUpdateExclusiveLock)Ĭonflicts with the SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. In general, this lock mode will be acquired by any command that modifies data in a table. The commands UPDATE, DELETE, INSERT, and MERGE acquire this lock mode on the target table (in addition to ACCESS SHARE locks on any other referenced tables). ROW EXCLUSIVE ( RowExclusiveLock)Ĭonflicts with the SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. The SELECT command acquires a lock of this mode on all tables on which one of the FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, or FOR KEY SHARE options is specified (in addition to ACCESS SHARE locks on any other tables that are referenced without any explicit FOR. ROW SHARE ( RowShareLock)Ĭonflicts with the EXCLUSIVE and ACCESS EXCLUSIVE lock modes. In general, any query that only reads a table and does not modify it will acquire this lock mode. The SELECT command acquires a lock of this mode on referenced tables. Table-Level Lock Modes ACCESS SHARE ( AccessShareLock)Ĭonflicts with the ACCESS EXCLUSIVE lock mode only. Notice in particular that some lock modes are self-conflicting (for example, an ACCESS EXCLUSIVE lock cannot be held by more than one transaction at a time) while others are not self-conflicting (for example, an ACCESS SHARE lock can be held by multiple transactions). For example, it might acquire ACCESS EXCLUSIVE lock and later acquire ACCESS SHARE lock on the same table.) Non-conflicting lock modes can be held concurrently by many transactions. (However, a transaction never conflicts with itself. Two transactions cannot hold locks of conflicting modes on the same table at the same time. The only real difference between one lock mode and another is the set of lock modes with which each conflicts (see Table 13.2). To some extent the names reflect the typical usage of each lock mode - but the semantics are all the same. Remember that all of these lock modes are table-level locks, even if the name contains the word “ row” the names of the lock modes are historical. You can also acquire any of these locks explicitly with the command LOCK. The list below shows the available lock modes and the contexts in which they are used automatically by PostgreSQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |