lmgr.c 17.7 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * lmgr.c
4
 *	  POSTGRES lock manager code
5
 *
B
Bruce Momjian 已提交
6
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
7
 * Portions Copyright (c) 1994, Regents of the University of California
8 9 10
 *
 *
 * IDENTIFICATION
11
 *	  src/backend/storage/lmgr/lmgr.c
12 13 14
 *
 *-------------------------------------------------------------------------
 */
15

16
#include "postgres.h"
17

18
#include "access/subtrans.h"
19 20
#include "access/transam.h"
#include "access/xact.h"
21
#include "catalog/catalog.h"
22
#include "miscadmin.h"
23
#include "storage/lmgr.h"
24
#include "storage/procarray.h"
25
#include "utils/inval.h"
26 27 28


/*
B
Bruce Momjian 已提交
29
 * RelationInitLockInfo
30
 *		Initializes the lock information in a relation descriptor.
31 32
 *
 *		relcache.c must call this during creation of any reldesc.
33 34 35 36
 */
void
RelationInitLockInfo(Relation relation)
{
37
	Assert(RelationIsValid(relation));
38
	Assert(OidIsValid(RelationGetRelid(relation)));
39

40
	relation->rd_lockInfo.lockRelId.relId = RelationGetRelid(relation);
41

42
	if (relation->rd_rel->relisshared)
43
		relation->rd_lockInfo.lockRelId.dbId = InvalidOid;
44
	else
45
		relation->rd_lockInfo.lockRelId.dbId = MyDatabaseId;
46 47
}

48 49 50 51 52 53 54
/*
 * SetLocktagRelationOid
 *		Set up a locktag for a relation, given only relation OID
 */
static inline void
SetLocktagRelationOid(LOCKTAG *tag, Oid relid)
{
B
Bruce Momjian 已提交
55
	Oid			dbid;
56 57 58 59 60 61 62 63 64 65 66 67

	if (IsSharedRelation(relid))
		dbid = InvalidOid;
	else
		dbid = MyDatabaseId;

	SET_LOCKTAG_RELATION(*tag, dbid, relid);
}

/*
 *		LockRelationOid
 *
B
Bruce Momjian 已提交
68
 * Lock a relation given only its OID.	This should generally be used
69 70 71 72 73 74 75 76 77 78 79 80 81
 * before attempting to open the relation's relcache entry.
 */
void
LockRelationOid(Oid relid, LOCKMODE lockmode)
{
	LOCKTAG		tag;
	LockAcquireResult res;

	SetLocktagRelationOid(&tag, relid);

	res = LockAcquire(&tag, lockmode, false, false);

	/*
B
Bruce Momjian 已提交
82 83 84 85 86 87 88
	 * Now that we have the lock, check for invalidation messages, so that we
	 * will update or flush any stale relcache entry before we try to use it.
	 * We can skip this in the not-uncommon case that we already had the same
	 * type of lock being requested, since then no one else could have
	 * modified the relcache entry in an undesirable way.  (In the case where
	 * our own xact modifies the rel, the relcache update happens via
	 * CommandCounterIncrement, not here.)
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
	 */
	if (res != LOCKACQUIRE_ALREADY_HELD)
		AcceptInvalidationMessages();
}

/*
 *		ConditionalLockRelationOid
 *
 * As above, but only lock if we can get the lock without blocking.
 * Returns TRUE iff the lock was acquired.
 *
 * NOTE: we do not currently need conditional versions of all the
 * LockXXX routines in this file, but they could easily be added if needed.
 */
bool
ConditionalLockRelationOid(Oid relid, LOCKMODE lockmode)
{
	LOCKTAG		tag;
	LockAcquireResult res;

	SetLocktagRelationOid(&tag, relid);

	res = LockAcquire(&tag, lockmode, false, true);

	if (res == LOCKACQUIRE_NOT_AVAIL)
		return false;

	/*
B
Bruce Momjian 已提交
117 118
	 * Now that we have the lock, check for invalidation messages; see notes
	 * in LockRelationOid.
119 120 121 122 123 124 125 126 127 128
	 */
	if (res != LOCKACQUIRE_ALREADY_HELD)
		AcceptInvalidationMessages();

	return true;
}

