In Microsoft SQL Server, the code below is used to get the IX (Intent Exclusive) lock:
SELECT request_mode FROM sys.dm_tran_locks WHERE resource_database_id = DB_ID() AND resource_associated_entity_id = OBJECT_ID(N'dbo.cars');
In PostgreSQL, pg_locks
table is available to tell locks information. However, there are many types of locktype
, which are:
relation, extend, frozenid, page, tuple, transactionid, virtualxid, object, userlock, or advisory
Which types of locktype
from pg_locks
is equivalent to IX (Intent Exclusive) lock from Microsoft SQL Server?
If locktype
is the wrong column to look at pg_locks
, please advise which column in pg_locks
should I use?
Thanks
Best Answer
You need to take a step back and check what Intent Locks are made for.
Transaction locking for MS-SQL server is broadly explained here: https://docs.microsoft.com/en-us/sql/relational-databases/sql-server-transaction-locking-and-row-versioning-guide
And for PostgreSQL it's broadly explained here https://www.postgresql.org/docs/current/mvcc.html
MS-SQL server doc says:
There is no equivalent to intent locks in PostgreSQL. The IS, IX, SIX, IU, SIU, UIX lock modes have no equivalent because they refer to a concept that PostgreSQL doesn't have and seemingly doesn't need.