PostgreSQL Source Code git master
Loading...
Searching...
No Matches
lockfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/predicate_internals.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for lockfuncs.c:

Go to the source code of this file.

Data Structures

struct  PG_Lock_Status
 

Macros

#define NUM_LOCK_STATUS_COLUMNS   16
 
#define SET_LOCKTAG_INT64(tag, key64)
 
#define SET_LOCKTAG_INT32(tag, key1, key2)    SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)
 

Functions

 StaticAssertDecl (lengthof(LockTagTypeNames)==(LOCKTAG_LAST_TYPE+1), "array length mismatch")
 
 StaticAssertDecl (lengthof(PredicateLockTagTypeNames)==(PREDLOCKTAG_TUPLE+1), "array length mismatch")
 
static Datum VXIDGetDatum (ProcNumber procNumber, LocalTransactionId lxid)
 
Datum pg_lock_status (PG_FUNCTION_ARGS)
 
Datum pg_blocking_pids (PG_FUNCTION_ARGS)
 
Datum pg_safe_snapshot_blocking_pids (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_all (PG_FUNCTION_ARGS)
 

Variables

const char *const LockTagTypeNames []
 
static const char *const PredicateLockTagTypeNames []
 

Macro Definition Documentation

◆ NUM_LOCK_STATUS_COLUMNS

#define NUM_LOCK_STATUS_COLUMNS   16

Definition at line 66 of file lockfuncs.c.

◆ SET_LOCKTAG_INT32

#define SET_LOCKTAG_INT32 (   tag,
  key1,
  key2 
)     SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)

Definition at line 619 of file lockfuncs.c.