/*
 *		UnlockRelationId
 *
129 130
 * Unlock, given a LockRelId.  This is preferred over UnlockRelationOid
 * for speed reasons.
131 132 133 134 135 136 137 138 139 140 141
 */
void
UnlockRelationId(LockRelId *relid, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);

	LockRelease(&tag, lockmode, false);
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
/*
 *		UnlockRelationOid
 *
 * Unlock, given only a relation Oid.  Use UnlockRelationId if you can.
 */
void
UnlockRelationOid(Oid relid, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SetLocktagRelationOid(&tag, relid);

	LockRelease(&tag, lockmode, false);
}

157
/*
V
Vadim B. Mikheev 已提交
158
 *		LockRelation
159 160 161 162
 *
 * This is a convenience routine for acquiring an additional lock on an
 * already-open relation.  Never try to do "relation_open(foo, NoLock)"
 * and then lock with this.
163 164
 */
void
V
Vadim B. Mikheev 已提交
165
LockRelation(Relation relation, LOCKMODE lockmode)
166
{
V
Vadim B. Mikheev 已提交
167
	LOCKTAG		tag;
168
	LockAcquireResult res;
169

170 171 172
	SET_LOCKTAG_RELATION(tag,
						 relation->rd_lockInfo.lockRelId.dbId,
						 relation->rd_lockInfo.lockRelId.relId);
V
Vadim B. Mikheev 已提交
173

174
	res = LockAcquire(&tag, lockmode, false, false);
175 176

	/*
B
Bruce Momjian 已提交
177 178
	 * Now that we have the lock, check for invalidation messages; see notes
	 * in LockRelationOid.
179
	 */
180 181
	if (res != LOCKACQUIRE_ALREADY_HELD)
		AcceptInvalidationMessages();
V
Vadim B. Mikheev 已提交
182
}
183

184 185 186
/*
 *		ConditionalLockRelation
 *
187 188 189
 * This is a convenience routine for acquiring an additional lock on an
 * already-open relation.  Never try to do "relation_open(foo, NoLock)"
 * and then lock with this.
190 191 192 193 194
 */
bool
ConditionalLockRelation(Relation relation, LOCKMODE lockmode)
{
	LOCKTAG		tag;
195
	LockAcquireResult res;
196

197 198 199
	SET_LOCKTAG_RELATION(tag,
						 relation->rd_lockInfo.lockRelId.dbId,
						 relation->rd_lockInfo.lockRelId.relId);
200

201
	res = LockAcquire(&tag, lockmode, false, true);
202 203

	if (res == LOCKACQUIRE_NOT_AVAIL)
204 205 206
		return false;

	/*
B
Bruce Momjian 已提交
207 208
	 * Now that we have the lock, check for invalidation messages; see notes
	 * in LockRelationOid.
209
	 */
210 211
	if (res != LOCKACQUIRE_ALREADY_HELD)
		AcceptInvalidationMessages();
212 213 214 215

	return true;
}

216
/*
V
Vadim B. Mikheev 已提交
217
 *		UnlockRelation
218 219 220
 *
 * This is a convenience routine for unlocking a relation without also
 * closing it.
221 222
 */
void
V
Vadim B. Mikheev 已提交
223
UnlockRelation(Relation relation, LOCKMODE lockmode)
224
{
V
Vadim B. Mikheev 已提交
225
	LOCKTAG		tag;
226

227 228 229
	SET_LOCKTAG_RELATION(tag,
						 relation->rd_lockInfo.lockRelId.dbId,
						 relation->rd_lockInfo.lockRelId.relId);
230

231
	LockRelease(&tag, lockmode, false);
232 233 234
}

