PostgreSQL Source Code  git master
lmgr.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * lmgr.h
4  * POSTGRES lock manager definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/lmgr.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef LMGR_H
15 #define LMGR_H
16 
17 #include "lib/stringinfo.h"
18 #include "storage/itemptr.h"
19 #include "storage/lock.h"
20 #include "utils/rel.h"
21 
22 
23 /* XactLockTableWait operations */
24 typedef enum XLTW_Oper
25 {
35 } XLTW_Oper;
36 
37 extern void RelationInitLockInfo(Relation relation);
38 
39 /* Lock a relation */
40 extern void LockRelationOid(Oid relid, LOCKMODE lockmode);
41 extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode);
42 extern void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode);
43 extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode);
44 
45 extern void LockRelation(Relation relation, LOCKMODE lockmode);
46 extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
47 extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
48 extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode,
49  bool orstronger);
50 extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
51 
52 extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
53 extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
54 
55 /* Lock a relation for extension */
56 extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
57 extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
59  LOCKMODE lockmode);
60 extern int RelationExtensionLockWaiterCount(Relation relation);
61 
62 /* Lock a page (currently only used within indexes) */
63 extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
64 extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
65 extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
66 
67 /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
68 extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
69 extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
70  LOCKMODE lockmode);
71 extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
72 
73 /* Lock an XID (used to wait for a transaction to finish) */
74 extern void XactLockTableInsert(TransactionId xid);
75 extern void XactLockTableDelete(TransactionId xid);
76 extern void XactLockTableWait(TransactionId xid, Relation rel,
77  ItemPointer ctid, XLTW_Oper oper);
79 
80 /* Lock VXIDs, specified by conflicting locktags */
81 extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress);
82 extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress);
83 
84 /* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
87 extern void SpeculativeInsertionWait(TransactionId xid, uint32 token);
88 
89 /* Lock a general object (other than a relation) of the current database */
90 extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
91  LOCKMODE lockmode);
92 extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
93  LOCKMODE lockmode);
94 
95 /* Lock a shared-across-databases object (other than a relation) */
96 extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
97  LOCKMODE lockmode);
98 extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
99  LOCKMODE lockmode);
100 
101 extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
102  LOCKMODE lockmode);
103 extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
104  LOCKMODE lockmode);
105 
106 /* Describe a locktag for error messages */
107 extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
108 
109 extern const char *GetLockNameFromTagType(uint16 locktag_type);
110 
111 #endif /* LMGR_H */
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:302
void DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
Definition: lmgr.c:1087
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:452
bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:489
void LockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:216
bool ConditionalXactLockTableWait(TransactionId xid)
Definition: lmgr.c:697
uint32 TransactionId
Definition: c.h:507
int LOCKMODE
Definition: lockdefs.h:26
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:562
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:984
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:369
void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:505
Definition: lock.h:164
void RelationInitLockInfo(Relation relation)
Definition: lmgr.c:71
void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1064
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1004
uint32 BlockNumber
Definition: block.h:31
bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:420
unsigned int Oid
Definition: postgres_ext.h:31
bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:345
bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:247
void XactLockTableDelete(TransactionId xid)
Definition: lmgr.c:600
int RelationExtensionLockWaiterCount(Relation relation)
Definition: lmgr.c:437
void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:525
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:199
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:402
unsigned short uint16
Definition: c.h:357
Definition: lmgr.h:26
Definition: rel.h:36
void XactLockTableInsert(TransactionId xid)
Definition: lmgr.c:583
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:863
void SpeculativeInsertionLockRelease(TransactionId xid)
Definition: lmgr.c:765
static char * buf
Definition: pg_test_fsync.c:68
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:624
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1172
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:108
unsigned int uint32
Definition: c.h:358
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:184
bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:545
void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
int progress
Definition: pgbench.c:215
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:382
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1025
uint32 SpeculativeInsertionLockAcquire(TransactionId xid)
Definition: lmgr.c:739
void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:470
void UnlockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:282
Definition: lmgr.h:29
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:944
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:151
XLTW_Oper
Definition: lmgr.h:24
void SpeculativeInsertionWait(TransactionId xid, uint32 token)
Definition: lmgr.c:781
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:963
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:377
Definition: pg_list.h:50