626{
628 LOCKTAG tag;
629
630 SET_LOCKTAG_INT64(tag, key);
631
632 (void) LockAcquire(&tag, ExclusiveLock, true, false);
633
635}
636
637/*
638 * pg_advisory_xact_lock(int8) - acquire xact scoped
639 * exclusive lock on an int8 key
640 */
641Datum
643{
645 LOCKTAG tag;
646
647 SET_LOCKTAG_INT64(tag, key);
648
649 (void) LockAcquire(&tag, ExclusiveLock, false, false);
650
652}
653
654/*
655 * pg_advisory_lock_shared(int8) - acquire share lock on an int8 key
656 */
657Datum
659{
661 LOCKTAG tag;
662
663 SET_LOCKTAG_INT64(tag, key);
664
665 (void) LockAcquire(&tag, ShareLock, true, false);
666
668}
669
670/*
671 * pg_advisory_xact_lock_shared(int8) - acquire xact scoped
672 * share lock on an int8 key
673 */
674Datum
676{
678 LOCKTAG tag;
679
680 SET_LOCKTAG_INT64(tag, key);
681
682 (void) LockAcquire(&tag, ShareLock, false, false);
683
685}
686
687/*
688 * pg_try_advisory_lock(int8) - acquire exclusive lock on an int8 key, no wait
689 *
690 * Returns true if successful, false if lock not available
691 */
692Datum
694{
696 LOCKTAG tag;
698
699 SET_LOCKTAG_INT64(tag, key);
700
701 res = LockAcquire(&tag, ExclusiveLock, true, true);
702
704}
705
706/*
707 * pg_try_advisory_xact_lock(int8) - acquire xact scoped
708 * exclusive lock on an int8 key, no wait
709 *
710 * Returns true if successful, false if lock not available
711 */
712Datum
714{
716 LOCKTAG tag;
718
719 SET_LOCKTAG_INT64(tag, key);
720
721 res = LockAcquire(&tag, ExclusiveLock, false, true);
722
724}
725
726/*
727 * pg_try_advisory_lock_shared(int8) - acquire share lock on an int8 key, no wait
728 *
729 * Returns true if successful, false if lock not available
730 */
731Datum
733{
735 LOCKTAG tag;
737
738 SET_LOCKTAG_INT64(tag, key);
739
740 res = LockAcquire(&tag, ShareLock, true, true);
741
743}
744
745/*
746 * pg_try_advisory_xact_lock_shared(int8) - acquire xact scoped
747 * share lock on an int8 key, no wait
748 *
749 * Returns true if successful, false if lock not available
750 */
751Datum
753{
755 LOCKTAG tag;
757
758 SET_LOCKTAG_INT64(tag, key);
759
760 res = LockAcquire(&tag, ShareLock, false, true);
761
763}
764
765/*
766 * pg_advisory_unlock(int8) - release exclusive lock on an int8 key
767 *
768 * Returns true if successful, false if lock was not held
769*/
770Datum
772{
774 LOCKTAG tag;
775 bool res;
776
777 SET_LOCKTAG_INT64(tag, key);
778
779 res = LockRelease(&tag, ExclusiveLock, true);
780
781 PG_RETURN_BOOL(res);
782}
783
784/*
785 * pg_advisory_unlock_shared(int8) - release share lock on an int8 key
786 *
787 * Returns true if successful, false if lock was not held
788 */
789Datum
791{
793 LOCKTAG tag;
794 bool res;
795
796 SET_LOCKTAG_INT64(tag, key);
797
798 res = LockRelease(&tag, ShareLock, true);
799
800 PG_RETURN_BOOL(res);
801}
802
803/*
804 * pg_advisory_lock(int4, int4) - acquire exclusive lock on 2 int4 keys
805 */
806Datum
808{
811 LOCKTAG tag;
812
814
815 (void) LockAcquire(&tag, ExclusiveLock, true, false);
816
818}
819
820/*
821 * pg_advisory_xact_lock(int4, int4) - acquire xact scoped
822 * exclusive lock on 2 int4 keys
823 */
824Datum
826{
829 LOCKTAG tag;
830
832
833 (void) LockAcquire(&tag, ExclusiveLock, false, false);
834
836}
837
838/*
839 * pg_advisory_lock_shared(int4, int4) - acquire share lock on 2 int4 keys
840 */
841Datum
843{
846 LOCKTAG tag;
847
849
850 (void) LockAcquire(&tag, ShareLock, true, false);
851
853}
854
855/*
856 * pg_advisory_xact_lock_shared(int4, int4) - acquire xact scoped
857 * share lock on 2 int4 keys
858 */
859Datum
861{
864 LOCKTAG tag;
865
867
868 (void) LockAcquire(&tag, ShareLock, false, false);
869
871}
872
873/*
874 * pg_try_advisory_lock(int4, int4) - acquire exclusive lock on 2 int4 keys, no wait
875 *
876 * Returns true if successful, false if lock not available
877 */
878Datum
880{
883 LOCKTAG tag;
885
887
888 res = LockAcquire(&tag, ExclusiveLock, true, true);
889
891}
892
893/*
894 * pg_try_advisory_xact_lock(int4, int4) - acquire xact scoped
895 * exclusive lock on 2 int4 keys, no wait
896 *
897 * Returns true if successful, false if lock not available
898 */
899Datum
901{
904 LOCKTAG tag;
906
908
909 res = LockAcquire(&tag, ExclusiveLock, false, true);
910
912}
913
914/*
915 * pg_try_advisory_lock_shared(int4, int4) - acquire share lock on 2 int4 keys, no wait
916 *
917 * Returns true if successful, false if lock not available
918 */
919Datum
921{
924 LOCKTAG tag;
926
928
929 res = LockAcquire(&tag, ShareLock, true, true);
930
932}
933
934/*
935 * pg_try_advisory_xact_lock_shared(int4, int4) - acquire xact scoped
936 * share lock on 2 int4 keys, no wait
937 *
938 * Returns true if successful, false if lock not available
939 */
940Datum
942{
945 LOCKTAG tag;
947
949
950 res = LockAcquire(&tag, ShareLock, false, true);
951
953}
954
955/*
956 * pg_advisory_unlock(int4, int4) - release exclusive lock on 2 int4 keys
957 *
958 * Returns true if successful, false if lock was not held
959*/
960Datum
962{
965 LOCKTAG tag;
966 bool res;
967
969
970 res = LockRelease(&tag, ExclusiveLock, true);
971
972 PG_RETURN_BOOL(res);
973}
974
975/*
976 * pg_advisory_unlock_shared(int4, int4) - release share lock on 2 int4 keys
977 *
978 * Returns true if successful, false if lock was not held
979 */
980Datum
982{
985 LOCKTAG tag;
986 bool res;
987
989
990 res = LockRelease(&tag, ShareLock, true);
991
992 PG_RETURN_BOOL(res);
993}
994
995/*
996 * pg_advisory_unlock_all() - release all advisory locks
997 */
998Datum
1000{
1002
1004}
int64_t int64
Definition c.h:543
int32_t int32
Definition c.h:542
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition lock.c:809
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition lock.c:2102
void LockReleaseSession(LOCKMETHODID lockmethodid)
Definition lock.c:2581
#define USER_LOCKMETHOD
Definition lock.h:128
LockAcquireResult
Definition lock.h:502
@ LOCKACQUIRE_NOT_AVAIL
Definition lock.h:503
#define ExclusiveLock
Definition lockdefs.h:42
#define ShareLock
Definition lockdefs.h:40
Datum pg_advisory_lock_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:808
#define SET_LOCKTAG_INT64(tag, key64)
Definition lockfuncs.c:613
Datum pg_try_advisory_xact_lock_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:901
Datum pg_advisory_unlock_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:772
Datum pg_advisory_lock_shared_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:843
Datum pg_try_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:753
Datum pg_advisory_xact_lock_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:643
Datum pg_try_advisory_lock_shared_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:921
Datum pg_try_advisory_lock_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:880
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition lockfuncs.c:619
Datum pg_advisory_unlock_shared_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:982
Datum pg_advisory_unlock_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:962
Datum pg_try_advisory_lock_shared_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:733
Datum pg_advisory_xact_lock_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:826
Datum pg_try_advisory_xact_lock_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:714
Datum pg_advisory_lock_shared_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:659
Datum pg_try_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:942
Datum pg_advisory_xact_lock_shared_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:676
Datum pg_advisory_unlock_shared_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:791
Datum pg_try_advisory_lock_int8(PG_FUNCTION_ARGS)
Definition lockfuncs.c:694
Datum pg_advisory_unlock_all(PG_FUNCTION_ARGS)
Definition lockfuncs.c:1000
Datum pg_advisory_xact_lock_shared_int4(PG_FUNCTION_ARGS)
Definition lockfuncs.c:861
uint64_t Datum
Definition postgres.h:70
static int fb(int x)