/*
235
 *		LockRelationIdForSession
236
 *
B
Bruce Momjian 已提交
237
 * This routine grabs a session-level lock on the target relation.	The
238
 * session lock persists across transaction boundaries.  It will be removed
239
 * when UnlockRelationIdForSession() is called, or if an ereport(ERROR) occurs,
240 241 242 243 244 245 246
 * or if the backend exits.
 *
 * Note that one should also grab a transaction-level lock on the rel
 * in any transaction that actually uses the rel, to ensure that the
 * relcache entry is up to date.
 */
void
247
LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
248 249 250
{
	LOCKTAG		tag;

251
	SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
252

253
	(void) LockAcquire(&tag, lockmode, true, false);
254 255 256
}

/*
257
 *		UnlockRelationIdForSession
258 259
 */
void
260
UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)
261 262 263
{
	LOCKTAG		tag;

264
	SET_LOCKTAG_RELATION(tag, relid->dbId, relid->relId);
265

266
	LockRelease(&tag, lockmode, true);
V
Vadim B. Mikheev 已提交
267
}
268

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
/*
 *		LockRelationForExtension
 *
 * This lock tag is used to interlock addition of pages to relations.
 * We need such locking because bufmgr/smgr definition of P_NEW is not
 * race-condition-proof.
 *
 * We assume the caller is already holding some type of regular lock on
 * the relation, so no AcceptInvalidationMessages call is needed here.
 */
void
LockRelationForExtension(Relation relation, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_RELATION_EXTEND(tag,
								relation->rd_lockInfo.lockRelId.dbId,
								relation->rd_lockInfo.lockRelId.relId);

288
	(void) LockAcquire(&tag, lockmode, false, false);
289 290 291 292 293 294 295 296 297 298 299 300 301 302
}

/*
 *		UnlockRelationForExtension
 */
void
UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_RELATION_EXTEND(tag,
								relation->rd_lockInfo.lockRelId.dbId,
								relation->rd_lockInfo.lockRelId.relId);

303
	LockRelease(&tag, lockmode, false);
304 305
}

306
/*
V
Vadim B. Mikheev 已提交
307
 *		LockPage
308 309
 *
 * Obtain a page-level lock.  This is currently used by some index access
310
 * methods to lock individual index pages.
311 312
 */
void
V
Vadim B. Mikheev 已提交
313
LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
314
{
V
Vadim B. Mikheev 已提交
315
	LOCKTAG		tag;
316

317 318 319 320
	SET_LOCKTAG_PAGE(tag,
					 relation->rd_lockInfo.lockRelId.dbId,
					 relation->rd_lockInfo.lockRelId.relId,
					 blkno);
V
Vadim B. Mikheev 已提交
321

322
	(void) LockAcquire(&tag, lockmode, false, false);
V
Vadim B. Mikheev 已提交
323
}
324

325 326 327 328 329 330 331 332 333 334 335
/*
 *		ConditionalLockPage
 *
 * As above, but only lock if we can get the lock without blocking.
 * Returns TRUE iff the lock was acquired.
 */
bool
ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
{
	LOCKTAG		tag;

336 337 338 339
	SET_LOCKTAG_PAGE(tag,
					 relation->rd_lockInfo.lockRelId.dbId,
					 relation->rd_lockInfo.lockRelId.relId,
					 blkno);
340

341
	return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
342 343
}

344
/*
V
Vadim B. Mikheev 已提交
345
 *		UnlockPage
346 347
 */
void
V
Vadim B. Mikheev 已提交
348
UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
349
{
V
Vadim B. Mikheev 已提交
350
	LOCKTAG		tag;
351

352 353 354 355
	SET_LOCKTAG_PAGE(tag,
					 relation->rd_lockInfo.lockRelId.dbId,
					 relation->rd_lockInfo.lockRelId.relId,
					 blkno);
356

357
	LockRelease(&tag, lockmode, false);
358 359
}

