PostgreSQL Source Code git master
lmgr.c File Reference
#include "postgres.h"
#include "access/subtrans.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "commands/progress.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/lmgr.h"
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/inval.h"
Include dependency graph for lmgr.c:

Go to the source code of this file.

Data Structures

struct  XactLockTableWaitInfo
 

Typedefs

typedef struct XactLockTableWaitInfo XactLockTableWaitInfo
 

Functions

static void XactLockTableWaitErrorCb (void *arg)
 
void RelationInitLockInfo (Relation relation)
 
static void SetLocktagRelationOid (LOCKTAG *tag, Oid relid)
 
void LockRelationOid (Oid relid, LOCKMODE lockmode)
 
bool ConditionalLockRelationOid (Oid relid, LOCKMODE lockmode)
 
void LockRelationId (LockRelId *relid, LOCKMODE lockmode)
 
void UnlockRelationId (LockRelId *relid, LOCKMODE lockmode)
 
void UnlockRelationOid (Oid relid, LOCKMODE lockmode)
 
void LockRelation (Relation relation, LOCKMODE lockmode)
 
bool ConditionalLockRelation (Relation relation, LOCKMODE lockmode)
 
void UnlockRelation (Relation relation, LOCKMODE lockmode)
 
bool CheckRelationLockedByMe (Relation relation, LOCKMODE lockmode, bool orstronger)
 
bool CheckRelationOidLockedByMe (Oid relid, LOCKMODE lockmode, bool orstronger)
 
bool LockHasWaitersRelation (Relation relation, LOCKMODE lockmode)
 
void LockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
 
void UnlockRelationIdForSession (LockRelId *relid, LOCKMODE lockmode)
 
void LockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
bool ConditionalLockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
int RelationExtensionLockWaiterCount (Relation relation)
 
void UnlockRelationForExtension (Relation relation, LOCKMODE lockmode)
 
void LockDatabaseFrozenIds (LOCKMODE lockmode)
 
void LockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
bool ConditionalLockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
void UnlockPage (Relation relation, BlockNumber blkno, LOCKMODE lockmode)
 
void LockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode)
 
bool ConditionalLockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode, bool logLockFailure)
 
void UnlockTuple (Relation relation, ItemPointer tid, LOCKMODE lockmode)
 
void XactLockTableInsert (TransactionId xid)
 
void XactLockTableDelete (TransactionId xid)
 
void XactLockTableWait (TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
 
bool ConditionalXactLockTableWait (TransactionId xid, bool logLockFailure)
 
uint32 SpeculativeInsertionLockAcquire (TransactionId xid)
 
void SpeculativeInsertionLockRelease (TransactionId xid)
 
void SpeculativeInsertionWait (TransactionId xid, uint32 token)
 
void WaitForLockersMultiple (List *locktags, LOCKMODE lockmode, bool progress)
 
void WaitForLockers (LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)
 
void LockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
bool ConditionalLockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockDatabaseObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void LockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
bool ConditionalLockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockSharedObject (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void LockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void UnlockSharedObjectForSession (Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
 
void LockApplyTransactionForSession (Oid suboid, TransactionId xid, uint16 objid, LOCKMODE lockmode)
 
void UnlockApplyTransactionForSession (Oid suboid, TransactionId xid, uint16 objid, LOCKMODE lockmode)
 
void DescribeLockTag (StringInfo buf, const LOCKTAG *tag)
 
const char * GetLockNameFromTagType (uint16 locktag_type)
 

Variables

static uint32 speculativeInsertionToken = 0
 

Typedef Documentation

◆ XactLockTableWaitInfo

Function Documentation

◆ CheckRelationLockedByMe()

bool CheckRelationLockedByMe ( Relation  relation,
LOCKMODE  lockmode,
bool  orstronger 
)

Definition at line 334 of file lmgr.c.

335{
336 LOCKTAG tag;
337
339 relation->rd_lockInfo.lockRelId.dbId,
340 relation->rd_lockInfo.lockRelId.relId);
341
342 return LockHeldByMe(&tag, lockmode, orstronger);
343}
bool LockHeldByMe(const LOCKTAG *locktag, LOCKMODE lockmode, bool orstronger)
Definition: lock.c:639
#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)
Definition: lock.h:182
Definition: lock.h:166
LockRelId lockRelId
Definition: rel.h:46
Oid relId
Definition: rel.h:40
Oid dbId
Definition: rel.h:41
LockInfoData rd_lockInfo
Definition: rel.h:114

References LockRelId::dbId, LockHeldByMe(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by addFkRecurseReferenced(), addFkRecurseReferencing(), addRangeTableEntryForRelation(), cluster_rel(), ExecGetRangeTableRelation(), rebuild_relation(), relation_open(), and try_relation_open().

◆ CheckRelationOidLockedByMe()

bool CheckRelationOidLockedByMe ( Oid  relid,
LOCKMODE  lockmode,
bool  orstronger 
)

Definition at line 351 of file lmgr.c.

352{
353 LOCKTAG tag;
354
355 SetLocktagRelationOid(&tag, relid);
356
357 return LockHeldByMe(&tag, lockmode, orstronger);
358}
static void SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
Definition: lmgr.c:88

References LockHeldByMe(), and SetLocktagRelationOid().

Referenced by ATRewriteTable(), build_index_value_desc(), ExecCheckPermissions(), rebuild_relation(), RefreshMatViewByOid(), ReportApplyConflict(), and SetRelationHasSubclass().

◆ ConditionalLockDatabaseObject()

bool ConditionalLockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1026 of file lmgr.c.

1028{
1029 LOCKTAG tag;
1030 LOCALLOCK *locallock;
1032
1035 classid,
1036 objid,
1037 objsubid);
1038
1039 res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock,
1040 false);
1041
1042 if (res == LOCKACQUIRE_NOT_AVAIL)
1043 return false;
1044
1045 /*
1046 * Now that we have the lock, check for invalidation messages; see notes
1047 * in LockRelationOid.
1048 */
1049 if (res != LOCKACQUIRE_ALREADY_CLEAR)
1050 {
1052 MarkLockClear(locallock);
1053 }
1054
1055 return true;
1056}
Oid MyDatabaseId
Definition: globals.c:93
void AcceptInvalidationMessages(void)
Definition: inval.c:929
LockAcquireResult LockAcquireExtended(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait, bool reportMemoryError, LOCALLOCK **locallockp, bool logLockFailure)
Definition: lock.c:832
void MarkLockClear(LOCALLOCK *locallock)
Definition: lock.c:1907
#define SET_LOCKTAG_OBJECT(locktag, dboid, classoid, objoid, objsubid)
Definition: lock.h:263
LockAcquireResult
Definition: lock.h:501
@ LOCKACQUIRE_ALREADY_CLEAR
Definition: lock.h:505
@ LOCKACQUIRE_NOT_AVAIL
Definition: lock.h:502

References AcceptInvalidationMessages(), LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), MarkLockClear(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

Referenced by do_autovacuum().

◆ ConditionalLockPage()

bool ConditionalLockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 526 of file lmgr.c.

527{
528 LOCKTAG tag;
529
531 relation->rd_lockInfo.lockRelId.dbId,
532 relation->rd_lockInfo.lockRelId.relId,
533 blkno);
534
535 return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
536}
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:805
#define SET_LOCKTAG_PAGE(locktag, dboid, reloid, blocknum)
Definition: lock.h:209

