Posts

Showing posts with the label row-level locks

Row-level Locks

Image
Introduction Row-level locks are used to protect specific rows when data is being modified. Unlike table locks, Postgres does any row lock storage outside of RAM, writing them directly into the tuples (data rows) on the hard disk to avoid memory overflow. Differences Table-level Lock (8 modes): Protects the table schema and controls broad behaviors, such as full-table reads, table writes, or column alterations. You can imagine these 8 modes as "admission tickets" that control who can enter the building and what they can do inside. Row-level Lock (4 modes): Protects the actual data values inside specific rows to prevent two people from modifying the same record simultaneously. It is like locking individual small rooms inside the building. Connections Although Table-level Lock and Row-level Lock are two distinct sets of lock modes, they always run in parallel and support each other. When you act on a row, Postgres automatically assigns both a table lock and a row lock under...