360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
/*
 *		LockTuple
 *
 * Obtain a tuple-level lock.  This is used in a less-than-intuitive fashion
 * because we can't afford to keep a separate lock in shared memory for every
 * tuple.  See heap_lock_tuple before using this!
 */
void
LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_TUPLE(tag,
					  relation->rd_lockInfo.lockRelId.dbId,
					  relation->rd_lockInfo.lockRelId.relId,
					  ItemPointerGetBlockNumber(tid),
					  ItemPointerGetOffsetNumber(tid));

378
	(void) LockAcquire(&tag, lockmode, false, false);
379 380
}

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
/*
 *		ConditionalLockTuple
 *
 * As above, but only lock if we can get the lock without blocking.
 * Returns TRUE iff the lock was acquired.
 */
bool
ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_TUPLE(tag,
					  relation->rd_lockInfo.lockRelId.dbId,
					  relation->rd_lockInfo.lockRelId.relId,
					  ItemPointerGetBlockNumber(tid),
					  ItemPointerGetOffsetNumber(tid));

398
	return (LockAcquire(&tag, lockmode, false, true) != LOCKACQUIRE_NOT_AVAIL);
399 400
}

401 402 403 404 405 406 407 408 409 410 411 412 413 414
/*
 *		UnlockTuple
 */
void
UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_TUPLE(tag,
					  relation->rd_lockInfo.lockRelId.dbId,
					  relation->rd_lockInfo.lockRelId.relId,
					  ItemPointerGetBlockNumber(tid),
					  ItemPointerGetOffsetNumber(tid));

415
	LockRelease(&tag, lockmode, false);
416 417
}

418 419 420 421
/*
 *		XactLockTableInsert
 *
 * Insert a lock showing that the given transaction ID is running ---
422 423
 * this is done when an XID is acquired by a transaction or subtransaction.
 * The lock can then be used to wait for the transaction to finish.
424
 */
425
void
V
Vadim B. Mikheev 已提交
426
XactLockTableInsert(TransactionId xid)
427
{
V
Vadim B. Mikheev 已提交
428
	LOCKTAG		tag;
429

430
	SET_LOCKTAG_TRANSACTION(tag, xid);
431

432
	(void) LockAcquire(&tag, ExclusiveLock, false, false);
433 434
}

435 436 437 438 439
/*
 *		XactLockTableDelete
 *
 * Delete the lock showing that the given transaction ID is running.
 * (This is never used for main transaction IDs; those locks are only
440
 * released implicitly at transaction end.	But we do use it for subtrans IDs.)
441 442 443 444 445 446
 */
void
XactLockTableDelete(TransactionId xid)
{
	LOCKTAG		tag;

447
	SET_LOCKTAG_TRANSACTION(tag, xid);
448

449
	LockRelease(&tag, ExclusiveLock, false);
450 451
}

452 453 454 455
/*
 *		XactLockTableWait
 *
 * Wait for the specified transaction to commit or abort.
456
 *
457 458 459 460
 * Note that this does the right thing for subtransactions: if we wait on a
 * subtransaction, we will exit as soon as it aborts or its top parent commits.
 * It takes some extra work to ensure this, because to save on shared memory
 * the XID lock of a subtransaction is released when it ends, whether
B
Bruce Momjian 已提交
461
 * successfully or unsuccessfully.	So we have to check if it's "still running"
462
 * and if so wait for its parent.
463
 */
464
void
V
Vadim B. Mikheev 已提交
465
XactLockTableWait(TransactionId xid)
466
{
V
Vadim B. Mikheev 已提交
467
	LOCKTAG		tag;
468

469 470 471
	for (;;)
	{
		Assert(TransactionIdIsValid(xid));
472
		Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny()));
473

474
		SET_LOCKTAG_TRANSACTION(tag, xid);
475

476
		(void) LockAcquire(&tag, ShareLock, false, false);