◆ SET_LOCKTAG_INT64

#define SET_LOCKTAG_INT64 (   tag,
  key64 
)
Value:
(uint32) ((key64) >> 32), \
(uint32) (key64), \
1)
uint32_t uint32
Definition c.h:546
Oid MyDatabaseId
Definition globals.c:94
#define SET_LOCKTAG_ADVISORY(locktag, id1, id2, id3, id4)
Definition lock.h:272

Definition at line 613 of file lockfuncs.c.

Function Documentation

◆ pg_advisory_lock_int4()

Datum pg_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 808 of file lockfuncs.c.

809{
812 LOCKTAG tag;
813
815
816 (void) LockAcquire(&tag, ExclusiveLock, true, false);
817
819}

References ExclusiveLock, fb(), LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, and SET_LOCKTAG_INT32.

◆ pg_advisory_lock_int8()

Datum pg_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 626 of file lockfuncs.c.

627{
629 LOCKTAG tag;
630
631 SET_LOCKTAG_INT64(tag, key);
632
633 (void) LockAcquire(&tag, ExclusiveLock, true, false);
634
636}

References ExclusiveLock, fb(), LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, and SET_LOCKTAG_INT64.

Referenced by delay_execution_planner().

◆ pg_advisory_lock_shared_int4()

Datum pg_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 843 of file lockfuncs.c.

844{
847 LOCKTAG tag;
848
850
851 (void) LockAcquire(&tag, ShareLock, true, false);
852
854}

References fb(), LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_lock_shared_int8()

Datum pg_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 659 of file lockfuncs.c.

660{
662 LOCKTAG tag;
663
664 SET_LOCKTAG_INT64(tag, key);
665
666 (void) LockAcquire(&tag, ShareLock, true, false);
667
669}

References fb(), LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_advisory_unlock_all()

Datum pg_advisory_unlock_all ( PG_FUNCTION_ARGS  )

Definition at line 1000 of file lockfuncs.c.

1001{
1003
1005}

References LockReleaseSession(), PG_RETURN_VOID, and USER_LOCKMETHOD.

◆ pg_advisory_unlock_int4()

Datum pg_advisory_unlock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 962 of file lockfuncs.c.

963{
966 LOCKTAG tag;
967 bool res;
968
970
971 res = LockRelease(&tag, ExclusiveLock, true);
972
973 PG_RETURN_BOOL(res);
974}

References ExclusiveLock, fb(), LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, and SET_LOCKTAG_INT32.

◆ pg_advisory_unlock_int8()

Datum pg_advisory_unlock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 772 of file lockfuncs.c.

773{
775 LOCKTAG tag;
776 bool res;
777
778 SET_LOCKTAG_INT64(tag, key);
779
780 res = LockRelease(&tag, ExclusiveLock, true);
781
782 PG_RETURN_BOOL(res);
783}

References ExclusiveLock, LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, and SET_LOCKTAG_INT64.

Referenced by delay_execution_planner().

◆ pg_advisory_unlock_shared_int4()

Datum pg_advisory_unlock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 982 of file lockfuncs.c.

983{
986 LOCKTAG tag;
987 bool res;
988
990
991 res = LockRelease(&tag, ShareLock, true);
992
993 PG_RETURN_BOOL(res);
994}

References fb(), LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_unlock_shared_int8()

Datum pg_advisory_unlock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 791 of file lockfuncs.c.

792{
794 LOCKTAG tag;
795 bool res;
796
797 SET_LOCKTAG_INT64(tag, key);
798
799 res = LockRelease(&tag, ShareLock, true);
800
801 PG_RETURN_BOOL(res);
802}

References LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_advisory_xact_lock_int4()

Datum pg_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 826 of file lockfuncs.c.

827{
830 LOCKTAG tag;
831
833
834 (void) LockAcquire(&tag, ExclusiveLock, false, false);
835
837}

References ExclusiveLock, fb(), LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, and SET_LOCKTAG_INT32.

◆ pg_advisory_xact_lock_int8()

Datum pg_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 643 of file lockfuncs.c.

644{
646 LOCKTAG tag;
647
648 SET_LOCKTAG_INT64(tag, key);
649
650 (void) LockAcquire(&tag, ExclusiveLock, false, false);
651
653}

References ExclusiveLock, fb(), LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, and SET_LOCKTAG_INT64.

◆ pg_advisory_xact_lock_shared_int4()

Datum pg_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 861 of file lockfuncs.c.

862{
865 LOCKTAG tag;
866
868
869 (void) LockAcquire(&tag, ShareLock, false, false);
870
872}

References fb(), LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_advisory_xact_lock_shared_int8()

Datum pg_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 676 of file lockfuncs.c.