References LockRelId::dbId, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

◆ ConditionalLockRelation()

bool ConditionalLockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 278 of file lmgr.c.

279{
280 LOCKTAG tag;
281 LOCALLOCK *locallock;
283
285 relation->rd_lockInfo.lockRelId.dbId,
286 relation->rd_lockInfo.lockRelId.relId);
287
288 res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock,
289 false);
290
291 if (res == LOCKACQUIRE_NOT_AVAIL)
292 return false;
293
294 /*
295 * Now that we have the lock, check for invalidation messages; see notes
296 * in LockRelationOid.
297 */
298 if (res != LOCKACQUIRE_ALREADY_CLEAR)
299 {
301 MarkLockClear(locallock);
302 }
303
304 return true;
305}

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), LockInfoData::lockRelId, MarkLockClear(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by lazy_truncate_heap().

◆ ConditionalLockRelationForExtension()

bool ConditionalLockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 442 of file lmgr.c.

443{
444 LOCKTAG tag;
445
447 relation->rd_lockInfo.lockRelId.dbId,
448 relation->rd_lockInfo.lockRelId.relId);
449
450 return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
451}
#define SET_LOCKTAG_RELATION_EXTEND(locktag, dboid, reloid)
Definition: lock.h:191

References LockRelId::dbId, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

◆ ConditionalLockRelationOid()

bool ConditionalLockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 151 of file lmgr.c.

152{
153 LOCKTAG tag;
154 LOCALLOCK *locallock;
156
157 SetLocktagRelationOid(&tag, relid);
158
159 res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock,
160 false);
161
162 if (res == LOCKACQUIRE_NOT_AVAIL)
163 return false;
164
165 /*
166 * Now that we have the lock, check for invalidation messages; see notes
167 * in LockRelationOid.
168 */
169 if (res != LOCKACQUIRE_ALREADY_CLEAR)
170 {
172 MarkLockClear(locallock);
173 }
174
175 return true;
176}

References AcceptInvalidationMessages(), LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), MarkLockClear(), and SetLocktagRelationOid().

Referenced by AlterTableMoveAll(), do_autovacuum(), LockTableRecurse(), LockViewRecurse_walker(), RangeVarGetRelidExtended(), and vacuum_open_relation().

◆ ConditionalLockSharedObject()

bool ConditionalLockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1106 of file lmgr.c.

1108{
1109 LOCKTAG tag;
1110 LOCALLOCK *locallock;
1112
1114 InvalidOid,
1115 classid,
1116 objid,
1117 objsubid);
1118
1119 res = LockAcquireExtended(&tag, lockmode, false, true, true, &locallock,
1120 false);
1121
1122 if (res == LOCKACQUIRE_NOT_AVAIL)
1123 return false;
1124
1125 /*
1126 * Now that we have the lock, check for invalidation messages; see notes
1127 * in LockRelationOid.
1128 */
1129 if (res != LOCKACQUIRE_ALREADY_CLEAR)
1130 {
1132 MarkLockClear(locallock);
1133 }
1134
1135 return true;
1136}
#define InvalidOid
Definition: postgres_ext.h:37

References AcceptInvalidationMessages(), InvalidOid, LOCKACQUIRE_ALREADY_CLEAR, LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), MarkLockClear(), and SET_LOCKTAG_OBJECT.

Referenced by EventTriggerOnLogin().

◆ ConditionalLockTuple()

bool ConditionalLockTuple ( Relation  relation,
ItemPointer  tid,
LOCKMODE  lockmode,
bool  logLockFailure 
)

Definition at line 582 of file lmgr.c.