477

478
		LockRelease(&tag, ShareLock, false);
479

480 481 482 483
		if (!TransactionIdIsInProgress(xid))
			break;
		xid = SubTransGetParent(xid);
	}
484
}
485

486 487 488 489 490 491 492 493 494 495 496 497 498 499
/*
 *		ConditionalXactLockTableWait
 *
 * As above, but only lock if we can get the lock without blocking.
 * Returns TRUE if the lock was acquired.
 */
bool
ConditionalXactLockTableWait(TransactionId xid)
{
	LOCKTAG		tag;

	for (;;)
	{
		Assert(TransactionIdIsValid(xid));
500
		Assert(!TransactionIdEquals(xid, GetTopTransactionIdIfAny()));
501 502 503

		SET_LOCKTAG_TRANSACTION(tag, xid);

504
		if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
505 506
			return false;

507
		LockRelease(&tag, ShareLock, false);
508 509 510 511 512 513 514 515

		if (!TransactionIdIsInProgress(xid))
			break;
		xid = SubTransGetParent(xid);
	}

	return true;
}
516

517 518

/*
B
Bruce Momjian 已提交
519
 *		VirtualXactLockTableInsert
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
 *
 * Insert a lock showing that the given virtual transaction ID is running ---
 * this is done at main transaction start when its VXID is assigned.
 * The lock can then be used to wait for the transaction to finish.
 */
void
VirtualXactLockTableInsert(VirtualTransactionId vxid)
{
	LOCKTAG		tag;

	Assert(VirtualTransactionIdIsValid(vxid));

	SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);

	(void) LockAcquire(&tag, ExclusiveLock, false, false);
}

/*
B
Bruce Momjian 已提交
538
 *		VirtualXactLockTableWait
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
 *
 * Waits until the lock on the given VXID is released, which shows that
 * the top-level transaction owning the VXID has ended.
 */
void
VirtualXactLockTableWait(VirtualTransactionId vxid)
{
	LOCKTAG		tag;

	Assert(VirtualTransactionIdIsValid(vxid));

	SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);

	(void) LockAcquire(&tag, ShareLock, false, false);

	LockRelease(&tag, ShareLock, false);
}

/*
B
Bruce Momjian 已提交
558
 *		ConditionalVirtualXactLockTableWait
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
 *
 * As above, but only lock if we can get the lock without blocking.
 * Returns TRUE if the lock was acquired.
 */
bool
ConditionalVirtualXactLockTableWait(VirtualTransactionId vxid)
{
	LOCKTAG		tag;

	Assert(VirtualTransactionIdIsValid(vxid));

	SET_LOCKTAG_VIRTUALTRANSACTION(tag, vxid);

	if (LockAcquire(&tag, ShareLock, false, true) == LOCKACQUIRE_NOT_AVAIL)
		return false;

	LockRelease(&tag, ShareLock, false);

	return true;
}


581 582 583 584
/*
 *		LockDatabaseObject
 *
 * Obtain a lock on a general object of the current database.  Don't use
585 586
 * this for shared objects (such as tablespaces).  It's unwise to apply it
 * to relations, also, since a lock taken this way will NOT conflict with
587
 * locks taken via LockRelation and friends.
588 589 590 591 592 593 594 595 596 597 598 599 600
 */
void
LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
				   LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   MyDatabaseId,
					   classid,
					   objid,
					   objsubid);

601
	(void) LockAcquire(&tag, lockmode, false, false);
602 603 604

	/* Make sure syscaches are up-to-date with any changes we waited for */
	AcceptInvalidationMessages();
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
}

/*
 *		UnlockDatabaseObject
 */
void
UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
					 LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   MyDatabaseId,
					   classid,
					   objid,
					   objsubid);

622
	LockRelease(&tag, lockmode, false);
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
}

/*
 *		LockSharedObject
 *
 * Obtain a lock on a shared-across-databases object.
 */
