3

Does anyone know what is the lock level (row, table) on PostgreSQL MERGE command? I tried to dig deep on the documentation but I couldn't find anything that could clarify my mind. If anyone have a clue and would be kind to share, that would be very appreciated.

wmrodrigues
  • 483
  • 1
  • 3
  • 10
  • 2
    See [Explicit Locking](https://www.postgresql.org/docs/15/explicit-locking.html#LOCKING-ROWS) and search for `MERGE`. – Adrian Klaver May 30 '22 at 16:52
  • 1
    If you need to worry, then maybe `insert on conflict` is the better alternative. Unless the new MERGE command (of the not yet released version 15) gives you a feature that `insert on conflict` doesn't give you. –  May 30 '22 at 17:02

1 Answers1

2

From the manual:

ROW EXCLUSIVE Conflicts with the SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes.

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). In general, this lock mode will be acquired by any command that modifies data in a table.

Frank Heikens
  • 117,544
  • 24
  • 142
  • 135