584{
585 LOCKTAG tag;
586
588 relation->rd_lockInfo.lockRelId.dbId,
589 relation->rd_lockInfo.lockRelId.relId,
592
593 return (LockAcquireExtended(&tag, lockmode, false, true, true, NULL,
594 logLockFailure) != LOCKACQUIRE_NOT_AVAIL);
595}
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:218

References LockRelId::dbId, ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_TUPLE.

◆ ConditionalXactLockTableWait()

bool ConditionalXactLockTableWait ( TransactionId  xid,
bool  logLockFailure 
)

Definition at line 736 of file lmgr.c.

737{
738 LOCKTAG tag;
739 bool first = true;
740
741 for (;;)
742 {
745
746 SET_LOCKTAG_TRANSACTION(tag, xid);
747
748 if (LockAcquireExtended(&tag, ShareLock, false, true, true, NULL,
749 logLockFailure)
751 return false;
752
753 LockRelease(&tag, ShareLock, false);
754
756 break;
757
758 /* See XactLockTableWait about this case */
759 if (!first)
760 pg_usleep(1000L);
761 first = false;
763 }
764
765 return true;
766}
Assert(PointerIsAligned(start, uint64))
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:2058
#define SET_LOCKTAG_TRANSACTION(locktag, xid)
Definition: lock.h:227
#define ShareLock
Definition: lockdefs.h:40
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1402
void pg_usleep(long microsec)
Definition: signal.c:53
TransactionId SubTransGetTopmostTransaction(TransactionId xid)
Definition: subtrans.c:163
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdIsValid(xid)
Definition: transam.h:41
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:441

References Assert(), GetTopTransactionIdIfAny(), LOCKACQUIRE_NOT_AVAIL, LockAcquireExtended(), LockRelease(), pg_usleep(), SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetTopmostTransaction(), TransactionIdEquals, TransactionIdIsInProgress(), and TransactionIdIsValid.

Referenced by Do_MultiXactIdWait(), heap_lock_tuple(), and heapam_tuple_lock().

◆ DescribeLockTag()

void DescribeLockTag ( StringInfo  buf,
const LOCKTAG tag 
)

Definition at line 1243 of file lmgr.c.

1244{
1245 switch ((LockTagType) tag->locktag_type)
1246 {
1247 case LOCKTAG_RELATION:
1249 _("relation %u of database %u"),
1250 tag->locktag_field2,
1251 tag->locktag_field1);
1252 break;
1255 _("extension of relation %u of database %u"),
1256 tag->locktag_field2,
1257 tag->locktag_field1);
1258 break;
1261 _("pg_database.datfrozenxid of database %u"),
1262 tag->locktag_field1);
1263 break;
1264 case LOCKTAG_PAGE:
1266 _("page %u of relation %u of database %u"),
1267 tag->locktag_field3,
1268 tag->locktag_field2,
1269 tag->locktag_field1);
1270 break;
1271 case LOCKTAG_TUPLE:
1273 _("tuple (%u,%u) of relation %u of database %u"),
1274 tag->locktag_field3,
1275 tag->locktag_field4,
1276 tag->locktag_field2,
1277 tag->locktag_field1);
1278 break;
1281 _("transaction %u"),
1282 tag->locktag_field1);
1283 break;
1286 _("virtual transaction %d/%u"),
1287 tag->locktag_field1,
1288 tag->locktag_field2);
1289 break;
1292 _("speculative token %u of transaction %u"),
1293 tag->locktag_field2,
1294 tag->locktag_field1);
1295 break;
1296 case LOCKTAG_OBJECT:
1298 _("object %u of class %u of database %u"),
1299 tag->locktag_field3,
1300 tag->locktag_field2,
1301 tag->locktag_field1);
1302 break;
1303 case LOCKTAG_USERLOCK:
1304 /* reserved for old contrib code, now on pgfoundry */
1306 _("user lock [%u,%u,%u]"),
1307 tag->locktag_field1,
1308 tag->locktag_field2,
1309 tag->locktag_field3);
1310 break;
1311 case LOCKTAG_ADVISORY:
1313 _("advisory lock [%u,%u,%u,%u]"),
1314 tag->locktag_field1,
1315 tag->locktag_field2,
1316 tag->locktag_field3,
1317 tag->locktag_field4);
1318 break;
1321 _("remote transaction %u of subscription %u of database %u"),
1322 tag->locktag_field3,
1323 tag->locktag_field2,
1324 tag->locktag_field1);
1325 break;
1326 default:
1328 _("unrecognized locktag type %d"),
1329 (int) tag->locktag_type);
1330 break;
1331 }
1332}
#define _(x)
Definition: elog.c:90
LockTagType
Definition: lock.h:137
@ LOCKTAG_OBJECT
Definition: lock.h:146
@ LOCKTAG_RELATION_EXTEND
Definition: lock.h:139
@ LOCKTAG_RELATION
Definition: lock.h:138
@ LOCKTAG_TUPLE
Definition: lock.h:142
@ LOCKTAG_SPECULATIVE_TOKEN
Definition: lock.h:145
@ LOCKTAG_APPLY_TRANSACTION
Definition: lock.h:149
@ LOCKTAG_USERLOCK
Definition: lock.h:147
@ LOCKTAG_DATABASE_FROZEN_IDS
Definition: lock.h:140
@ LOCKTAG_VIRTUALTRANSACTION
Definition: lock.h:144
@ LOCKTAG_TRANSACTION
Definition: lock.h:143
@ LOCKTAG_PAGE
Definition: lock.h:141
@ LOCKTAG_ADVISORY
Definition: lock.h:148
static char * buf
Definition: pg_test_fsync.c:72
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
uint8 locktag_type
Definition: lock.h:171
uint32 locktag_field3
Definition: lock.h:169
uint32 locktag_field1
Definition: lock.h:167
uint16 locktag_field4
Definition: lock.h:170
uint32 locktag_field2
Definition: lock.h:168