677{
679 LOCKTAG tag;
680
681 SET_LOCKTAG_INT64(tag, key);
682
683 (void) LockAcquire(&tag, ShareLock, false, false);
684
686}

References fb(), LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_blocking_pids()

Datum pg_blocking_pids ( PG_FUNCTION_ARGS  )

Definition at line 466 of file lockfuncs.c.

467{
470 int narrayelems;
471 BlockedProcsData *lockData; /* state data from lmgr */
472 int i,
473 j;
474
475 /* Collect a snapshot of lock manager state */
477
478 /* We can't need more output entries than there are reported PROCLOCKs */
479 arrayelems = (Datum *) palloc(lockData->nlocks * sizeof(Datum));
480 narrayelems = 0;
481
482 /* For each blocked proc in the lock group ... */
483 for (i = 0; i < lockData->nprocs; i++)
484 {
485 BlockedProcData *bproc = &lockData->procs[i];
486 LockInstanceData *instances = &lockData->locks[bproc->first_lock];
487 int *preceding_waiters = &lockData->waiter_pids[bproc->first_waiter];
490 int conflictMask;
491
492 /*
493 * Locate the blocked proc's own entry in the LockInstanceData array.
494 * There should be exactly one matching entry.
495 */
497 for (j = 0; j < bproc->num_locks; j++)
498 {
500
501 if (instance->pid == bproc->pid)
502 {
505 }
506 }
508
510 conflictMask = lockMethodTable->conflictTab[blocked_instance->waitLockMode];
511
512 /* Now scan the PROCLOCK data for conflicting procs */
513 for (j = 0; j < bproc->num_locks; j++)
514 {
516
517 /* A proc never blocks itself, so ignore that entry */
519 continue;
520 /* Members of same lock group never block each other, either */
521 if (instance->leaderPid == blocked_instance->leaderPid)
522 continue;
523
524 if (conflictMask & instance->holdMask)
525 {
526 /* hard block: blocked by lock already held by this entry */
527 }
528 else if (instance->waitLockMode != NoLock &&
529 (conflictMask & LOCKBIT_ON(instance->waitLockMode)))
530 {
531 /* conflict in lock requests; who's in front in wait queue? */
532 bool ahead = false;
533 int k;
534
535 for (k = 0; k < bproc->num_waiters; k++)
536 {
537 if (preceding_waiters[k] == instance->pid)
538 {
539 /* soft block: this entry is ahead of blocked proc */
540 ahead = true;
541 break;
542 }
543 }
544 if (!ahead)
545 continue; /* not blocked by this entry */
546 }
547 else
548 {
549 /* not blocked by this entry */
550 continue;
551 }
552
553 /* blocked by this entry, so emit a record */
555 }
556 }
557
558 /* Assert we didn't overrun arrayelems[] */
560
562}
#define PG_RETURN_ARRAYTYPE_P(x)
Definition array.h:265
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
#define Assert(condition)
Definition c.h:873
int j
Definition isn.c:78
int i
Definition isn.c:77
BlockedProcsData * GetBlockerStatusData(int blocked_pid)
Definition lock.c:3996
LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)
Definition lock.c:539
#define LOCKBIT_ON(lockmode)
Definition lock.h:86
#define NoLock
Definition lockdefs.h:34
void * palloc(Size size)
Definition mcxt.c:1387
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
LockInstanceData * locks
Definition lock.h:489
int * waiter_pids
Definition lock.h:490
BlockedProcData * procs
Definition lock.h:488

References Assert, construct_array_builtin(), fb(), GetBlockerStatusData(), GetLockTagsMethodTable(), i, Int32GetDatum(), j, LOCKBIT_ON, BlockedProcsData::locks, BlockedProcsData::nlocks, NoLock, BlockedProcsData::nprocs, palloc(), PG_GETARG_INT32, PG_RETURN_ARRAYTYPE_P, BlockedProcsData::procs, and BlockedProcsData::waiter_pids.

Referenced by pg_isolation_test_session_is_blocked().

◆ pg_lock_status()

Datum pg_lock_status ( PG_FUNCTION_ARGS  )

Definition at line 93 of file lockfuncs.c.

