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-2024, 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 CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode,
52  bool orstronger);
53 extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
54 
55 extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
56 extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
57 
58 /* Lock a relation for extension */
59 extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
60 extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
62  LOCKMODE lockmode);
63 extern int RelationExtensionLockWaiterCount(Relation relation);
64 
65 /* Lock to recompute pg_database.datfrozenxid in the current database */
66 extern void LockDatabaseFrozenIds(LOCKMODE lockmode);
67 
68 /* Lock a page (currently only used within indexes) */
69 extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
70 extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
71 extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
72 
73 /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
74 extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
75 extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
76  LOCKMODE lockmode);
77 extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
78 
79 /* Lock an XID (used to wait for a transaction to finish) */
80 extern void XactLockTableInsert(TransactionId xid);
81 extern void XactLockTableDelete(TransactionId xid);
82 extern void XactLockTableWait(TransactionId xid, Relation rel,
83  ItemPointer ctid, XLTW_Oper oper);
85 
86 /* Lock VXIDs, specified by conflicting locktags */
87 extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress);
88 extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress);
89 
90 /* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
94 
95 /* Lock a general object (other than a relation) of the current database */
96 extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
97  LOCKMODE lockmode);
98 extern bool ConditionalLockDatabaseObject(Oid classid, Oid objid,
99  uint16 objsubid, LOCKMODE lockmode);
100 extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
101  LOCKMODE lockmode);
102 
103 /* Lock a shared-across-databases object (other than a relation) */
104 extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
105  LOCKMODE lockmode);
106 extern bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid,
107  LOCKMODE lockmode);
108 extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
109  LOCKMODE lockmode);
110 
111 extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
112  LOCKMODE lockmode);
113 extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
114  LOCKMODE lockmode);
115 
116 extern void LockApplyTransactionForSession(Oid suboid, TransactionId xid, uint16 objid,
117  LOCKMODE lockmode);
118 extern void UnlockApplyTransactionForSession(Oid suboid, TransactionId xid, uint16 objid,
119  LOCKMODE lockmode);
120 
121 /* Describe a locktag for error messages */
122 extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
123 
124 extern const char *GetLockNameFromTagType(uint16 locktag_type);
125 
126 #endif /* LMGR_H */
uint32 BlockNumber
Definition: block.h:31
unsigned short uint16
Definition: c.h:508
unsigned int uint32
Definition: c.h:509
uint32 TransactionId
Definition: c.h:655
#define token
Definition: indent_globs.h:126
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:151
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:657
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1073
bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:522
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:227
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:994
void UnlockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:310
void DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
Definition: lmgr.c:1233
void SpeculativeInsertionWait(TransactionId xid, uint32 token)
Definition: lmgr.c:814
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1097
void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1171
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:897
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:387
void RelationInitLockInfo(Relation relation)
Definition: lmgr.c:71
bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:578
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:108
void LockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:244
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:212
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:975
void XactLockTableDelete(TransactionId xid)
Definition: lmgr.c:633
void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:558
void XactLockTableInsert(TransactionId xid)
Definition: lmgr.c:616
uint32 SpeculativeInsertionLockAcquire(TransactionId xid)
Definition: lmgr.c:772
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:420
bool ConditionalXactLockTableWait(TransactionId xid)
Definition: lmgr.c:730
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:330
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 UnlockApplyTransactionForSession(Oid suboid, TransactionId xid, uint16 objid, LOCKMODE lockmode)
Definition: lmgr.c:1211
void SpeculativeInsertionLockRelease(TransactionId xid)
Definition: lmgr.c:798
void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:503
bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:438
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:347
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1330
void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:538
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:400
bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:275
bool ConditionalLockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1018
void LockDatabaseFrozenIds(LOCKMODE lockmode)
Definition: lmgr.c:487
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:470
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1132
void LockApplyTransactionForSession(Oid suboid, TransactionId xid, uint16 objid, LOCKMODE lockmode)
Definition: lmgr.c:1193
void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1153
void LockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:184
bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:363
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1053
int RelationExtensionLockWaiterCount(Relation relation)
Definition: lmgr.c:455
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:595
int LOCKMODE
Definition: lockdefs.h:26
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:370
static char * buf
Definition: pg_test_fsync.c:73
static int progress
Definition: pgbench.c:261
unsigned int Oid
Definition: postgres_ext.h:31
Definition: lock.h:165
Definition: pg_list.h:54
Definition: rel.h:39