References _, appendStringInfo(), buf, LOCKTAG_ADVISORY, LOCKTAG_APPLY_TRANSACTION, LOCKTAG_DATABASE_FROZEN_IDS, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_SPECULATIVE_TOKEN, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, and LOCKTAG_VIRTUALTRANSACTION.

Referenced by DeadLockReport(), LockAcquireExtended(), and ProcSleep().

◆ GetLockNameFromTagType()

const char * GetLockNameFromTagType ( uint16  locktag_type)

Definition at line 1340 of file lmgr.c.

1341{
1342 if (locktag_type > LOCKTAG_LAST_TYPE)
1343 return "???";
1344 return LockTagTypeNames[locktag_type];
1345}
#define LOCKTAG_LAST_TYPE
Definition: lock.h:153
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:28

References LOCKTAG_LAST_TYPE, and LockTagTypeNames.

Referenced by pgstat_get_wait_event().

◆ LockApplyTransactionForSession()

void LockApplyTransactionForSession ( Oid  suboid,
TransactionId  xid,
uint16  objid,
LOCKMODE  lockmode 
)

Definition at line 1203 of file lmgr.c.

1205{
1206 LOCKTAG tag;
1207
1210 suboid,
1211 xid,
1212 objid);
1213
1214 (void) LockAcquire(&tag, lockmode, true, false);
1215}
#define SET_LOCKTAG_APPLY_TRANSACTION(locktag, dboid, suboid, xid, objid)
Definition: lock.h:283

References LockAcquire(), MyDatabaseId, and SET_LOCKTAG_APPLY_TRANSACTION.

Referenced by pa_lock_stream(), and pa_lock_transaction().

◆ LockDatabaseFrozenIds()

void LockDatabaseFrozenIds ( LOCKMODE  lockmode)

Definition at line 491 of file lmgr.c.

492{
493 LOCKTAG tag;
494
496
497 (void) LockAcquire(&tag, lockmode, false, false);
498}
#define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag, dboid)
Definition: lock.h:200

References LockAcquire(), MyDatabaseId, and SET_LOCKTAG_DATABASE_FROZEN_IDS.

Referenced by vac_update_datfrozenxid().

◆ LockDatabaseObject()

void LockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1002 of file lmgr.c.

1004{
1005 LOCKTAG tag;
1006
1009 classid,
1010 objid,
1011 objsubid);
1012
1013 (void) LockAcquire(&tag, lockmode, false, false);
1014
1015 /* Make sure syscaches are up-to-date with any changes we waited for */
1017}

References AcceptInvalidationMessages(), LockAcquire(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

Referenced by AcquireDeletionLock(), AddEnumLabel(), AlterPublication(), AlterPublicationOptions(), get_object_address(), LockSchemaList(), RangeVarGetAndCheckCreationNamespace(), and RenameEnumLabel().

◆ LockHasWaitersRelation()

bool LockHasWaitersRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 367 of file lmgr.c.

368{
369 LOCKTAG tag;
370
372 relation->rd_lockInfo.lockRelId.dbId,
373 relation->rd_lockInfo.lockRelId.relId);
374
375 return LockHasWaiters(&tag, lockmode, false);
376}
bool LockHasWaiters(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:692

References LockRelId::dbId, LockHasWaiters(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by count_nondeletable_pages().

◆ LockPage()

void LockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 507 of file lmgr.c.

508{
509 LOCKTAG tag;
510
512 relation->rd_lockInfo.lockRelId.dbId,
513 relation->rd_lockInfo.lockRelId.relId,
514 blkno);
515
516 (void) LockAcquire(&tag, lockmode, false, false);
517}

References LockRelId::dbId, LockAcquire(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

◆ LockRelation()

void LockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 246 of file lmgr.c.

247{
248 LOCKTAG tag;
249 LOCALLOCK *locallock;
251
253 relation->rd_lockInfo.lockRelId.dbId,
254 relation->rd_lockInfo.lockRelId.relId);
255
256 res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock,
257 false);
258
259 /*
260 * Now that we have the lock, check for invalidation messages; see notes
261 * in LockRelationOid.
262 */
263 if (res != LOCKACQUIRE_ALREADY_CLEAR)
264 {
266 MarkLockClear(locallock);
267 }
268}

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), LockInfoData::lockRelId, MarkLockClear(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by index_create().

◆ LockRelationForExtension()

void LockRelationForExtension ( Relation  relation,
LOCKMODE  lockmode 
)

◆ LockRelationId()

void LockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 185 of file lmgr.c.

186{
187 LOCKTAG tag;
188 LOCALLOCK *locallock;
190
191 SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
192
193 res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock,
194 false);
195
196 /*
197 * Now that we have the lock, check for invalidation messages; see notes
198 * in LockRelationOid.
199 */
200 if (res != LOCKACQUIRE_ALREADY_CLEAR)
201 {
203 MarkLockClear(locallock);
204 }
205}