94{
97 LockData *lockData;
98 PredicateLockData *predLockData;
99
100 if (SRF_IS_FIRSTCALL())
101 {
102 TupleDesc tupdesc;
103 MemoryContext oldcontext;
104
105 /* create a function context for cross-call persistence */
107
108 /*
109 * switch to memory context appropriate for multiple function calls
110 */
111 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
112
113 /* build tupdesc for result tuples */
114 /* this had better match function's declaration in pg_proc.h */
116 TupleDescInitEntry(tupdesc, (AttrNumber) 1, "locktype",
117 TEXTOID, -1, 0);
118 TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database",
119 OIDOID, -1, 0);
120 TupleDescInitEntry(tupdesc, (AttrNumber) 3, "relation",
121 OIDOID, -1, 0);
122 TupleDescInitEntry(tupdesc, (AttrNumber) 4, "page",
123 INT4OID, -1, 0);
124 TupleDescInitEntry(tupdesc, (AttrNumber) 5, "tuple",
125 INT2OID, -1, 0);
126 TupleDescInitEntry(tupdesc, (AttrNumber) 6, "virtualxid",
127 TEXTOID, -1, 0);
128 TupleDescInitEntry(tupdesc, (AttrNumber) 7, "transactionid",
129 XIDOID, -1, 0);
130 TupleDescInitEntry(tupdesc, (AttrNumber) 8, "classid",
131 OIDOID, -1, 0);
132 TupleDescInitEntry(tupdesc, (AttrNumber) 9, "objid",
133 OIDOID, -1, 0);
134 TupleDescInitEntry(tupdesc, (AttrNumber) 10, "objsubid",
135 INT2OID, -1, 0);
136 TupleDescInitEntry(tupdesc, (AttrNumber) 11, "virtualtransaction",
137 TEXTOID, -1, 0);
138 TupleDescInitEntry(tupdesc, (AttrNumber) 12, "pid",
139 INT4OID, -1, 0);
140 TupleDescInitEntry(tupdesc, (AttrNumber) 13, "mode",
141 TEXTOID, -1, 0);
142 TupleDescInitEntry(tupdesc, (AttrNumber) 14, "granted",
143 BOOLOID, -1, 0);
144 TupleDescInitEntry(tupdesc, (AttrNumber) 15, "fastpath",
145 BOOLOID, -1, 0);
146 TupleDescInitEntry(tupdesc, (AttrNumber) 16, "waitstart",
147 TIMESTAMPTZOID, -1, 0);
148
149 funcctx->tuple_desc = BlessTupleDesc(tupdesc);
150
151 /*
152 * Collect all the locking information that we will format and send
153 * out as a result set.
154 */
156 funcctx->user_fctx = mystatus;
157
158 mystatus->lockData = GetLockStatusData();
159 mystatus->currIdx = 0;
160 mystatus->predLockData = GetPredicateLockStatusData();
161 mystatus->predLockIdx = 0;
162
163 MemoryContextSwitchTo(oldcontext);
164 }
165
167 mystatus = (PG_Lock_Status *) funcctx->user_fctx;
168 lockData = mystatus->lockData;
169
170 while (mystatus->currIdx < lockData->nelements)
171 {
172 bool granted;
173 LOCKMODE mode = 0;
174 const char *locktypename;
175 char tnbuf[32];
177 bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
178 HeapTuple tuple;
179 Datum result;
181
182 instance = &(lockData->locks[mystatus->currIdx]);
183
184 /*
185 * Look to see if there are any held lock modes in this PROCLOCK. If
186 * so, report, and destructively modify lockData so we don't report
187 * again.
188 */
189 granted = false;
190 if (instance->holdMask)
191 {
192 for (mode = 0; mode < MAX_LOCKMODES; mode++)
193 {
194 if (instance->holdMask & LOCKBIT_ON(mode))
195 {
196 granted = true;
198 break;
199 }
200 }
201 }
202
203 /*
204 * If no (more) held modes to report, see if PROC is waiting for a
205 * lock on this lock.
206 */
207 if (!granted)
208 {
209 if (instance->waitLockMode != NoLock)
210 {
211 /* Yes, so report it with proper mode */
212 mode = instance->waitLockMode;
213
214 /*
215 * We are now done with this PROCLOCK, so advance pointer to
216 * continue with next one on next call.
217 */
218 mystatus->currIdx++;
219 }
220 else
221 {
222 /*
223 * Okay, we've displayed all the locks associated with this
224 * PROCLOCK, proceed to the next one.
225 */
226 mystatus->currIdx++;
227 continue;
228 }
229 }
230
231 /*
232 * Form tuple with appropriate data.
233 */
234
235 if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
236 locktypename = LockTagTypeNames[instance->locktag.locktag_type];
237 else
238 {
239 snprintf(tnbuf, sizeof(tnbuf), "unknown %d",
240 (int) instance->locktag.locktag_type);
242 }
244
245 switch ((LockTagType) instance->locktag.locktag_type)
246 {
247 case LOCKTAG_RELATION:
249 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
250 values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
251 nulls[3] = true;
252 nulls[4] = true;
253 nulls[5] = true;
254 nulls[6] = true;
255 nulls[7] = true;
256 nulls[8] = true;
257 nulls[9] = true;
258 break;
260 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
261 nulls[2] = true;
262 nulls[3] = true;
263 nulls[4] = true;
264 nulls[5] = true;
265 nulls[6] = true;
266 nulls[7] = true;
267 nulls[8] = true;
268 nulls[9] = true;
269 break;
270 case LOCKTAG_PAGE:
271 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
272 values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
273 values[3] = UInt32GetDatum(instance->locktag.locktag_field3);
274 nulls[4] = true;
275 nulls[5] = true;
276 nulls[6] = true;
277 nulls[7] = true;
278 nulls[8] = true;
279 nulls[9] = true;
280 break;
281 case LOCKTAG_TUPLE:
282 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
283 values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
284 values[3] = UInt32GetDatum(instance->locktag.locktag_field3);
285 values[4] = UInt16GetDatum(instance->locktag.locktag_field4);
286 nulls[5] = true;
287 nulls[6] = true;
288 nulls[7] = true;
289 nulls[8] = true;
290 nulls[9] = true;
291 break;
293 values[6] =
294 TransactionIdGetDatum(instance->locktag.locktag_field1);
295 nulls[1] = true;
296 nulls[2] = true;
297 nulls[3] = true;
298 nulls[4] = true;
299 nulls[5] = true;
300 nulls[7] = true;
301 nulls[8] = true;
302 nulls[9] = true;
303 break;
305 values[5] = VXIDGetDatum(instance->locktag.locktag_field1,
306 instance->locktag.locktag_field2);
307 nulls[1] = true;
308 nulls[2] = true;
309 nulls[3] = true;
310 nulls[4] = true;
311 nulls[6] = true;
312 nulls[7] = true;
313 nulls[8] = true;
314 nulls[9] = true;
315 break;
317 values[6] =
318 TransactionIdGetDatum(instance->locktag.locktag_field1);
319 values[8] = ObjectIdGetDatum(instance->locktag.locktag_field2);
320 nulls[1] = true;
321 nulls[2] = true;
322 nulls[3] = true;
323 nulls[4] = true;
324 nulls[5] = true;
325 nulls[7] = true;
326 nulls[9] = true;
327 break;
329 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
330 values[8] = ObjectIdGetDatum(instance->locktag.locktag_field2);
331 values[6] = ObjectIdGetDatum(instance->locktag.locktag_field3);
332 values[9] = UInt16GetDatum(instance->locktag.locktag_field4);
333 nulls[2] = true;
334 nulls[3] = true;
335 nulls[4] = true;
336 nulls[5] = true;
337 nulls[7] = true;
338 break;
339 case LOCKTAG_OBJECT:
340 case LOCKTAG_USERLOCK:
341 case LOCKTAG_ADVISORY:
342 default: /* treat unknown locktags like OBJECT */
343 values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
344 values[7] = ObjectIdGetDatum(instance->locktag.locktag_field2);
345 values[8] = ObjectIdGetDatum(instance->locktag.locktag_field3);
346 values[9] = UInt16GetDatum(instance->locktag.locktag_field4);
347 nulls[2] = true;
348 nulls[3] = true;
349 nulls[4] = true;
350 nulls[5] = true;
351 nulls[6] = true;
352 break;
353 }
354
355 values[10] = VXIDGetDatum(instance->vxid.procNumber, instance->vxid.localTransactionId);
356 if (instance->pid != 0)
357 values[11] = Int32GetDatum(instance->pid);
358 else
359 nulls[11] = true;
360 values[12] = CStringGetTextDatum(GetLockmodeName(instance->locktag.locktag_lockmethodid, mode));
361 values[13] = BoolGetDatum(granted);
362 values[14] = BoolGetDatum(instance->fastpath);
363 if (!granted && instance->waitStart != 0)
364 values[15] = TimestampTzGetDatum(instance->waitStart);
365 else
366 nulls[15] = true;
367
368 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
369 result = HeapTupleGetDatum(tuple);
370 SRF_RETURN_NEXT(funcctx, result);
371 }
372
373 /*
374 * Have returned all regular locks. Now start on the SIREAD predicate
375 * locks.
376 */
377 predLockData = mystatus->predLockData;
378 if (mystatus->predLockIdx < predLockData->nelements)
379 {
381
382 PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
383 SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
385 bool nulls[NUM_LOCK_STATUS_COLUMNS] = {0};
386 HeapTuple tuple;
387 Datum result;
388
389 mystatus->predLockIdx++;
390
391 /*
392 * Form tuple with appropriate data.
393 */
394
395 /* lock type */
397
399
400 /* lock target */
405 else
406 nulls[4] = true;
407 if ((lockType == PREDLOCKTAG_TUPLE) ||
410 else
411 nulls[3] = true;
412
413 /* these fields are targets for other types of locks */
414 nulls[5] = true; /* virtualxid */
415 nulls[6] = true; /* transactionid */
416 nulls[7] = true; /* classid */
417 nulls[8] = true; /* objid */
418 nulls[9] = true; /* objsubid */
419
420 /* lock holder */
421 values[10] = VXIDGetDatum(xact->vxid.procNumber,
422 xact->vxid.localTransactionId);
423 if (xact->pid != 0)
424 values[11] = Int32GetDatum(xact->pid);
425 else
426 nulls[11] = true;
427
428 /*
429 * Lock mode. Currently all predicate locks are SIReadLocks, which are
430 * always held (never waiting) and have no fast path
431 */
432 values[12] = CStringGetTextDatum("SIReadLock");
433 values[13] = BoolGetDatum(true);
434 values[14] = BoolGetDatum(false);
435 nulls[15] = true;
436
437 tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
438 result = HeapTupleGetDatum(tuple);
439 SRF_RETURN_NEXT(funcctx, result);
440 }
441
443}
int16 AttrNumber
Definition attnum.h:21
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
#define palloc_object(type)
Definition fe_memutils.h:74
#define SRF_IS_FIRSTCALL()
Definition funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition funcapi.h:306
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
#define SRF_RETURN_DONE(_funcctx)
Definition funcapi.h:328
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition lock.c:4253
LockData * GetLockStatusData(void)
Definition lock.c:3793
LockTagType
Definition lock.h:138
@ LOCKTAG_OBJECT
Definition lock.h:147
@ LOCKTAG_RELATION_EXTEND
Definition lock.h:140
@ LOCKTAG_RELATION
Definition lock.h:139
@ LOCKTAG_TUPLE
Definition lock.h:143
@ LOCKTAG_SPECULATIVE_TOKEN
Definition lock.h:146
@ LOCKTAG_APPLY_TRANSACTION
Definition lock.h:150
@ LOCKTAG_USERLOCK
Definition lock.h:148
@ LOCKTAG_DATABASE_FROZEN_IDS
Definition lock.h:141
@ LOCKTAG_VIRTUALTRANSACTION
Definition lock.h:145
@ LOCKTAG_TRANSACTION
Definition lock.h:144
@ LOCKTAG_PAGE
Definition lock.h:142
@ LOCKTAG_ADVISORY
Definition lock.h:149
#define LOCKBIT_OFF(lockmode)
Definition lock.h:87
#define LOCKTAG_LAST_TYPE
Definition lock.h:154
#define MAX_LOCKMODES
Definition lock.h:84
int LOCKMODE
Definition lockdefs.h:26
static Datum VXIDGetDatum(ProcNumber procNumber, LocalTransactionId lxid)
Definition lockfuncs.c:74
#define NUM_LOCK_STATUS_COLUMNS
Definition lockfuncs.c:66
static const char *const PredicateLockTagTypeNames[]
Definition lockfuncs.c:47
const char *const LockTagTypeNames[]
Definition lockfuncs.c:28
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
static PgChecksumMode mode
#define snprintf
Definition port.h:260
static Datum TransactionIdGetDatum(TransactionId X)
Definition postgres.h:302
static Datum UInt16GetDatum(uint16 X)
Definition postgres.h:202
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Datum UInt32GetDatum(uint32 X)
Definition postgres.h:242
PredicateLockData * GetPredicateLockStatusData(void)
Definition predicate.c:1445
PredicateLockTargetType
@ PREDLOCKTAG_PAGE
@ PREDLOCKTAG_TUPLE
#define GET_PREDICATELOCKTARGETTAG_DB(locktag)
#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag)
#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag)
#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag)
#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag)
LockInstanceData * locks
Definition lock.h:470
int nelements
Definition lock.h:469
LOCKMASK holdMask
Definition lock.h:457
PREDICATELOCKTARGETTAG * locktags
SERIALIZABLEXACT * xacts
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:825
static Datum TimestampTzGetDatum(TimestampTz X)
Definition timestamp.h:52

