IT lexicon › Database › Table lock

Table lock

Database På svenska → Updated: 2026-05-27

Lock on entire table instead of individual rows. PostgreSQL has 8 levels (AccessShare, RowShare, RowExclusive, ShareUpdateExclusive, Share, ShareRowExclusive, Exclusive, AccessExclusive). Taken primarily at DDL operations.

AccessShare = SELECT, compatible with everything except AccessExclusive. AccessExclusive = blocks everything, including SELECT — taken by ALTER TABLE, DROP TABLE, REINDEX. Anti-pattern: ALTER TABLE ADD COLUMN with default value on 100M-row table → entire table rewrite + lock for several minutes → app downtime. Modern PG (11+): default no rewrite for nullable + immutable defaults. Online DDL tools: pt-online-schema-change (Percona), gh-ost (GitHub), pgroll (Xata). MySQL InnoDB online DDL handles many operations without lock.

← Back to the lexicon