References AcceptInvalidationMessages(), LockRelId::dbId, LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), MarkLockClear(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by CreateDatabaseUsingWalLog(), and ScanSourceDatabasePgClass().

◆ LockRelationIdForSession()

void LockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 391 of file lmgr.c.

392{
393 LOCKTAG tag;
394
395 SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
396
397 (void) LockAcquire(&tag, lockmode, true, false);
398}

References LockRelId::dbId, LockAcquire(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by DefineIndex(), index_drop(), ReindexRelationConcurrently(), and vacuum_rel().

◆ LockRelationOid()

void LockRelationOid ( Oid  relid,
LOCKMODE  lockmode 
)

Definition at line 107 of file lmgr.c.

108{
109 LOCKTAG tag;
110 LOCALLOCK *locallock;
112
113 SetLocktagRelationOid(&tag, relid);
114
115 res = LockAcquireExtended(&tag, lockmode, false, false, true, &locallock,
116 false);
117
118 /*
119 * Now that we have the lock, check for invalidation messages, so that we
120 * will update or flush any stale relcache entry before we try to use it.
121 * RangeVarGetRelid() specifically relies on us for this. We can skip
122 * this in the not-uncommon case that we already had the same type of lock
123 * being requested, since then no one else could have modified the
124 * relcache entry in an undesirable way. (In the case where our own xact
125 * modifies the rel, the relcache update happens via
126 * CommandCounterIncrement, not here.)
127 *
128 * However, in corner cases where code acts on tables (usually catalogs)
129 * recursively, we might get here while still processing invalidation
130 * messages in some outer execution of this function or a sibling. The
131 * "cleared" status of the lock tells us whether we really are done
132 * absorbing relevant inval messages.
133 */
134 if (res != LOCKACQUIRE_ALREADY_CLEAR)
135 {
137 MarkLockClear(locallock);
138 }
139}

References AcceptInvalidationMessages(), LOCKACQUIRE_ALREADY_CLEAR, LockAcquireExtended(), MarkLockClear(), and SetLocktagRelationOid().

Referenced by AcquireDeletionLock(), AcquireExecutorLocks(), AlterTableMoveAll(), ATExecAttachPartition(), ATExecDetachPartition(), ATPostAlterTypeCleanup(), binary_upgrade_replorigin_advance(), copy_table_data(), CreateTriggerFiringOn(), ExecDoInitialPruning(), find_inheritance_children_extended(), heap_create_with_catalog(), heap_drop_with_catalog(), index_create(), IndexSetParentIndex(), InitCatCachePhase2(), load_critical_index(), lock_and_open_sequence(), LockTableRecurse(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), pg_replication_origin_advance(), RangeVarCallbackForAttachIndex(), RangeVarCallbackForDropRelation(), RangeVarCallbackForReindexIndex(), RangeVarGetAndCheckCreationNamespace(), RangeVarGetRelidExtended(), relation_open(), ScanQueryForLocks(), SequenceChangePersistence(), and try_relation_open().

◆ LockSharedObject()

void LockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

◆ LockSharedObjectForSession()

void LockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1163 of file lmgr.c.

1165{
1166 LOCKTAG tag;
1167
1169 InvalidOid,
1170 classid,
1171 objid,
1172 objsubid);
1173
1174 (void) LockAcquire(&tag, lockmode, true, false);
1175}

References InvalidOid, LockAcquire(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

◆ LockTuple()

◆ RelationExtensionLockWaiterCount()

int RelationExtensionLockWaiterCount ( Relation  relation)

Definition at line 459 of file lmgr.c.

460{
461 LOCKTAG tag;
462
464 relation->rd_lockInfo.lockRelId.dbId,
465 relation->rd_lockInfo.lockRelId.relId);
466
467 return LockWaiterCount(&tag);
468}
int LockWaiterCount(const LOCKTAG *locktag)
Definition: lock.c:4812

References LockRelId::dbId, LockInfoData::lockRelId, LockWaiterCount(), RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION_EXTEND.

Referenced by RelationAddBlocks().

◆ RelationInitLockInfo()

void RelationInitLockInfo ( Relation  relation)

Definition at line 70 of file lmgr.c.

71{
72 Assert(RelationIsValid(relation));
74
75 relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
76
77 if (relation->rd_rel->relisshared)
79 else
81}
#define OidIsValid(objectId)
Definition: c.h:746
#define RelationGetRelid(relation)
Definition: rel.h:513
#define RelationIsValid(relation)
Definition: rel.h:486
Form_pg_class rd_rel
Definition: rel.h:111

References Assert(), LockRelId::dbId, InvalidOid, LockInfoData::lockRelId, MyDatabaseId, OidIsValid, RelationData::rd_lockInfo, RelationData::rd_rel, RelationGetRelid, RelationIsValid, and LockRelId::relId.

Referenced by formrdesc(), load_relcache_init_file(), RelationBuildDesc(), and RelationBuildLocalRelation().

◆ SetLocktagRelationOid()

static void SetLocktagRelationOid ( LOCKTAG tag,
Oid  relid 
)
inlinestatic

Definition at line 88 of file lmgr.c.

89{
90 Oid dbid;
91
92 if (IsSharedRelation(relid))
93 dbid = InvalidOid;
94 else
95 dbid = MyDatabaseId;
96
97 SET_LOCKTAG_RELATION(*tag, dbid, relid);
98}
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:273
unsigned int Oid
Definition: postgres_ext.h:32

References InvalidOid, IsSharedRelation(), MyDatabaseId, and SET_LOCKTAG_RELATION.

Referenced by CheckRelationOidLockedByMe(), ConditionalLockRelationOid(), LockRelationOid(), and UnlockRelationOid().

◆ SpeculativeInsertionLockAcquire()

uint32 SpeculativeInsertionLockAcquire ( TransactionId  xid)

Definition at line 780 of file lmgr.c.

781{
782 LOCKTAG tag;
783
785
786 /*
787 * Check for wrap-around. Zero means no token is held, so don't use that.
788 */
791
793
794 (void) LockAcquire(&tag, ExclusiveLock, false, false);
795
797}
static uint32 speculativeInsertionToken
Definition: lmgr.c:45
#define SET_LOCKTAG_SPECULATIVE_INSERTION(locktag, xid, token)
Definition: lock.h:248
#define ExclusiveLock
Definition: lockdefs.h:42

References ExclusiveLock, LockAcquire(), SET_LOCKTAG_SPECULATIVE_INSERTION, and speculativeInsertionToken.

Referenced by ExecInsert().

◆ SpeculativeInsertionLockRelease()

void SpeculativeInsertionLockRelease ( TransactionId  xid)

Definition at line 806 of file lmgr.c.

807{
808 LOCKTAG tag;
809
811
812 LockRelease(&tag, ExclusiveLock, false);
813}

References ExclusiveLock, LockRelease(), SET_LOCKTAG_SPECULATIVE_INSERTION, and speculativeInsertionToken.

Referenced by ExecInsert().

◆ SpeculativeInsertionWait()

void SpeculativeInsertionWait ( TransactionId  xid,
uint32  token 
)

Definition at line 822 of file lmgr.c.

823{
824 LOCKTAG tag;
825
827
829 Assert(token != 0);
830
831 (void) LockAcquire(&tag, ShareLock, false, false);
832 LockRelease(&tag, ShareLock, false);
833}

References Assert(), LockAcquire(), LockRelease(), SET_LOCKTAG_SPECULATIVE_INSERTION, ShareLock, and TransactionIdIsValid.

Referenced by _bt_doinsert(), and check_exclusion_or_unique_constraint().

◆ UnlockApplyTransactionForSession()

void UnlockApplyTransactionForSession ( Oid  suboid,
TransactionId  xid,
uint16  objid,
LOCKMODE  lockmode 
)

Definition at line 1221 of file lmgr.c.

1223{
1224 LOCKTAG tag;
1225
1228 suboid,
1229 xid,
1230 objid);
1231
1232 LockRelease(&tag, lockmode, true);
1233}

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_APPLY_TRANSACTION.