References BlessTupleDesc(), BoolGetDatum(), CreateTemplateTupleDesc(), CStringGetTextDatum, fb(), GET_PREDICATELOCKTARGETTAG_DB, GET_PREDICATELOCKTARGETTAG_OFFSET, GET_PREDICATELOCKTARGETTAG_PAGE, GET_PREDICATELOCKTARGETTAG_RELATION, GET_PREDICATELOCKTARGETTAG_TYPE, GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), heap_form_tuple(), HeapTupleGetDatum(), LockInstanceData::holdMask, Int32GetDatum(), LOCKBIT_OFF, LOCKBIT_ON, LockData::locks, LOCKTAG_ADVISORY, LOCKTAG_APPLY_TRANSACTION, LOCKTAG_DATABASE_FROZEN_IDS, LOCKTAG_LAST_TYPE, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_SPECULATIVE_TOKEN, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG_USERLOCK, LOCKTAG_VIRTUALTRANSACTION, PredicateLockData::locktags, LockTagTypeNames, MAX_LOCKMODES, MemoryContextSwitchTo(), mode, LockData::nelements, PredicateLockData::nelements, NoLock, NUM_LOCK_STATUS_COLUMNS, ObjectIdGetDatum(), palloc_object, PredicateLockTagTypeNames, PREDLOCKTAG_PAGE, PREDLOCKTAG_TUPLE, snprintf, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TimestampTzGetDatum(), TransactionIdGetDatum(), TupleDescInitEntry(), UInt16GetDatum(), UInt32GetDatum(), values, VXIDGetDatum(), and PredicateLockData::xacts.