void
LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
				 LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   InvalidOid,
					   classid,
					   objid,
					   objsubid);

642
	(void) LockAcquire(&tag, lockmode, false, false);
643 644 645

	/* Make sure syscaches are up-to-date with any changes we waited for */
	AcceptInvalidationMessages();
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
}

/*
 *		UnlockSharedObject
 */
void
UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
				   LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   InvalidOid,
					   classid,
					   objid,
					   objsubid);

663
	LockRelease(&tag, lockmode, false);
664
}
665

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
/*
 *		LockSharedObjectForSession
 *
 * Obtain a session-level lock on a shared-across-databases object.
 * See LockRelationIdForSession for notes about session-level locks.
 */
void
LockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
						   LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   InvalidOid,
					   classid,
					   objid,
					   objsubid);

	(void) LockAcquire(&tag, lockmode, true, false);
}

/*
 *		UnlockSharedObjectForSession
 */
void
UnlockSharedObjectForSession(Oid classid, Oid objid, uint16 objsubid,
							 LOCKMODE lockmode)
{
	LOCKTAG		tag;

	SET_LOCKTAG_OBJECT(tag,
					   InvalidOid,
					   classid,
					   objid,
					   objsubid);

	LockRelease(&tag, lockmode, true);
}

705

706 707 708 709 710 711 712 713 714 715
/*
 * Append a description of a lockable object to buf.
 *
 * Ideally we would print names for the numeric values, but that requires
 * getting locks on system tables, which might cause problems since this is
 * typically used to report deadlock situations.
 */
void
DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
{
716
	switch ((LockTagType) tag->locktag_type)
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
	{
		case LOCKTAG_RELATION:
			appendStringInfo(buf,
							 _("relation %u of database %u"),
							 tag->locktag_field2,
							 tag->locktag_field1);
			break;
		case LOCKTAG_RELATION_EXTEND:
			appendStringInfo(buf,
							 _("extension of relation %u of database %u"),
							 tag->locktag_field2,
							 tag->locktag_field1);
			break;
		case LOCKTAG_PAGE:
			appendStringInfo(buf,
							 _("page %u of relation %u of database %u"),
							 tag->locktag_field3,
							 tag->locktag_field2,
							 tag->locktag_field1);
			break;
		case LOCKTAG_TUPLE:
			appendStringInfo(buf,
							 _("tuple (%u,%u) of relation %u of database %u"),
							 tag->locktag_field3,
							 tag->locktag_field4,
							 tag->locktag_field2,
							 tag->locktag_field1);
			break;
		case LOCKTAG_TRANSACTION:
			appendStringInfo(buf,
							 _("transaction %u"),
							 tag->locktag_field1);
			break;
750 751 752 753 754 755
		case LOCKTAG_VIRTUALTRANSACTION:
			appendStringInfo(buf,
							 _("virtual transaction %d/%u"),
							 tag->locktag_field1,
							 tag->locktag_field2);
			break;
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781
		case LOCKTAG_OBJECT:
			appendStringInfo(buf,
							 _("object %u of class %u of database %u"),
							 tag->locktag_field3,
							 tag->locktag_field2,
							 tag->locktag_field1);
			break;
		case LOCKTAG_USERLOCK:
			/* reserved for old contrib code, now on pgfoundry */
			appendStringInfo(buf,
							 _("user lock [%u,%u,%u]"),
							 tag->locktag_field1,
							 tag->locktag_field2,
							 tag->locktag_field3);
			break;
		case LOCKTAG_ADVISORY:
			appendStringInfo(buf,
							 _("advisory lock [%u,%u,%u,%u]"),
							 tag->locktag_field1,
							 tag->locktag_field2,
							 tag->locktag_field3,
							 tag->locktag_field4);
			break;
		default:
			appendStringInfo(buf,
							 _("unrecognized locktag type %d"),
782
							 (int) tag->locktag_type);
783 784 785
			break;
	}
}