Senior
What locks does PostgreSQL create when deleting specific rows?
sobes.tech AI
Answer from AI
When deleting specific rows in PostgreSQL, a lock of type Row Exclusive Lock is created at the row level (row-level lock). This means that the rows being deleted are locked for other transactions to prevent simultaneous modification or deletion of the same rows.
Additionally, depending on the context, a table-level lock may be set, such as Row Share Lock or Row Exclusive Lock, to ensure data integrity during the delete operation.
Example: when executing DELETE FROM table WHERE id = 1;, PostgreSQL locks the row with id = 1 for other transactions to avoid conflicts.