◆ pg_safe_snapshot_blocking_pids()

Datum pg_safe_snapshot_blocking_pids ( PG_FUNCTION_ARGS  )

Definition at line 573 of file lockfuncs.c.

574{
576 int *blockers;
577 int num_blockers;
579
580 /* A buffer big enough for any possible blocker list without truncation */
581 blockers = (int *) palloc(MaxBackends * sizeof(int));
582
583 /* Collect a snapshot of processes waited for by GetSafeSnapshot */
586
587 /* Convert int array to Datum array */
588 if (num_blockers > 0)
589 {
590 int i;
591
593 for (i = 0; i < num_blockers; ++i)
594 blocker_datums[i] = Int32GetDatum(blockers[i]);
595 }
596 else
598
600}
int MaxBackends
Definition globals.c:146
int GetSafeSnapshotBlockingPids(int blocked_pid, int *output, int output_size)
Definition predicate.c:1626

References construct_array_builtin(), fb(), GetSafeSnapshotBlockingPids(), i, Int32GetDatum(), MaxBackends, palloc(), PG_GETARG_INT32, and PG_RETURN_ARRAYTYPE_P.

◆ pg_try_advisory_lock_int4()

Datum pg_try_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 880 of file lockfuncs.c.

881{
884 LOCKTAG tag;
886
888
889 res = LockAcquire(&tag, ExclusiveLock, true, true);
890
892}