Referenced by pa_unlock_stream(), and pa_unlock_transaction().

◆ UnlockDatabaseObject()

void UnlockDatabaseObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1062 of file lmgr.c.

1064{
1065 LOCKTAG tag;
1066
1069 classid,
1070 objid,
1071 objsubid);
1072
1073 LockRelease(&tag, lockmode, false);
1074}

References LockRelease(), MyDatabaseId, and SET_LOCKTAG_OBJECT.

Referenced by get_object_address(), RangeVarGetAndCheckCreationNamespace(), and ReleaseDeletionLock().

◆ UnlockPage()

void UnlockPage ( Relation  relation,
BlockNumber  blkno,
LOCKMODE  lockmode 
)

Definition at line 542 of file lmgr.c.

543{
544 LOCKTAG tag;
545
547 relation->rd_lockInfo.lockRelId.dbId,
548 relation->rd_lockInfo.lockRelId.relId,
549 blkno);
550
551 LockRelease(&tag, lockmode, false);
552}

References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_PAGE.

Referenced by ginInsertCleanup().

◆ UnlockRelation()

void UnlockRelation ( Relation  relation,
LOCKMODE  lockmode 
)

Definition at line 314 of file lmgr.c.

315{
316 LOCKTAG tag;
317
319 relation->rd_lockInfo.lockRelId.dbId,
320 relation->rd_lockInfo.lockRelId.relId);
321
322 LockRelease(&tag, lockmode, false);
323}

References LockRelId::dbId, LockRelease(), LockInfoData::lockRelId, RelationData::rd_lockInfo, LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by lazy_truncate_heap().

◆ UnlockRelationForExtension()

◆ UnlockRelationId()

void UnlockRelationId ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 214 of file lmgr.c.

215{
216 LOCKTAG tag;
217
218 SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
219
220 LockRelease(&tag, lockmode, false);
221}

References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by CreateDatabaseUsingWalLog(), index_close(), relation_close(), and ScanSourceDatabasePgClass().

◆ UnlockRelationIdForSession()

void UnlockRelationIdForSession ( LockRelId relid,
LOCKMODE  lockmode 
)

Definition at line 404 of file lmgr.c.

405{
406 LOCKTAG tag;
407
408 SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
409
410 LockRelease(&tag, lockmode, true);
411}

References LockRelId::dbId, LockRelease(), LockRelId::relId, and SET_LOCKTAG_RELATION.

Referenced by DefineIndex(), index_drop(), ReindexRelationConcurrently(), and vacuum_rel().

◆ UnlockRelationOid()

◆ UnlockSharedObject()

void UnlockSharedObject ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1142 of file lmgr.c.

1144{
1145 LOCKTAG tag;
1146
1148 InvalidOid,
1149 classid,
1150 objid,
1151 objsubid);
1152
1153 LockRelease(&tag, lockmode, false);
1154}

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by AddSubscriptionRelState(), AlterDatabaseSet(), createdb_failure_callback(), drop_local_obsolete_slots(), get_db_info(), get_object_address(), replorigin_drop_by_name(), and synchronize_slots().

◆ UnlockSharedObjectForSession()

void UnlockSharedObjectForSession ( Oid  classid,
Oid  objid,
uint16  objsubid,
LOCKMODE  lockmode 
)

Definition at line 1181 of file lmgr.c.

