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-2022, 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 {
36 
37 extern void RelationInitLockInfo(Relation relation);
38 
39 /* Lock a relation */
40 extern void LockRelationOid(Oid relid, LOCKMODE lockmode);
41 extern void LockRelationId(LockRelId *relid, LOCKMODE lockmode);
42 extern bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode);
43 extern void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode);
44 extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode);
45 
46 extern void LockRelation(Relation relation, LOCKMODE lockmode);
47 extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
48 extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
49 extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode,
50  bool orstronger);
51 extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
52 
53 extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
54 extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
55 
56 /* Lock a relation for extension */
57 extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
58 extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
60  LOCKMODE lockmode);
61 extern int RelationExtensionLockWaiterCount(Relation relation);
62 
63 /* Lock to recompute pg_database.datfrozenxid in the current database */
64 extern void LockDatabaseFrozenIds(LOCKMODE lockmode);
65 
66 /* Lock a page (currently only used within indexes) */
67 extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
68 extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
69 extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
70 
71 /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
72 extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
73 extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
74  LOCKMODE lockmode);
75 extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
76 
77 /* Lock an XID (used to wait for a transaction to finish) */
78 extern void XactLockTableInsert(TransactionId xid);
79 extern void XactLockTableDelete(TransactionId xid);
80 extern void XactLockTableWait(TransactionId xid, Relation rel,
81  ItemPointer ctid, XLTW_Oper oper);
83 
84 /* Lock VXIDs, specified by conflicting locktags */
85 extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress);
86 extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress);
87 
88 /* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
91 extern void SpeculativeInsertionWait(TransactionId xid, uint32 token);
92 
93 /* Lock a general object (other than a relation) of the current database */
94 extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
95  LOCKMODE lockmode);
96 extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
97  LOCKMODE lockmode);
98 
99 /* Lock a shared-across-databases object (other than a relation) */
100 extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
101  LOCKMODE lockmode);
102 extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
103  LOCKMODE lockmode);
104 
105 extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
106  LOCKMODE lockmode);
107 extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
108  LOCKMODE lockmode);
109 
110 /* Describe a locktag for error messages */
111 extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
112 
113 extern const char *GetLockNameFromTagType(uint16 locktag_type);
114 
115 #endif /* LMGR_H */
uint32 BlockNumber
Definition: block.h:31
unsigned short uint16
Definition: c.h:440
unsigned int uint32
Definition: c.h:441
uint32 TransactionId
Definition: c.h:587
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:152
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:668
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:533
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:228
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1005
void UnlockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:311
void DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
Definition: lmgr.c:1129
void SpeculativeInsertionWait(TransactionId xid, uint32 token)
Definition: lmgr.c:825
void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1106
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:908
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:398
void RelationInitLockInfo(Relation relation)
Definition: lmgr.c:72
bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:589
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:109
void LockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:245
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:213
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:986
void XactLockTableDelete(TransactionId xid)
Definition: lmgr.c:644
void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:569
void XactLockTableInsert(TransactionId xid)
Definition: lmgr.c:627
uint32 SpeculativeInsertionLockAcquire(TransactionId xid)
Definition: lmgr.c:783
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:431
bool ConditionalXactLockTableWait(TransactionId xid)
Definition: lmgr.c:741
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:331
XLTW_Oper
Definition: lmgr.h:25
@ XLTW_FetchUpdated
Definition: lmgr.h:33
@ XLTW_None
Definition: lmgr.h:26
@ XLTW_Lock
Definition: lmgr.h:29
@ XLTW_Delete
Definition: lmgr.h:28
@ XLTW_InsertIndex
Definition: lmgr.h:31
@ XLTW_LockUpdated
Definition: lmgr.h:30
@ XLTW_RecheckExclusionConstr
Definition: lmgr.h:34
@ XLTW_Update
Definition: lmgr.h:27
@ XLTW_InsertIndexUnique
Definition: lmgr.h:32
void SpeculativeInsertionLockRelease(TransactionId xid)
Definition: lmgr.c:809
void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:514
bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:449
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1219
void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:549
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:411
bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:276
void LockDatabaseFrozenIds(LOCKMODE lockmode)
Definition: lmgr.c:498
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:481
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1067
void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1088
void LockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:185
bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:374
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1026
int RelationExtensionLockWaiterCount(Relation relation)
Definition: lmgr.c:466
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:606
int LOCKMODE
Definition: lockdefs.h:26
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:382
static char * buf
Definition: pg_test_fsync.c:67
int progress
Definition: pgbench.c:274
unsigned int Oid
Definition: postgres_ext.h:31
Definition: lock.h:168
Definition: pg_list.h:51
Definition: rel.h:38