References ExclusiveLock, fb(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, and SET_LOCKTAG_INT32.

◆ pg_try_advisory_lock_int8()

Datum pg_try_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 694 of file lockfuncs.c.

695{
697 LOCKTAG tag;
699
700 SET_LOCKTAG_INT64(tag, key);
701
702 res = LockAcquire(&tag, ExclusiveLock, true, true);
703
705}

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, and SET_LOCKTAG_INT64.

◆ pg_try_advisory_lock_shared_int4()

Datum pg_try_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 921 of file lockfuncs.c.

922{
925 LOCKTAG tag;
927
929
930 res = LockAcquire(&tag, ShareLock, true, true);
931
933}

References fb(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_try_advisory_lock_shared_int8()

Datum pg_try_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 733 of file lockfuncs.c.

734{
736 LOCKTAG tag;
738
739 SET_LOCKTAG_INT64(tag, key);
740
741 res = LockAcquire(&tag, ShareLock, true, true);
742
744}

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, SET_LOCKTAG_INT64, and ShareLock.

◆ pg_try_advisory_xact_lock_int4()

Datum pg_try_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 901 of file lockfuncs.c.

902{
905 LOCKTAG tag;
907
909
910 res = LockAcquire(&tag, ExclusiveLock, false, true);
911
913}

References ExclusiveLock, fb(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, and SET_LOCKTAG_INT32.

◆ pg_try_advisory_xact_lock_int8()

Datum pg_try_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 714 of file lockfuncs.c.

715{
717 LOCKTAG tag;
719
720 SET_LOCKTAG_INT64(tag, key);
721
722 res = LockAcquire(&tag, ExclusiveLock, false, true);
723
725}

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, and SET_LOCKTAG_INT64.

◆ pg_try_advisory_xact_lock_shared_int4()

Datum pg_try_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 942 of file lockfuncs.c.

943{
946 LOCKTAG tag;
948
950
951 res = LockAcquire(&tag, ShareLock, false, true);
952
954}

References fb(), LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, SET_LOCKTAG_INT32, and ShareLock.

◆ pg_try_advisory_xact_lock_shared_int8()

Datum pg_try_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 753 of file lockfuncs.c.

754{
756 LOCKTAG tag;
758
759 SET_LOCKTAG_INT64(tag, key);
760
761 res = LockAcquire(&tag, ShareLock, false, true);
762
764}

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, SET_LOCKTAG_INT64, and ShareLock.

◆ StaticAssertDecl() [1/2]

StaticAssertDecl ( lengthof(LockTagTypeNames = =(LOCKTAG_LAST_TYPE+1),
"array length mismatch"   
)

◆ StaticAssertDecl() [2/2]

StaticAssertDecl ( lengthof(PredicateLockTagTypeNames = =(PREDLOCKTAG_TUPLE+1),
"array length mismatch"   
)

◆ VXIDGetDatum()

static Datum VXIDGetDatum ( ProcNumber  procNumber,
LocalTransactionId  lxid 
)
static

Definition at line 74 of file lockfuncs.c.

75{
76 /*
77 * The representation is "<procNumber>/<lxid>", decimal and unsigned
78 * decimal respectively. Note that elog.c also knows how to format a
79 * vxid.
80 */
81 char vxidstr[32];
82
83 snprintf(vxidstr, sizeof(vxidstr), "%d/%u", procNumber, lxid);
84
86}

References CStringGetTextDatum, fb(), and snprintf.

Referenced by pg_lock_status().

Variable Documentation

◆ LockTagTypeNames

const char* const LockTagTypeNames[]
Initial value:
= {
"relation",
"extend",
"frozenid",
"page",
"tuple",
"transactionid",
"virtualxid",
"spectoken",
"object",
"userlock",
"advisory",
"applytransaction"
}

Definition at line 28 of file lockfuncs.c.

28 {
29 "relation",
30 "extend",
31 "frozenid",
32 "page",
33 "tuple",
34 "transactionid",
35 "virtualxid",
36 "spectoken",
37 "object",
38 "userlock",
39 "advisory",
40 "applytransaction"
41};

Referenced by GetLockNameFromTagType(), and pg_lock_status().

◆ PredicateLockTagTypeNames

const char* const PredicateLockTagTypeNames[]
static
Initial value:
= {
"relation",
"page",
"tuple"
}

Definition at line 47 of file lockfuncs.c.

47 {
48 "relation",
49 "page",
50 "tuple"
51};

Referenced by pg_lock_status().