1183{
1184 LOCKTAG tag;
1185
1187 InvalidOid,
1188 classid,
1189 objid,
1190 objsubid);
1191
1192 LockRelease(&tag, lockmode, true);
1193}

References InvalidOid, LockRelease(), and SET_LOCKTAG_OBJECT.

Referenced by dbase_redo(), and movedb().

◆ UnlockTuple()

◆ WaitForLockers()

void WaitForLockers ( LOCKTAG  heaplocktag,
LOCKMODE  lockmode,
bool  progress 
)

Definition at line 983 of file lmgr.c.

984{
985 List *l;
986
987 l = list_make1(&heaplocktag);
988 WaitForLockersMultiple(l, lockmode, progress);
989 list_free(l);
990}
void list_free(List *list)
Definition: list.c:1546
void WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
Definition: lmgr.c:905
#define list_make1(x1)
Definition: pg_list.h:212
static int progress
Definition: pgbench.c:262
Definition: pg_list.h:54

References list_free(), list_make1, progress, and WaitForLockersMultiple().

Referenced by DefineIndex(), and index_drop().

◆ WaitForLockersMultiple()

void WaitForLockersMultiple ( List locktags,
LOCKMODE  lockmode,
bool  progress 
)

Definition at line 905 of file lmgr.c.

906{
907 List *holders = NIL;
908 ListCell *lc;
909 int total = 0;
910 int done = 0;
911
912 /* Done if no locks to wait for */
913 if (locktags == NIL)
914 return;
915
916 /* Collect the transactions we need to wait on */
917 foreach(lc, locktags)
918 {
919 LOCKTAG *locktag = lfirst(lc);
920 int count;
921
922 holders = lappend(holders,
923 GetLockConflicts(locktag, lockmode,
924 progress ? &count : NULL));
925 if (progress)
926 total += count;
927 }
928
929 if (progress)
931
932 /*
933 * Note: GetLockConflicts() never reports our own xid, hence we need not
934 * check for that. Also, prepared xacts are reported and awaited.
935 */
936
937 /* Finally wait for each such transaction to complete */
938 foreach(lc, holders)
939 {
940 VirtualTransactionId *lockholders = lfirst(lc);
941
942 while (VirtualTransactionIdIsValid(*lockholders))
943 {
944 /* If requested, publish who we're going to wait for. */
945 if (progress)
946 {
947 PGPROC *holder = ProcNumberGetProc(lockholders->procNumber);
948
949 if (holder)
951 holder->pid);
952 }
953 VirtualXactLock(*lockholders, true);
954 lockholders++;
955
956 if (progress)
958 }
959 }
960 if (progress)
961 {
962 const int index[] = {
966 };
967 const int64 values[] = {
968 0, 0, 0
969 };
970
972 }
973
974 list_free_deep(holders);
975}
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
static Datum values[MAXATTR]
Definition: bootstrap.c:151
int64_t int64
Definition: c.h:499
List * lappend(List *list, void *datum)
Definition: list.c:339
void list_free_deep(List *list)
Definition: list.c:1560
bool VirtualXactLock(VirtualTransactionId vxid, bool wait)
Definition: lock.c:4701
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition: lock.c:3025
#define VirtualTransactionIdIsValid(vxid)
Definition: lock.h:68
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
PGPROC * ProcNumberGetProc(ProcNumber procNumber)
Definition: procarray.c:3138
#define PROGRESS_WAITFOR_DONE
Definition: progress.h:120
#define PROGRESS_WAITFOR_TOTAL
Definition: progress.h:119
#define PROGRESS_WAITFOR_CURRENT_PID
Definition: progress.h:121
Definition: proc.h:163
int pid
Definition: proc.h:183
ProcNumber procNumber
Definition: lock.h:62
Definition: type.h:96

References GetLockConflicts(), lappend(), lfirst, list_free_deep(), NIL, pgstat_progress_update_multi_param(), pgstat_progress_update_param(), PGPROC::pid, VirtualTransactionId::procNumber, ProcNumberGetProc(), progress, PROGRESS_WAITFOR_CURRENT_PID, PROGRESS_WAITFOR_DONE, PROGRESS_WAITFOR_TOTAL, values, VirtualTransactionIdIsValid, and VirtualXactLock().

Referenced by ATExecDetachPartition(), ReindexRelationConcurrently(), and WaitForLockers().

◆ XactLockTableDelete()

void XactLockTableDelete ( TransactionId  xid)

Definition at line 639 of file lmgr.c.

640{
641 LOCKTAG tag;
642
643 SET_LOCKTAG_TRANSACTION(tag, xid);
644
645 LockRelease(&tag, ExclusiveLock, false);
646}

References ExclusiveLock, LockRelease(), and SET_LOCKTAG_TRANSACTION.

Referenced by CommitSubTransaction().

◆ XactLockTableInsert()

void XactLockTableInsert ( TransactionId  xid)

Definition at line 622 of file lmgr.c.

623{
624 LOCKTAG tag;
625
626 SET_LOCKTAG_TRANSACTION(tag, xid);
627
628 (void) LockAcquire(&tag, ExclusiveLock, false, false);
629}

References ExclusiveLock, LockAcquire(), and SET_LOCKTAG_TRANSACTION.

Referenced by AssignTransactionId().

◆ XactLockTableWait()

void XactLockTableWait ( TransactionId  xid,
Relation  rel,
ItemPointer  ctid,
XLTW_Oper  oper 
)

Definition at line 663 of file lmgr.c.

