Reputation: 1326
I am doing a simple insert row inside of a transaction, here is the steps that I followed
The pg_locks now says that there is an Exclusive lock as in the picture below.
According to the documentation an Exclusive Lock is only Acquired by refresh materialized view concurrently.
What am I doing wrong here?
Using pgsql - 9.4
Pg Locks table before insert has four rows, this is due to querying the pg_locks table itself in two separate sessions.
After insert it has two extra rows, one which is the actual transaction id itself which is an exclusive lock and another is on relation RowExclusiveLock
Upvotes: 1
Views: 851
Reputation: 324911
Those are locks on the transaction IDs. That's totally normal.
The purpose is that another transaction can try to acquire the lock on this transaction, causing it to wait until the first transaction commits or rolls back (and thus releases the lock on its self) before continuing.
You only need to worry about relation locks.
Upvotes: 3