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-2017, 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 LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
49 
50 extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
51 extern void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
52 
53 /* Lock a relation for extension */
54 extern void LockRelationForExtension(Relation relation, LOCKMODE lockmode);
55 extern void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode);
57  LOCKMODE lockmode);
58 extern int RelationExtensionLockWaiterCount(Relation relation);
59 
60 /* Lock a page (currently only used within indexes) */
61 extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
62 extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
63 extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
64 
65 /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
66 extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
67 extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
68  LOCKMODE lockmode);
69 extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
70 
71 /* Lock an XID (used to wait for a transaction to finish) */
72 extern void XactLockTableInsert(TransactionId xid);
73 extern void XactLockTableDelete(TransactionId xid);
74 extern void XactLockTableWait(TransactionId xid, Relation rel,
75  ItemPointer ctid, XLTW_Oper oper);
77 
78 /* Lock VXIDs, specified by conflicting locktags */
79 extern void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode);
80 extern void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode);
81 
82 /* Lock an XID for tuple insertion (used to wait for an insertion to finish) */
85 extern void SpeculativeInsertionWait(TransactionId xid, uint32 token);
86 
87 /* Lock a general object (other than a relation) of the current database */
88 extern void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
89  LOCKMODE lockmode);
90 extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
91  LOCKMODE lockmode);
92 
93 /* Lock a shared-across-databases object (other than a relation) */
94 extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
95  LOCKMODE lockmode);
96 extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
97  LOCKMODE lockmode);
98 
99 extern void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
100  LOCKMODE lockmode);
101 extern void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
102  LOCKMODE lockmode);
103 
104 /* Describe a locktag for error messages */
105 extern void DescribeLockTag(StringInfo buf, const LOCKTAG *tag);
106 
107 extern const char *GetLockNameFromTagType(uint16 locktag_type);
108 
109 #endif /* LMGR_H */
void DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
Definition: lmgr.c:954
void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:382
bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:419
void LockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:199
bool ConditionalXactLockTableWait(TransactionId xid)
Definition: lmgr.c:607
uint32 TransactionId
Definition: c.h:445
int LOCKMODE
Definition: lockdefs.h:26
void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:492
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:851
void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:299
void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:435
Definition: lock.h:178
void RelationInitLockInfo(Relation relation)
Definition: lmgr.c:68
void UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:931
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:871
uint32 BlockNumber
Definition: block.h:31
bool ConditionalLockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:350
unsigned int Oid
Definition: postgres_ext.h:31
bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:275
bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:226
void XactLockTableDelete(TransactionId xid)
Definition: lmgr.c:530
int RelationExtensionLockWaiterCount(Relation relation)
Definition: lmgr.c:367
void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:455
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode)
Definition: lmgr.c:767
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:182
void LockRelationForExtension(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:332
unsigned short uint16
Definition: c.h:295
Definition: lmgr.h:26
Definition: rel.h:36
void XactLockTableInsert(TransactionId xid)
Definition: lmgr.c:513
void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode)
Definition: lmgr.c:811
void SpeculativeInsertionLockRelease(TransactionId xid)
Definition: lmgr.c:669
static char * buf
Definition: pg_test_fsync.c:67
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:554
const char * GetLockNameFromTagType(uint16 locktag_type)
Definition: lmgr.c:1039
void LockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:105
unsigned int uint32
Definition: c.h:296
void UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:167
bool ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
Definition: lmgr.c:475
void LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:913
void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
Definition: lmgr.c:312
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:892
uint32 SpeculativeInsertionLockAcquire(TransactionId xid)
Definition: lmgr.c:643
void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
Definition: lmgr.c:400
void UnlockRelation(Relation relation, LOCKMODE lockmode)
Definition: lmgr.c:257
Definition: lmgr.h:29
bool ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
Definition: lmgr.c:138
XLTW_Oper
Definition: lmgr.h:24
void SpeculativeInsertionWait(TransactionId xid, uint32 token)
Definition: lmgr.c:685
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:830
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:377
Definition: pg_list.h:45