665{
666 LOCKTAG tag;
669 bool first = true;
670
671 /*
672 * If an operation is specified, set up our verbose error context
673 * callback.
674 */
675 if (oper != XLTW_None)
676 {
679
680 info.rel = rel;
681 info.ctid = ctid;
682 info.oper = oper;
683
685 callback.arg = &info;
686 callback.previous = error_context_stack;
688 }
689
690 for (;;)
691 {
694
695 SET_LOCKTAG_TRANSACTION(tag, xid);
696
697 (void) LockAcquire(&tag, ShareLock, false, false);
698
699 LockRelease(&tag, ShareLock, false);
700
702 break;
703
704 /*
705 * If the Xid belonged to a subtransaction, then the lock would have
706 * gone away as soon as it was finished; for correct tuple visibility,
707 * the right action is to wait on its parent transaction to go away.
708 * But instead of going levels up one by one, we can just wait for the
709 * topmost transaction to finish with the same end result, which also
710 * incurs less locktable traffic.
711 *
712 * Some uses of this function don't involve tuple visibility -- such
713 * as when building snapshots for logical decoding. It is possible to
714 * see a transaction in ProcArray before it registers itself in the
715 * locktable. The topmost transaction in that case is the same xid,
716 * so we try again after a short sleep. (Don't sleep the first time
717 * through, to avoid slowing down the normal case.)
718 */
719 if (!first)
720 pg_usleep(1000L);
721 first = false;
723 }
724
725 if (oper != XLTW_None)
726 error_context_stack = callback.previous;
727}
ErrorContextCallback * error_context_stack
Definition: elog.c:94
static bool ItemPointerIsValid(const ItemPointerData *pointer)
Definition: itemptr.h:83
static void XactLockTableWaitErrorCb(void *arg)
Definition: lmgr.c:840
@ XLTW_None
Definition: lmgr.h:26
Operator oper(ParseState *pstate, List *opname, Oid ltypeId, Oid rtypeId, bool noError, int location)
Definition: parse_oper.c:370
ItemPointer ctid
Definition: lmgr.c:58
XLTW_Oper oper
Definition: lmgr.c:56
Relation rel
Definition: lmgr.c:57
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46

References Assert(), callback(), XactLockTableWaitInfo::ctid, error_context_stack, GetTopTransactionIdIfAny(), ItemPointerIsValid(), LockAcquire(), LockRelease(), oper(), XactLockTableWaitInfo::oper, pg_usleep(), XactLockTableWaitInfo::rel, RelationIsValid, SET_LOCKTAG_TRANSACTION, ShareLock, SubTransGetTopmostTransaction(), TransactionIdEquals, TransactionIdIsInProgress(), TransactionIdIsValid, XactLockTableWaitErrorCb(), and XLTW_None.

Referenced by _bt_doinsert(), check_exclusion_or_unique_constraint(), Do_MultiXactIdWait(), heap_delete(), heap_inplace_lock(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_update(), heapam_index_build_range_scan(), heapam_tuple_lock(), RelationFindReplTupleByIndex(), RelationFindReplTupleSeq(), and SnapBuildWaitSnapshot().

◆ XactLockTableWaitErrorCb()

static void XactLockTableWaitErrorCb ( void *  arg)
static

Definition at line 840 of file lmgr.c.

841{
843
844 /*
845 * We would like to print schema name too, but that would require a
846 * syscache lookup.
847 */
848 if (info->oper != XLTW_None &&
850 {
851 const char *cxt;
852
853 switch (info->oper)
854 {
855 case XLTW_Update:
856 cxt = gettext_noop("while updating tuple (%u,%u) in relation \"%s\"");
857 break;
858 case XLTW_Delete:
859 cxt = gettext_noop("while deleting tuple (%u,%u) in relation \"%s\"");
860 break;
861 case XLTW_Lock:
862 cxt = gettext_noop("while locking tuple (%u,%u) in relation \"%s\"");
863 break;
864 case XLTW_LockUpdated:
865 cxt = gettext_noop("while locking updated version (%u,%u) of tuple in relation \"%s\"");
866 break;
867 case XLTW_InsertIndex:
868 cxt = gettext_noop("while inserting index tuple (%u,%u) in relation \"%s\"");
869 break;
871 cxt = gettext_noop("while checking uniqueness of tuple (%u,%u) in relation \"%s\"");
872 break;
874 cxt = gettext_noop("while rechecking updated tuple (%u,%u) in relation \"%s\"");
875 break;
877 cxt = gettext_noop("while checking exclusion constraint on tuple (%u,%u) in relation \"%s\"");
878 break;
879
880 default:
881 return;
882 }
883
884 errcontext(cxt,
888 }
889}
#define gettext_noop(x)
Definition: c.h:1167
#define errcontext
Definition: elog.h:196
@ XLTW_FetchUpdated
Definition: lmgr.h:33
@ 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 * arg
#define RelationGetRelationName(relation)
Definition: rel.h:547

References arg, XactLockTableWaitInfo::ctid, errcontext, gettext_noop, ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), ItemPointerIsValid(), XactLockTableWaitInfo::oper, XactLockTableWaitInfo::rel, RelationGetRelationName, RelationIsValid, XLTW_Delete, XLTW_FetchUpdated, XLTW_InsertIndex, XLTW_InsertIndexUnique, XLTW_Lock, XLTW_LockUpdated, XLTW_None, XLTW_RecheckExclusionConstr, and XLTW_Update.

Referenced by XactLockTableWait().

Variable Documentation

◆ speculativeInsertionToken

uint32 speculativeInsertionToken = 0
static

Definition at line 45 of file lmgr.c.

Referenced by SpeculativeInsertionLockAcquire(), and SpeculativeInsertionLockRelease().