PostgreSQL Source Code git master
Loading...
Searching...
No Matches
proc.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * proc.c
4 * routines to manage per-process shared memory data structure
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/storage/lmgr/proc.c
12 *
13 *-------------------------------------------------------------------------
14 */
15/*
16 * Interface (a):
17 * JoinWaitQueue(), ProcSleep(), ProcWakeup()
18 *
19 * Waiting for a lock causes the backend to be put to sleep. Whoever releases
20 * the lock wakes the process up again (and gives it an error code so it knows
21 * whether it was awoken on an error condition).
22 *
23 * Interface (b):
24 *
25 * ProcReleaseLocks -- frees the locks associated with current transaction
26 *
27 * ProcKill -- destroys the shared memory state (and locks)
28 * associated with the process.
29 */
30#include "postgres.h"
31
32#include <signal.h>
33#include <unistd.h>
34#include <sys/time.h>
35
36#include "access/clog.h"
37#include "access/transam.h"
38#include "access/twophase.h"
39#include "access/xlogutils.h"
40#include "access/xlogwait.h"
41#include "miscadmin.h"
42#include "pgstat.h"
45#include "replication/syncrep.h"
47#include "storage/ipc.h"
48#include "storage/lmgr.h"
49#include "storage/pmsignal.h"
50#include "storage/proc.h"
51#include "storage/procarray.h"
52#include "storage/procsignal.h"
53#include "storage/spin.h"
54#include "storage/standby.h"
55#include "utils/timeout.h"
56#include "utils/timestamp.h"
57#include "utils/wait_event.h"
58
59/* GUC variables */
60int DeadlockTimeout = 1000;
66bool log_lock_waits = true;
67
68/* Pointer to this process's PGPROC struct, if any */
70
71/* Pointers to shared-memory structures */
75
76/* Is a deadlock check pending? */
78
79static void RemoveProcFromArray(int code, Datum arg);
80static void ProcKill(int code, Datum arg);
81static void AuxiliaryProcKill(int code, Datum arg);
82static DeadLockState CheckDeadLock(void);
83
84
85/*
86 * Report shared-memory space needed by PGPROC.
87 */
88static Size
90{
91 Size size = 0;
94
95 size = add_size(size, mul_size(TotalProcs, sizeof(PGPROC)));
96 size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->xids)));
97 size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->subxidStates)));
98 size = add_size(size, mul_size(TotalProcs, sizeof(*ProcGlobal->statusFlags)));
99
100 return size;
101}
102
103/*
104 * Report shared-memory space needed by Fast-Path locks.
105 */
106static Size
108{
109 Size size = 0;
114
115 /*
116 * Memory needed for PGPROC fast-path lock arrays. Make sure the sizes are
117 * nicely aligned in each backend.
118 */
121
123
124 return size;
125}
126
127/*
128 * Report shared-memory space needed by InitProcGlobal.
129 */
130Size
132{
133 Size size = 0;
134
135 /* ProcGlobal */
136 size = add_size(size, sizeof(PROC_HDR));
137 size = add_size(size, sizeof(slock_t));
138
140 size = add_size(size, PGProcShmemSize());
141 size = add_size(size, FastPathLockShmemSize());
142
143 return size;
144}
145
146/*
147 * Report number of semaphores needed by InitProcGlobal.
148 */
149int
151{
152 /*
153 * We need a sema per backend (including autovacuum), plus one for each
154 * auxiliary process.
155 */
157}
158
159/*
160 * InitProcGlobal -
161 * Initialize the global process table during postmaster or standalone
162 * backend startup.
163 *
164 * We also create all the per-process semaphores we will need to support
165 * the requested number of backends. We used to allocate semaphores
166 * only when backends were actually started up, but that is bad because
167 * it lets Postgres fail under load --- a lot of Unix systems are
168 * (mis)configured with small limits on the number of semaphores, and
169 * running out when trying to start another backend is a common failure.
170 * So, now we grab enough semaphores to support the desired max number
171 * of backends immediately at initialization --- if the sysadmin has set
172 * MaxConnections, max_worker_processes, max_wal_senders, or
173 * autovacuum_worker_slots higher than his kernel will support, he'll
174 * find out sooner rather than later.
175 *
176 * Another reason for creating semaphores here is that the semaphore
177 * implementation typically requires us to create semaphores in the
178 * postmaster, not in backends.
179 *
180 * Note: this is NOT called by individual backends under a postmaster,
181 * not even in the EXEC_BACKEND case. The ProcGlobal and AuxiliaryProcs
182 * pointers must be propagated specially for EXEC_BACKEND operation.
183 */
184void
186{
187 PGPROC *procs;
188 int i,
189 j;
190 bool found;
192
193 /* Used for setup of per-backend fast-path slots. */
194 char *fpPtr,
199 char *ptr;
200
201 /* Create the ProcGlobal shared structure */
202 ProcGlobal = (PROC_HDR *)
203 ShmemInitStruct("Proc Header", sizeof(PROC_HDR), &found);
204 Assert(!found);
205
206 /*
207 * Initialize the data structures.
208 */
220
221 /*
222 * Create and initialize all the PGPROC structures we'll need. There are
223 * six separate consumers: (1) normal backends, (2) autovacuum workers and
224 * special workers, (3) background workers, (4) walsenders, (5) auxiliary
225 * processes, and (6) prepared transactions. (For largely-historical
226 * reasons, we combine autovacuum and special workers into one category
227 * with a single freelist.) Each PGPROC structure is dedicated to exactly
228 * one of these purposes, and they do not move between groups.
229 */
231
232 ptr = ShmemInitStruct("PGPROC structures",
234 &found);
235
236 MemSet(ptr, 0, requestSize);
237
238 procs = (PGPROC *) ptr;
239 ptr = ptr + TotalProcs * sizeof(PGPROC);
240
241 ProcGlobal->allProcs = procs;
242 /* XXX allProcCount isn't really all of them; it excludes prepared xacts */
244
245 /*
246 * Allocate arrays mirroring PGPROC fields in a dense manner. See
247 * PROC_HDR.
248 *
249 * XXX: It might make sense to increase padding for these arrays, given
250 * how hotly they are accessed.
251 */
252 ProcGlobal->xids = (TransactionId *) ptr;
253 ptr = ptr + (TotalProcs * sizeof(*ProcGlobal->xids));
254
256 ptr = ptr + (TotalProcs * sizeof(*ProcGlobal->subxidStates));
257
258 ProcGlobal->statusFlags = (uint8 *) ptr;
259 ptr = ptr + (TotalProcs * sizeof(*ProcGlobal->statusFlags));
260
261 /* make sure wer didn't overflow */
262 Assert((ptr > (char *) procs) && (ptr <= (char *) procs + requestSize));
263
264 /*
265 * Allocate arrays for fast-path locks. Those are variable-length, so
266 * can't be included in PGPROC directly. We allocate a separate piece of
267 * shared memory and then divide that between backends.
268 */
271
273
274 fpPtr = ShmemInitStruct("Fast-Path Lock Array",
276 &found);
277
279
280 /* For asserts checking we did not overflow. */
282
283 /* Reserve space for semaphores. */
285
286 for (i = 0; i < TotalProcs; i++)
287 {
288 PGPROC *proc = &procs[i];
289
290 /* Common initialization for all PGPROCs, regardless of type. */
291
292 /*
293 * Set the fast-path lock arrays, and move the pointer. We interleave
294 * the two arrays, to (hopefully) get some locality for each backend.
295 */
296 proc->fpLockBits = (uint64 *) fpPtr;
298
299 proc->fpRelId = (Oid *) fpPtr;
301
303
304 /*
305 * Set up per-PGPROC semaphore, latch, and fpInfoLock. Prepared xact
306 * dummy PGPROCs don't need these though - they're never associated
307 * with a real process
308 */
310 {
311 proc->sem = PGSemaphoreCreate();
312 InitSharedLatch(&(proc->procLatch));
314 }
315
316 /*
317 * Newly created PGPROCs for normal backends, autovacuum workers,
318 * special workers, bgworkers, and walsenders must be queued up on the
319 * appropriate free list. Because there can only ever be a small,
320 * fixed number of auxiliary processes, no free list is used in that
321 * case; InitAuxiliaryProcess() instead uses a linear search. PGPROCs
322 * for prepared transactions are added to a free list by
323 * TwoPhaseShmemInit().
324 */
325 if (i < MaxConnections)
326 {
327 /* PGPROC for normal backend, add to freeProcs list */
330 }
332 {
333 /* PGPROC for AV or special worker, add to autovacFreeProcs list */
336 }
338 {
339 /* PGPROC for bgworker, add to bgworkerFreeProcs list */
342 }
343 else if (i < MaxBackends)
344 {
345 /* PGPROC for walsender, add to walsenderFreeProcs list */
348 }
349
350 /* Initialize myProcLocks[] shared memory queues. */
351 for (j = 0; j < NUM_LOCK_PARTITIONS; j++)
352 dlist_init(&(proc->myProcLocks[j]));
353
354 /* Initialize lockGroupMembers list. */
356
357 /*
358 * Initialize the atomic variables, otherwise, it won't be safe to
359 * access them for backends that aren't currently in use.
360 */
363 pg_atomic_init_u64(&(proc->waitStart), 0);
364 }
365
366 /* Should have consumed exactly the expected amount of fast-path memory. */
368
369 /*
370 * Save pointers to the blocks of PGPROC structures reserved for auxiliary
371 * processes and prepared transactions.
372 */
373 AuxiliaryProcs = &procs[MaxBackends];
375}
376
377/*
378 * InitProcess -- initialize a per-process PGPROC entry for this backend
379 */
380void
382{
383 dlist_head *procgloballist;
384
385 /*
386 * ProcGlobal should be set up already (if we are a backend, we inherit
387 * this by fork() or EXEC_BACKEND mechanism from the postmaster).
388 */
389 if (ProcGlobal == NULL)
390 elog(PANIC, "proc header uninitialized");
391
392 if (MyProc != NULL)
393 elog(ERROR, "you already exist");
394
395 /*
396 * Before we start accessing the shared memory in a serious way, mark
397 * ourselves as an active postmaster child; this is so that the postmaster
398 * can detect it if we exit without cleaning up.
399 */
402
403 /*
404 * Decide which list should supply our PGPROC. This logic must match the
405 * way the freelists were constructed in InitProcGlobal().
406 */
408 procgloballist = &ProcGlobal->autovacFreeProcs;
409 else if (AmBackgroundWorkerProcess())
410 procgloballist = &ProcGlobal->bgworkerFreeProcs;
411 else if (AmWalSenderProcess())
412 procgloballist = &ProcGlobal->walsenderFreeProcs;
413 else
414 procgloballist = &ProcGlobal->freeProcs;
415
416 /*
417 * Try to get a proc struct from the appropriate free list. If this
418 * fails, we must be out of PGPROC structures (not to mention semaphores).
419 *
420 * While we are holding the spinlock, also copy the current shared
421 * estimate of spins_per_delay to local storage.
422 */
424
426
427 if (!dlist_is_empty(procgloballist))
428 {
429 MyProc = dlist_container(PGPROC, freeProcsLink, dlist_pop_head_node(procgloballist));
431 }
432 else
433 {
434 /*
435 * If we reach here, all the PGPROCs are in use. This is one of the
436 * possible places to detect "too many backends", so give the standard
437 * error message. XXX do we need to give a different failure message
438 * in the autovacuum case?
439 */
441 if (AmWalSenderProcess())
444 errmsg("number of requested standby connections exceeds \"max_wal_senders\" (currently %d)",
448 errmsg("sorry, too many clients already")));
449 }
451
452 /*
453 * Cross-check that the PGPROC is of the type we expect; if this were not
454 * the case, it would get returned to the wrong list.
455 */
456 Assert(MyProc->procgloballist == procgloballist);
457
458 /*
459 * Initialize all fields of MyProc, except for those previously
460 * initialized by InitProcGlobal.
461 */
464 MyProc->fpVXIDLock = false;
471 /* databaseId and roleId will be filled in later */
477 MyProc->statusFlags = 0;
478 /* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
482 MyProc->lwWaitMode = 0;
487#ifdef USE_ASSERT_CHECKING
488 {
489 int i;
490
491 /* Last process should have released all locks. */
492 for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
494 }
495#endif
497
498 /* Initialize fields for sync rep */
502
503 /* Initialize fields for group XID clearing. */
507
508 /* Check that group locking fields are in a proper initial state. */
511
512 /* Initialize wait event information. */
514
515 /* Initialize fields for group transaction status update. */
516 MyProc->clogGroupMember = false;
522
523 /*
524 * Acquire ownership of the PGPROC's latch, so that we can use WaitLatch
525 * on it. That allows us to repoint the process latch, which so far
526 * points to process local one, to the shared one.
527 */
530
531 /* now that we have a proc, report wait events to shared memory */
533
534 /*
535 * We might be reusing a semaphore that belonged to a failed process. So
536 * be careful and reinitialize its value here. (This is not strictly
537 * necessary anymore, but seems like a good idea for cleanliness.)
538 */
540
541 /*
542 * Arrange to clean up at backend exit.
543 */
545
546 /*
547 * Now that we have a PGPROC, we could try to acquire locks, so initialize
548 * local state needed for LWLocks, and the deadlock checker.
549 */
552
553#ifdef EXEC_BACKEND
554
555 /*
556 * Initialize backend-local pointers to all the shared data structures.
557 * (We couldn't do this until now because it needs LWLocks.)
558 */
561#endif
562}
563
564/*
565 * InitProcessPhase2 -- make MyProc visible in the shared ProcArray.
566 *
567 * This is separate from InitProcess because we can't acquire LWLocks until
568 * we've created a PGPROC, but in the EXEC_BACKEND case ProcArrayAdd won't
569 * work until after we've done AttachSharedMemoryStructs.
570 */
571void
573{
574 Assert(MyProc != NULL);
575
576 /*
577 * Add our PGPROC to the PGPROC array in shared memory.
578 */
580
581 /*
582 * Arrange to clean that up at backend exit.
583 */
585}
586
587/*
588 * InitAuxiliaryProcess -- create a PGPROC entry for an auxiliary process
589 *
590 * This is called by bgwriter and similar processes so that they will have a
591 * MyProc value that's real enough to let them wait for LWLocks. The PGPROC
592 * and sema that are assigned are one of the extra ones created during
593 * InitProcGlobal.
594 *
595 * Auxiliary processes are presently not expected to wait for real (lockmgr)
596 * locks, so we need not set up the deadlock checker. They are never added
597 * to the ProcArray or the sinval messaging mechanism, either. They also
598 * don't get a VXID assigned, since this is only useful when we actually
599 * hold lockmgr locks.
600 *
601 * Startup process however uses locks but never waits for them in the
602 * normal backend sense. Startup process also takes part in sinval messaging
603 * as a sendOnly process, so never reads messages from sinval queue. So
604 * Startup process does have a VXID and does show up in pg_locks.
605 */
606void
608{
610 int proctype;
611
612 /*
613 * ProcGlobal should be set up already (if we are a backend, we inherit
614 * this by fork() or EXEC_BACKEND mechanism from the postmaster).
615 */
616 if (ProcGlobal == NULL || AuxiliaryProcs == NULL)
617 elog(PANIC, "proc header uninitialized");
618
619 if (MyProc != NULL)
620 elog(ERROR, "you already exist");
621
624
625 /*
626 * We use the freeProcsLock to protect assignment and releasing of
627 * AuxiliaryProcs entries.
628 *
629 * While we are holding the spinlock, also copy the current shared
630 * estimate of spins_per_delay to local storage.
631 */
633
635
636 /*
637 * Find a free auxproc ... *big* trouble if there isn't one ...
638 */
640 {
642 if (auxproc->pid == 0)
643 break;
644 }
646 {
648 elog(FATAL, "all AuxiliaryProcs are in use");
649 }
650
651 /* Mark auxiliary proc as in use by me */
652 /* use volatile pointer to prevent code rearrangement */
653 ((volatile PGPROC *) auxproc)->pid = MyProcPid;
654
656
657 MyProc = auxproc;
659
660 /*
661 * Initialize all fields of MyProc, except for those previously
662 * initialized by InitProcGlobal.
663 */
666 MyProc->fpVXIDLock = false;
677 MyProc->statusFlags = 0;
679 MyProc->lwWaitMode = 0;
684#ifdef USE_ASSERT_CHECKING
685 {
686 int i;
687
688 /* Last process should have released all locks. */
689 for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
691 }
692#endif
694
695 /*
696 * Acquire ownership of the PGPROC's latch, so that we can use WaitLatch
697 * on it. That allows us to repoint the process latch, which so far
698 * points to process local one, to the shared one.
699 */
702
703 /* now that we have a proc, report wait events to shared memory */
705
706 /* Check that group locking fields are in a proper initial state. */
709
710 /*
711 * We might be reusing a semaphore that belonged to a failed process. So
712 * be careful and reinitialize its value here. (This is not strictly
713 * necessary anymore, but seems like a good idea for cleanliness.)
714 */
716
717 /*
718 * Arrange to clean up at process exit.
719 */
721
722 /*
723 * Now that we have a PGPROC, we could try to acquire lightweight locks.
724 * Initialize local state needed for them. (Heavyweight locks cannot be
725 * acquired in aux processes.)
726 */
728
729#ifdef EXEC_BACKEND
730
731 /*
732 * Initialize backend-local pointers to all the shared data structures.
733 * (We couldn't do this until now because it needs LWLocks.)
734 */
737#endif
738}
739
740/*
741 * Used from bufmgr to share the value of the buffer that Startup waits on,
742 * or to reset the value to "not waiting" (-1). This allows processing
743 * of recovery conflicts for buffer pins. Set is made before backends look
744 * at this value, so locking not required, especially since the set is
745 * an atomic integer set operation.
746 */
747void
749{
750 /* use volatile pointer to prevent code rearrangement */
751 volatile PROC_HDR *procglobal = ProcGlobal;
752
754}
755
756/*
757 * Used by backends when they receive a request to check for buffer pin waits.
758 */
759int
761{
762 /* use volatile pointer to prevent code rearrangement */
763 volatile PROC_HDR *procglobal = ProcGlobal;
764
766}
767
768/*
769 * Check whether there are at least N free PGPROC objects. If false is
770 * returned, *nfree will be set to the number of free PGPROC objects.
771 * Otherwise, *nfree will be set to n.
772 *
773 * Note: this is designed on the assumption that N will generally be small.
774 */
775bool
776HaveNFreeProcs(int n, int *nfree)
777{
778 dlist_iter iter;
779
780 Assert(n > 0);
781 Assert(nfree);
782
784
785 *nfree = 0;
787 {
788 (*nfree)++;
789 if (*nfree == n)
790 break;
791 }
792
794
795 return (*nfree == n);
796}
797
798/*
799 * Cancel any pending wait for lock, when aborting a transaction, and revert
800 * any strong lock count acquisition for a lock being acquired.
801 *
802 * (Normally, this would only happen if we accept a cancel/die
803 * interrupt while waiting; but an ereport(ERROR) before or during the lock
804 * wait is within the realm of possibility, too.)
805 */
806void
808{
812
814
816
817 /* Nothing to do if we weren't waiting for a lock */
819 if (lockAwaited == NULL)
820 {
822 return;
823 }
824
825 /*
826 * Turn off the deadlock and lock timeout timers, if they are still
827 * running (see ProcSleep). Note we must preserve the LOCK_TIMEOUT
828 * indicator flag, since this function is executed before
829 * ProcessInterrupts when responding to SIGINT; else we'd lose the
830 * knowledge that the SIGINT came from a lock timeout and not an external
831 * source.
832 */
834 timeouts[0].keep_indicator = false;
835 timeouts[1].id = LOCK_TIMEOUT;
836 timeouts[1].keep_indicator = true;
838
839 /* Unlink myself from the wait queue, if on it (might not be anymore!) */
842
844 {
845 /* We could not have been granted the lock yet */
847 }
848 else
849 {
850 /*
851 * Somebody kicked us off the lock queue already. Perhaps they
852 * granted us the lock, or perhaps they detected a deadlock. If they
853 * did grant us the lock, we'd better remember it in our local lock
854 * table.
855 */
858 }
859
861
863
865}
866
867
868/*
869 * ProcReleaseLocks() -- release locks associated with current transaction
870 * at main transaction commit or abort
871 *
872 * At main transaction commit, we release standard locks except session locks.
873 * At main transaction abort, we release all locks including session locks.
874 *
875 * Advisory locks are released only if they are transaction-level;
876 * session-level holds remain, whether this is a commit or not.
877 *
878 * At subtransaction commit, we don't release any locks (so this func is not
879 * needed at all); we will defer the releasing to the parent transaction.
880 * At subtransaction abort, we release all locks held by the subtransaction;
881 * this is implemented by retail releasing of the locks under control of
882 * the ResourceOwner mechanism.
883 */
884void
886{
887 if (!MyProc)
888 return;
889 /* If waiting, get off wait queue (should only be needed after error) */
891 /* Release standard locks, including session-level if aborting */
893 /* Release transaction-level advisory locks */
895}
896
897
898/*
899 * RemoveProcFromArray() -- Remove this process from the shared ProcArray.
900 */
901static void
907
908/*
909 * ProcKill() -- Destroy the per-proc data structure for
910 * this process. Release any of its held LW locks.
911 */
912static void
914{
915 PGPROC *proc;
916 dlist_head *procgloballist;
917
918 Assert(MyProc != NULL);
919
920 /* not safe if forked by system(), etc. */
921 if (MyProc->pid != (int) getpid())
922 elog(PANIC, "ProcKill() called in child process");
923
924 /* Make sure we're out of the sync rep lists */
926
927#ifdef USE_ASSERT_CHECKING
928 {
929 int i;
930
931 /* Last process should have released all locks. */
932 for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
934 }
935#endif
936
937 /*
938 * Release any LW locks I am holding. There really shouldn't be any, but
939 * it's cheap to check again before we cut the knees off the LWLock
940 * facility by releasing our PGPROC ...
941 */
943
944 /*
945 * Cleanup waiting for LSN if any.
946 */
948
949 /* Cancel any pending condition variable sleep, too */
951
952 /*
953 * Detach from any lock group of which we are a member. If the leader
954 * exits before all other group members, its PGPROC will remain allocated
955 * until the last group process exits; that process must return the
956 * leader's PGPROC to the appropriate list.
957 */
959 {
960 PGPROC *leader = MyProc->lockGroupLeader;
962
966 if (dlist_is_empty(&leader->lockGroupMembers))
967 {
968 leader->lockGroupLeader = NULL;
969 if (leader != MyProc)
970 {
971 procgloballist = leader->procgloballist;
972
973 /* Leader exited first; return its PGPROC. */
975 dlist_push_head(procgloballist, &leader->freeProcsLink);
977 }
978 }
979 else if (leader != MyProc)
982 }
983
984 /*
985 * Reset MyLatch to the process local one. This is so that signal
986 * handlers et al can continue using the latch after the shared latch
987 * isn't ours anymore.
988 *
989 * Similarly, stop reporting wait events to MyProc->wait_event_info.
990 *
991 * After that clear MyProc and disown the shared latch.
992 */
995
996 proc = MyProc;
997 MyProc = NULL;
999 DisownLatch(&proc->procLatch);
1000
1001 /* Mark the proc no longer in use */
1002 proc->pid = 0;
1005
1006 procgloballist = proc->procgloballist;
1008
1009 /*
1010 * If we're still a member of a locking group, that means we're a leader
1011 * which has somehow exited before its children. The last remaining child
1012 * will release our PGPROC. Otherwise, release it now.
1013 */
1014 if (proc->lockGroupLeader == NULL)
1015 {
1016 /* Since lockGroupLeader is NULL, lockGroupMembers should be empty. */
1018
1019 /* Return PGPROC structure (and semaphore) to appropriate freelist */
1020 dlist_push_tail(procgloballist, &proc->freeProcsLink);
1021 }
1022
1023 /* Update shared estimate of spins_per_delay */
1025
1027}
1028
1029/*
1030 * AuxiliaryProcKill() -- Cut-down version of ProcKill for auxiliary
1031 * processes (bgwriter, etc). The PGPROC and sema are not released, only
1032 * marked as not-in-use.
1033 */
1034static void
1036{
1037 int proctype = DatumGetInt32(arg);
1039 PGPROC *proc;
1040
1042
1043 /* not safe if forked by system(), etc. */
1044 if (MyProc->pid != (int) getpid())
1045 elog(PANIC, "AuxiliaryProcKill() called in child process");
1046
1048
1049 Assert(MyProc == auxproc);
1050
1051 /* Release any LW locks I am holding (see notes above) */
1053
1054 /* Cancel any pending condition variable sleep, too */
1056
1057 /* look at the equivalent ProcKill() code for comments */
1060
1061 proc = MyProc;
1062 MyProc = NULL;
1064 DisownLatch(&proc->procLatch);
1065
1067
1068 /* Mark auxiliary proc no longer in use */
1069 proc->pid = 0;
1072
1073 /* Update shared estimate of spins_per_delay */
1075
1077}
1078
1079/*
1080 * AuxiliaryPidGetProc -- get PGPROC for an auxiliary process
1081 * given its PID
1082 *
1083 * Returns NULL if not found.
1084 */
1085PGPROC *
1087{
1088 PGPROC *result = NULL;
1089 int index;
1090
1091 if (pid == 0) /* never match dummy PGPROCs */
1092 return NULL;
1093
1094 for (index = 0; index < NUM_AUXILIARY_PROCS; index++)
1095 {
1096 PGPROC *proc = &AuxiliaryProcs[index];
1097
1098 if (proc->pid == pid)
1099 {
1100 result = proc;
1101 break;
1102 }
1103 }
1104 return result;
1105}
1106
1107
1108/*
1109 * JoinWaitQueue -- join the wait queue on the specified lock
1110 *
1111 * It's not actually guaranteed that we need to wait when this function is
1112 * called, because it could be that when we try to find a position at which
1113 * to insert ourself into the wait queue, we discover that we must be inserted
1114 * ahead of everyone who wants a lock that conflict with ours. In that case,
1115 * we get the lock immediately. Because of this, it's sensible for this function
1116 * to have a dontWait argument, despite the name.
1117 *
1118 * On entry, the caller has already set up LOCK and PROCLOCK entries to
1119 * reflect that we have "requested" the lock. The caller is responsible for
1120 * cleaning that up, if we end up not joining the queue after all.
1121 *
1122 * The lock table's partition lock must be held at entry, and is still held
1123 * at exit. The caller must release it before calling ProcSleep().
1124 *
1125 * Result is one of the following:
1126 *
1127 * PROC_WAIT_STATUS_OK - lock was immediately granted
1128 * PROC_WAIT_STATUS_WAITING - joined the wait queue; call ProcSleep()
1129 * PROC_WAIT_STATUS_ERROR - immediate deadlock was detected, or would
1130 * need to wait and dontWait == true
1131 *
1132 * NOTES: The process queue is now a priority queue for locking.
1133 */
1136{
1137 LOCKMODE lockmode = locallock->tag.mode;
1138 LOCK *lock = locallock->lock;
1139 PROCLOCK *proclock = locallock->proclock;
1140 uint32 hashcode = locallock->hashcode;
1146 bool early_deadlock = false;
1147 PGPROC *leader = MyProc->lockGroupLeader;
1148
1150
1151 /*
1152 * Set bitmask of locks this process already holds on this object.
1153 */
1154 myHeldLocks = MyProc->heldLocks = proclock->holdMask;
1155
1156 /*
1157 * Determine which locks we're already holding.
1158 *
1159 * If group locking is in use, locks held by members of my locking group
1160 * need to be included in myHeldLocks. This is not required for relation
1161 * extension lock which conflict among group members. However, including
1162 * them in myHeldLocks will give group members the priority to get those
1163 * locks as compared to other backends which are also trying to acquire
1164 * those locks. OTOH, we can avoid giving priority to group members for
1165 * that kind of locks, but there doesn't appear to be a clear advantage of
1166 * the same.
1167 */
1168 myProcHeldLocks = proclock->holdMask;
1170 if (leader != NULL)
1171 {
1172 dlist_iter iter;
1173
1174 dlist_foreach(iter, &lock->procLocks)
1175 {
1177
1178 otherproclock = dlist_container(PROCLOCK, lockLink, iter.cur);
1179
1180 if (otherproclock->groupLeader == leader)
1181 myHeldLocks |= otherproclock->holdMask;
1182 }
1183 }
1184
1185 /*
1186 * Determine where to add myself in the wait queue.
1187 *
1188 * Normally I should go at the end of the queue. However, if I already
1189 * hold locks that conflict with the request of any previous waiter, put
1190 * myself in the queue just in front of the first such waiter. This is not
1191 * a necessary step, since deadlock detection would move me to before that
1192 * waiter anyway; but it's relatively cheap to detect such a conflict
1193 * immediately, and avoid delaying till deadlock timeout.
1194 *
1195 * Special case: if I find I should go in front of some waiter, check to
1196 * see if I conflict with already-held locks or the requests before that
1197 * waiter. If not, then just grant myself the requested lock immediately.
1198 * This is the same as the test for immediate grant in LockAcquire, except
1199 * we are only considering the part of the wait queue before my insertion
1200 * point.
1201 */
1203 {
1205 dlist_iter iter;
1206
1208 {
1209 PGPROC *proc = dlist_container(PGPROC, waitLink, iter.cur);
1210
1211 /*
1212 * If we're part of the same locking group as this waiter, its
1213 * locks neither conflict with ours nor contribute to
1214 * aheadRequests.
1215 */
1216 if (leader != NULL && leader == proc->lockGroupLeader)
1217 continue;
1218
1219 /* Must he wait for me? */
1220 if (lockMethodTable->conflictTab[proc->waitLockMode] & myHeldLocks)
1221 {
1222 /* Must I wait for him ? */
1223 if (lockMethodTable->conflictTab[lockmode] & proc->heldLocks)
1224 {
1225 /*
1226 * Yes, so we have a deadlock. Easiest way to clean up
1227 * correctly is to call RemoveFromWaitQueue(), but we
1228 * can't do that until we are *on* the wait queue. So, set
1229 * a flag to check below, and break out of loop. Also,
1230 * record deadlock info for later message.
1231 */
1232 RememberSimpleDeadLock(MyProc, lockmode, lock, proc);
1233 early_deadlock = true;
1234 break;
1235 }
1236 /* I must go before this waiter. Check special case. */
1237 if ((lockMethodTable->conflictTab[lockmode] & aheadRequests) == 0 &&
1238 !LockCheckConflicts(lockMethodTable, lockmode, lock,
1239 proclock))
1240 {
1241 /* Skip the wait and just grant myself the lock. */
1242 GrantLock(lock, proclock, lockmode);
1243 return PROC_WAIT_STATUS_OK;
1244 }
1245
1246 /* Put myself into wait queue before conflicting process */
1247 insert_before = proc;
1248 break;
1249 }
1250 /* Nope, so advance to next waiter */
1252 }
1253 }
1254
1255 /*
1256 * If we detected deadlock, give up without waiting. This must agree with
1257 * CheckDeadLock's recovery code.
1258 */
1259 if (early_deadlock)
1261
1262 /*
1263 * At this point we know that we'd really need to sleep. If we've been
1264 * commanded not to do that, bail out.
1265 */
1266 if (dontWait)
1268
1269 /*
1270 * Insert self into queue, at the position determined above.
1271 */
1272 if (insert_before)
1274 else
1276
1277 lock->waitMask |= LOCKBIT_ON(lockmode);
1278
1279 /* Set up wait information in PGPROC object, too */
1281 MyProc->waitLock = lock;
1282 MyProc->waitProcLock = proclock;
1283 MyProc->waitLockMode = lockmode;
1284
1286
1288}
1289
1290/*
1291 * ProcSleep -- put process to sleep waiting on lock
1292 *
1293 * This must be called when JoinWaitQueue() returns PROC_WAIT_STATUS_WAITING.
1294 * Returns after the lock has been granted, or if a deadlock is detected. Can
1295 * also bail out with ereport(ERROR), if some other error condition, or a
1296 * timeout or cancellation is triggered.
1297 *
1298 * Result is one of the following:
1299 *
1300 * PROC_WAIT_STATUS_OK - lock was granted
1301 * PROC_WAIT_STATUS_ERROR - a deadlock was detected
1302 */
1305{
1306 LOCKMODE lockmode = locallock->tag.mode;
1307 LOCK *lock = locallock->lock;
1308 uint32 hashcode = locallock->hashcode;
1311 bool allow_autovacuum_cancel = true;
1312 bool logged_recovery_conflict = false;
1313 bool logged_lock_wait = false;
1316
1317 /* The caller must've armed the on-error cleanup mechanism */
1320
1321 /*
1322 * Now that we will successfully clean up after an ereport, it's safe to
1323 * check to see if there's a buffer pin deadlock against the Startup
1324 * process. Of course, that's only necessary if we're doing Hot Standby
1325 * and are not the Startup process ourselves.
1326 */
1329
1330 /* Reset deadlock_state before enabling the timeout handler */
1332 got_deadlock_timeout = false;
1333
1334 /*
1335 * Set timer so we can wake up after awhile and check for a deadlock. If a
1336 * deadlock is detected, the handler sets MyProc->waitStatus =
1337 * PROC_WAIT_STATUS_ERROR, allowing us to know that we must report failure
1338 * rather than success.
1339 *
1340 * By delaying the check until we've waited for a bit, we can avoid
1341 * running the rather expensive deadlock-check code in most cases.
1342 *
1343 * If LockTimeout is set, also enable the timeout for that. We can save a
1344 * few cycles by enabling both timeout sources in one call.
1345 *
1346 * If InHotStandby we set lock waits slightly later for clarity with other
1347 * code.
1348 */
1349 if (!InHotStandby)
1350 {
1351 if (LockTimeout > 0)
1352 {
1354
1356 timeouts[0].type = TMPARAM_AFTER;
1357 timeouts[0].delay_ms = DeadlockTimeout;
1358 timeouts[1].id = LOCK_TIMEOUT;
1359 timeouts[1].type = TMPARAM_AFTER;
1360 timeouts[1].delay_ms = LockTimeout;
1362 }
1363 else
1365
1366 /*
1367 * Use the current time obtained for the deadlock timeout timer as
1368 * waitStart (i.e., the time when this process started waiting for the
1369 * lock). Since getting the current time newly can cause overhead, we
1370 * reuse the already-obtained time to avoid that overhead.
1371 *
1372 * Note that waitStart is updated without holding the lock table's
1373 * partition lock, to avoid the overhead by additional lock
1374 * acquisition. This can cause "waitstart" in pg_locks to become NULL
1375 * for a very short period of time after the wait started even though
1376 * "granted" is false. This is OK in practice because we can assume
1377 * that users are likely to look at "waitstart" when waiting for the
1378 * lock for a long time.
1379 */
1382 }
1384 {
1385 /*
1386 * Set the wait start timestamp if logging is enabled and in hot
1387 * standby.
1388 */
1390 }
1391
1392 /*
1393 * If somebody wakes us between LWLockRelease and WaitLatch, the latch
1394 * will not wait. But a set latch does not necessarily mean that the lock
1395 * is free now, as there are many other sources for latch sets than
1396 * somebody releasing the lock.
1397 *
1398 * We process interrupts whenever the latch has been set, so cancel/die
1399 * interrupts are processed quickly. This means we must not mind losing
1400 * control to a cancel/die interrupt here. We don't, because we have no
1401 * shared-state-change work to do after being granted the lock (the
1402 * grantor did it all). We do have to worry about canceling the deadlock
1403 * timeout and updating the locallock table, but if we lose control to an
1404 * error, LockErrorCleanup will fix that up.
1405 */
1406 do
1407 {
1408 if (InHotStandby)
1409 {
1410 bool maybe_log_conflict =
1412
1413 /* Set a timer and wait for that or for the lock to be granted */
1416
1417 /*
1418 * Emit the log message if the startup process is waiting longer
1419 * than deadlock_timeout for recovery conflict on lock.
1420 */
1422 {
1424
1427 {
1429 int cnt;
1430
1431 vxids = GetLockConflicts(&locallock->tag.lock,
1432 AccessExclusiveLock, &cnt);
1433
1434 /*
1435 * Log the recovery conflict and the list of PIDs of
1436 * backends holding the conflicting lock. Note that we do
1437 * logging even if there are no such backends right now
1438 * because the startup process here has already waited
1439 * longer than deadlock_timeout.
1440 */
1443 cnt > 0 ? vxids : NULL, true);
1445 }
1446 }
1447 }
1448 else
1449 {
1451 PG_WAIT_LOCK | locallock->tag.lock.locktag_type);
1453 /* check for deadlocks first, as that's probably log-worthy */
1455 {
1457 got_deadlock_timeout = false;
1458 }
1460 }
1461
1462 /*
1463 * waitStatus could change from PROC_WAIT_STATUS_WAITING to something
1464 * else asynchronously. Read it just once per loop to prevent
1465 * surprising behavior (such as missing log messages).
1466 */
1467 myWaitStatus = *((volatile ProcWaitStatus *) &MyProc->waitStatus);
1468
1469 /*
1470 * If we are not deadlocked, but are waiting on an autovacuum-induced
1471 * task, send a signal to interrupt it.
1472 */
1474 {
1476 uint8 statusFlags;
1479
1480 /*
1481 * Grab info we need, then release lock immediately. Note this
1482 * coding means that there is a tiny chance that the process
1483 * terminates its current transaction and starts a different one
1484 * before we have a change to send the signal; the worst possible
1485 * consequence is that a for-wraparound vacuum is canceled. But
1486 * that could happen in any case unless we were to do kill() with
1487 * the lock held, which is much more undesirable.
1488 */
1490 statusFlags = ProcGlobal->statusFlags[autovac->pgxactoff];
1492 locktag_copy = lock->tag;
1494
1495 /*
1496 * Only do it if the worker is not working to protect against Xid
1497 * wraparound.
1498 */
1499 if ((statusFlags & PROC_IS_AUTOVACUUM) &&
1500 !(statusFlags & PROC_VACUUM_FOR_WRAPAROUND))
1501 {
1502 int pid = autovac->pid;
1503
1504 /* report the case, if configured to do so */
1506 {
1508 StringInfoData logbuf; /* errdetail for server log */
1509
1514 "Process %d waits for %s on %s.",
1515 MyProcPid,
1517 locktagbuf.data);
1518
1520 (errmsg_internal("sending cancel to blocking autovacuum PID %d",
1521 pid),
1522 errdetail_log("%s", logbuf.data)));
1523
1524 pfree(locktagbuf.data);
1525 pfree(logbuf.data);
1526 }
1527
1528 /* send the autovacuum worker Back to Old Kent Road */
1529 if (kill(pid, SIGINT) < 0)
1530 {
1531 /*
1532 * There's a race condition here: once we release the
1533 * ProcArrayLock, it's possible for the autovac worker to
1534 * close up shop and exit before we can do the kill().
1535 * Therefore, we do not whinge about no-such-process.
1536 * Other errors such as EPERM could conceivably happen if
1537 * the kernel recycles the PID fast enough, but such cases
1538 * seem improbable enough that it's probably best to issue
1539 * a warning if we see some other errno.
1540 */
1541 if (errno != ESRCH)
1543 (errmsg("could not send signal to process %d: %m",
1544 pid)));
1545 }
1546 }
1547
1548 /* prevent signal from being sent again more than once */
1550 }
1551
1552 /*
1553 * If awoken after the deadlock check interrupt has run, increment the
1554 * lock statistics counters and if log_lock_waits is on, then report
1555 * about the wait.
1556 */
1558 {
1559 long secs;
1560 int usecs;
1561 long msecs;
1562
1565 &secs, &usecs);
1566 msecs = secs * 1000 + usecs / 1000;
1567 usecs = usecs % 1000;
1568
1569 /* Increment the lock statistics counters if done waiting. */
1571 pgstat_count_lock_waits(locallock->tag.lock.locktag_type, msecs);
1572
1573 if (log_lock_waits)
1574 {
1578 const char *modename;
1579 int lockHoldersNum = 0;
1580
1584
1585 DescribeLockTag(&buf, &locallock->tag.lock);
1586 modename = GetLockmodeName(locallock->tag.lock.locktag_lockmethodid,
1587 lockmode);
1588
1589 /* Gather a list of all lock holders and waiters */
1594
1596 ereport(LOG,
1597 (errmsg("process %d avoided deadlock for %s on %s by rearranging queue order after %ld.%03d ms",
1598 MyProcPid, modename, buf.data, msecs, usecs),
1599 (errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
1600 "Processes holding the lock: %s. Wait queue: %s.",
1602 else if (deadlock_state == DS_HARD_DEADLOCK)
1603 {
1604 /*
1605 * This message is a bit redundant with the error that
1606 * will be reported subsequently, but in some cases the
1607 * error report might not make it to the log (eg, if it's
1608 * caught by an exception handler), and we want to ensure
1609 * all long-wait events get logged.
1610 */
1611 ereport(LOG,
1612 (errmsg("process %d detected deadlock while waiting for %s on %s after %ld.%03d ms",
1613 MyProcPid, modename, buf.data, msecs, usecs),
1614 (errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
1615 "Processes holding the lock: %s. Wait queue: %s.",
1617 }
1618
1620 {
1621 /*
1622 * Guard the "still waiting on lock" log message so it is
1623 * reported at most once while waiting for the lock.
1624 *
1625 * Without this guard, the message can be emitted whenever
1626 * the lock-wait sleep is interrupted (for example by
1627 * SIGHUP for config reload or by
1628 * client_connection_check_interval). For example, if
1629 * client_connection_check_interval is set very low (e.g.,
1630 * 100 ms), the message could be logged repeatedly,
1631 * flooding the log and making it difficult to use.
1632 */
1633 if (!logged_lock_wait)
1634 {
1635 ereport(LOG,
1636 (errmsg("process %d still waiting for %s on %s after %ld.%03d ms",
1637 MyProcPid, modename, buf.data, msecs, usecs),
1638 (errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
1639 "Processes holding the lock: %s. Wait queue: %s.",
1641 logged_lock_wait = true;
1642 }
1643 }
1645 ereport(LOG,
1646 (errmsg("process %d acquired %s on %s after %ld.%03d ms",
1647 MyProcPid, modename, buf.data, msecs, usecs)));
1648 else
1649 {
1651
1652 /*
1653 * Currently, the deadlock checker always kicks its own
1654 * process, which means that we'll only see
1655 * PROC_WAIT_STATUS_ERROR when deadlock_state ==
1656 * DS_HARD_DEADLOCK, and there's no need to print
1657 * redundant messages. But for completeness and
1658 * future-proofing, print a message if it looks like
1659 * someone else kicked us off the lock.
1660 */
1662 ereport(LOG,
1663 (errmsg("process %d failed to acquire %s on %s after %ld.%03d ms",
1664 MyProcPid, modename, buf.data, msecs, usecs),
1665 (errdetail_log_plural("Process holding the lock: %s. Wait queue: %s.",
1666 "Processes holding the lock: %s. Wait queue: %s.",
1668 }
1669 pfree(buf.data);
1672 }
1673
1674 /*
1675 * At this point we might still need to wait for the lock. Reset
1676 * state so we don't print the above messages again if
1677 * log_lock_waits is on.
1678 */
1680 }
1682
1683 /*
1684 * Disable the timers, if they are still running. As in LockErrorCleanup,
1685 * we must preserve the LOCK_TIMEOUT indicator flag: if a lock timeout has
1686 * already caused QueryCancelPending to become set, we want the cancel to
1687 * be reported as a lock timeout, not a user cancel.
1688 */
1689 if (!InHotStandby)
1690 {
1691 if (LockTimeout > 0)
1692 {
1694
1696 timeouts[0].keep_indicator = false;
1697 timeouts[1].id = LOCK_TIMEOUT;
1698 timeouts[1].keep_indicator = true;
1700 }
1701 else
1703 }
1704
1705 /*
1706 * Emit the log message if recovery conflict on lock was resolved but the
1707 * startup process waited longer than deadlock_timeout for it.
1708 */
1712 NULL, false);
1713
1714 /*
1715 * We don't have to do anything else, because the awaker did all the
1716 * necessary updates of the lock table and MyProc. (The caller is
1717 * responsible for updating the local lock table.)
1718 */
1719 return myWaitStatus;
1720}
1721
1722
1723/*
1724 * ProcWakeup -- wake up a process by setting its latch.
1725 *
1726 * Also remove the process from the wait queue and set its waitLink invalid.
1727 *
1728 * The appropriate lock partition lock must be held by caller.
1729 *
1730 * XXX: presently, this code is only used for the "success" case, and only
1731 * works correctly for that case. To clean up in failure case, would need
1732 * to twiddle the lock's request counts too --- see RemoveFromWaitQueue.
1733 * Hence, in practice the waitStatus parameter must be PROC_WAIT_STATUS_OK.
1734 */
1735void
1737{
1738 if (dlist_node_is_detached(&proc->waitLink))
1739 return;
1740
1742
1743 /* Remove process from wait queue */
1745
1746 /* Clean up process' state and pass it the ok/fail signal */
1747 proc->waitLock = NULL;
1748 proc->waitProcLock = NULL;
1749 proc->waitStatus = waitStatus;
1750 pg_atomic_write_u64(&proc->waitStart, 0);
1751
1752 /* And awaken it */
1753 SetLatch(&proc->procLatch);
1754}
1755
1756/*
1757 * ProcLockWakeup -- routine for waking up processes when a lock is
1758 * released (or a prior waiter is aborted). Scan all waiters
1759 * for lock, waken any that are no longer blocked.
1760 *
1761 * The appropriate lock partition lock must be held by caller.
1762 */
1763void
1765{
1769
1771 return;
1772
1774 {
1775 PGPROC *proc = dlist_container(PGPROC, waitLink, miter.cur);
1776 LOCKMODE lockmode = proc->waitLockMode;
1777
1778 /*
1779 * Waken if (a) doesn't conflict with requests of earlier waiters, and
1780 * (b) doesn't conflict with already-held locks.
1781 */
1782 if ((lockMethodTable->conflictTab[lockmode] & aheadRequests) == 0 &&
1783 !LockCheckConflicts(lockMethodTable, lockmode, lock,
1784 proc->waitProcLock))
1785 {
1786 /* OK to waken */
1787 GrantLock(lock, proc->waitProcLock, lockmode);
1788 /* removes proc from the lock's waiting process queue */
1790 }
1791 else
1792 {
1793 /*
1794 * Lock conflicts: Don't wake, but remember requested mode for
1795 * later checks.
1796 */
1797 aheadRequests |= LOCKBIT_ON(lockmode);
1798 }
1799 }
1800}
1801
1802/*
1803 * CheckDeadLock
1804 *
1805 * We only get to this routine, if DEADLOCK_TIMEOUT fired while waiting for a
1806 * lock to be released by some other process. Check if there's a deadlock; if
1807 * not, just return. If we have a real deadlock, remove ourselves from the
1808 * lock's wait queue.
1809 */
1810static DeadLockState
1812{
1813 int i;
1814 DeadLockState result;
1815
1816 /*
1817 * Acquire exclusive lock on the entire shared lock data structures. Must
1818 * grab LWLocks in partition-number order to avoid LWLock deadlock.
1819 *
1820 * Note that the deadlock check interrupt had better not be enabled
1821 * anywhere that this process itself holds lock partition locks, else this
1822 * will wait forever. Also note that LWLockAcquire creates a critical
1823 * section, so that this routine cannot be interrupted by cancel/die
1824 * interrupts.
1825 */
1826 for (i = 0; i < NUM_LOCK_PARTITIONS; i++)
1828
1829 /*
1830 * Check to see if we've been awoken by anyone in the interim.
1831 *
1832 * If we have, we can return and resume our transaction -- happy day.
1833 * Before we are awoken the process releasing the lock grants it to us so
1834 * we know that we don't have to wait anymore.
1835 *
1836 * We check by looking to see if we've been unlinked from the wait queue.
1837 * This is safe because we hold the lock partition lock.
1838 */
1840 {
1841 result = DS_NO_DEADLOCK;
1842 goto check_done;
1843 }
1844
1845#ifdef LOCK_DEBUG
1846 if (Debug_deadlocks)
1847 DumpAllLocks();
1848#endif
1849
1850 /* Run the deadlock check */
1851 result = DeadLockCheck(MyProc);
1852
1853 if (result == DS_HARD_DEADLOCK)
1854 {
1855 /*
1856 * Oops. We have a deadlock.
1857 *
1858 * Get this process out of wait state. (Note: we could do this more
1859 * efficiently by relying on lockAwaited, but use this coding to
1860 * preserve the flexibility to kill some other transaction than the
1861 * one detecting the deadlock.)
1862 *
1863 * RemoveFromWaitQueue sets MyProc->waitStatus to
1864 * PROC_WAIT_STATUS_ERROR, so ProcSleep will report an error after we
1865 * return.
1866 */
1869
1870 /*
1871 * We're done here. Transaction abort caused by the error that
1872 * ProcSleep will raise will cause any other locks we hold to be
1873 * released, thus allowing other processes to wake up; we don't need
1874 * to do that here. NOTE: an exception is that releasing locks we
1875 * hold doesn't consider the possibility of waiters that were blocked
1876 * behind us on the lock we just failed to get, and might now be
1877 * wakable because we're not in front of them anymore. However,
1878 * RemoveFromWaitQueue took care of waking up any such processes.
1879 */
1880 }
1881
1882 /*
1883 * And release locks. We do this in reverse order for two reasons: (1)
1884 * Anyone else who needs more than one of the locks will be trying to lock
1885 * them in increasing order; we don't want to release the other process
1886 * until it can get all the locks it needs. (2) This avoids O(N^2)
1887 * behavior inside LWLockRelease.
1888 */
1890 for (i = NUM_LOCK_PARTITIONS; --i >= 0;)
1892
1893 return result;
1894}
1895
1896/*
1897 * CheckDeadLockAlert - Handle the expiry of deadlock_timeout.
1898 *
1899 * NB: Runs inside a signal handler, be careful.
1900 */
1901void
1903{
1904 int save_errno = errno;
1905
1906 got_deadlock_timeout = true;
1907
1908 /*
1909 * Have to set the latch again, even if handle_sig_alarm already did. Back
1910 * then got_deadlock_timeout wasn't yet set... It's unlikely that this
1911 * ever would be a problem, but setting a set latch again is cheap.
1912 *
1913 * Note that, when this function runs inside procsignal_sigusr1_handler(),
1914 * the handler function sets the latch again after the latch is set here.
1915 */
1917 errno = save_errno;
1918}
1919
1920/*
1921 * GetLockHoldersAndWaiters - get lock holders and waiters for a lock
1922 *
1923 * Fill lock_holders_sbuf and lock_waiters_sbuf with the PIDs of processes holding
1924 * and waiting for the lock, and set lockHoldersNum to the number of lock holders.
1925 *
1926 * The lock table's partition lock must be held on entry and remains held on exit.
1927 */
1928void
1931{
1934 LOCK *lock = locallock->lock;
1935 bool first_holder = true,
1936 first_waiter = true;
1937
1938#ifdef USE_ASSERT_CHECKING
1939 {
1940 uint32 hashcode = locallock->hashcode;
1942
1944 }
1945#endif
1946
1947 *lockHoldersNum = 0;
1948
1949 /*
1950 * Loop over the lock's procLocks to gather a list of all holders and
1951 * waiters. Thus we will be able to provide more detailed information for
1952 * lock debugging purposes.
1953 *
1954 * lock->procLocks contains all processes which hold or wait for this
1955 * lock.
1956 */
1958 {
1959 curproclock =
1960 dlist_container(PROCLOCK, lockLink, proc_iter.cur);
1961
1962 /*
1963 * We are a waiter if myProc->waitProcLock == curproclock; we are a
1964 * holder if it is NULL or something different.
1965 */
1966 if (curproclock->tag.myProc->waitProcLock == curproclock)
1967 {
1968 if (first_waiter)
1969 {
1971 curproclock->tag.myProc->pid);
1972 first_waiter = false;
1973 }
1974 else
1976 curproclock->tag.myProc->pid);
1977 }
1978 else
1979 {
1980 if (first_holder)
1981 {
1983 curproclock->tag.myProc->pid);
1984 first_holder = false;
1985 }
1986 else
1988 curproclock->tag.myProc->pid);
1989
1990 (*lockHoldersNum)++;
1991 }
1992 }
1993}
1994
1995/*
1996 * ProcWaitForSignal - wait for a signal from another backend.
1997 *
1998 * As this uses the generic process latch the caller has to be robust against
1999 * unrelated wakeups: Always check that the desired state has occurred, and
2000 * wait again if not.
2001 */
2002void
2004{
2006 wait_event_info);
2009}
2010
2011/*
2012 * ProcSendSignal - set the latch of a backend identified by ProcNumber
2013 */
2014void
2016{
2018 elog(ERROR, "procNumber out of range");
2019
2020 SetLatch(&GetPGProcByNumber(procNumber)->procLatch);
2021}
2022
2023/*
2024 * BecomeLockGroupLeader - designate process as lock group leader
2025 *
2026 * Once this function has returned, other processes can join the lock group
2027 * by calling BecomeLockGroupMember.
2028 */
2029void
2031{
2033
2034 /* If we already did it, we don't need to do it again. */
2036 return;
2037
2038 /* We had better not be a follower. */
2040
2041 /* Create single-member group, containing only ourselves. */
2047}
2048
2049/*
2050 * BecomeLockGroupMember - designate process as lock group member
2051 *
2052 * This is pretty straightforward except for the possibility that the leader
2053 * whose group we're trying to join might exit before we manage to do so;
2054 * and the PGPROC might get recycled for an unrelated process. To avoid
2055 * that, we require the caller to pass the PID of the intended PGPROC as
2056 * an interlock. Returns true if we successfully join the intended lock
2057 * group, and false if not.
2058 */
2059bool
2061{
2063 bool ok = false;
2064
2065 /* Group leader can't become member of group */
2066 Assert(MyProc != leader);
2067
2068 /* Can't already be a member of a group */
2070
2071 /* PID must be valid. */
2072 Assert(pid != 0);
2073
2074 /*
2075 * Get lock protecting the group fields. Note LockHashPartitionLockByProc
2076 * calculates the proc number based on the PGPROC slot without looking at
2077 * its contents, so we will acquire the correct lock even if the leader
2078 * PGPROC is in process of being recycled.
2079 */
2082
2083 /* Is this the leader we're looking for? */
2084 if (leader->pid == pid && leader->lockGroupLeader == leader)
2085 {
2086 /* OK, join the group */
2087 ok = true;
2088 MyProc->lockGroupLeader = leader;
2090 }
2092
2093 return ok;
2094}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:485
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:274
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition atomics.h:237
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:453
int autovacuum_worker_slots
Definition autovacuum.c:120
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition timestamp.c:1715
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
Definition timestamp.c:1775
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1639
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1603
#define MAXALIGN(LEN)
Definition c.h:898
uint8_t uint8
Definition c.h:616
#define PG_USED_FOR_ASSERTS_ONLY
Definition c.h:243
#define Assert(condition)
Definition c.h:945
uint64_t uint64
Definition c.h:619
uint32_t uint32
Definition c.h:618
#define MemSet(start, val, len)
Definition c.h:1109
uint32 TransactionId
Definition c.h:738
size_t Size
Definition c.h:691
#define TRANSACTION_STATUS_IN_PROGRESS
Definition clog.h:27
bool ConditionVariableCancelSleep(void)
int64 TimestampTz
Definition timestamp.h:39
PGPROC * GetBlockingAutoVacuumPgproc(void)
Definition deadlock.c:290
void RememberSimpleDeadLock(PGPROC *proc1, LOCKMODE lockmode, LOCK *lock, PGPROC *proc2)
Definition deadlock.c:1147
void InitDeadLockChecking(void)
Definition deadlock.c:143
DeadLockState DeadLockCheck(PGPROC *proc)
Definition deadlock.c:220
Datum arg
Definition elog.c:1322
bool message_level_is_interesting(int elevel)
Definition elog.c:284
int errcode(int sqlerrcode)
Definition elog.c:874
#define LOG
Definition elog.h:31
#define FATAL
Definition elog.h:41
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define WARNING
Definition elog.h:36
#define PANIC
Definition elog.h:42
#define DEBUG1
Definition elog.h:30
#define ERROR
Definition elog.h:39
int int int errdetail_log(const char *fmt,...) pg_attribute_printf(1
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
int int int int errdetail_log_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
int MyProcPid
Definition globals.c:47
ProcNumber MyProcNumber
Definition globals.c:90
bool IsUnderPostmaster
Definition globals.c:120
int MaxConnections
Definition globals.c:143
int MaxBackends
Definition globals.c:146
struct Latch * MyLatch
Definition globals.c:63
int max_worker_processes
Definition globals.c:144
static dlist_node * dlist_pop_head_node(dlist_head *head)
Definition ilist.h:450
#define dlist_foreach(iter, lhead)
Definition ilist.h:623
static void dlist_init(dlist_head *head)
Definition ilist.h:314
static void dclist_push_tail(dclist_head *head, dlist_node *node)
Definition ilist.h:709
static void dlist_delete(dlist_node *node)
Definition ilist.h:405
static bool dclist_is_empty(const dclist_head *head)
Definition ilist.h:682
static bool dlist_node_is_detached(const dlist_node *node)
Definition ilist.h:525
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition ilist.h:347
static bool dlist_is_empty(const dlist_head *head)
Definition ilist.h:336
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition ilist.h:364
static void dclist_delete_from_thoroughly(dclist_head *head, dlist_node *node)
Definition ilist.h:776
static void dclist_insert_before(dclist_head *head, dlist_node *before, dlist_node *node)
Definition ilist.h:745
#define dclist_foreach_modify(iter, lhead)
Definition ilist.h:973
static void dlist_node_init(dlist_node *node)
Definition ilist.h:325
#define dlist_container(type, membername, ptr)
Definition ilist.h:593
#define dclist_foreach(iter, lhead)
Definition ilist.h:970
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:372
int j
Definition isn.c:78
int i
Definition isn.c:77
void OwnLatch(Latch *latch)
Definition latch.c:126
void DisownLatch(Latch *latch)
Definition latch.c:144
void InitSharedLatch(Latch *latch)
Definition latch.c:93
void SetLatch(Latch *latch)
Definition latch.c:290
void ResetLatch(Latch *latch)
Definition latch.c:374
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
Definition latch.c:172
void DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
Definition lmgr.c:1249
void GrantAwaitedLock(void)
Definition lock.c:1901
void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode)
Definition lock.c:1670
VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode, int *countp)
Definition lock.c:3081
void RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
Definition lock.c:2058
void LockReleaseAll(LOCKMETHODID lockmethodid, bool allLocks)
Definition lock.c:2319
void ResetAwaitedLock(void)
Definition lock.c:1919
void AbortStrongLockAcquire(void)
Definition lock.c:1872
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition lock.c:4264
LOCALLOCK * GetAwaitedLock(void)
Definition lock.c:1910
int FastPathLockGroupsPerBackend
Definition lock.c:203
uint32 LockTagHashCode(const LOCKTAG *locktag)
Definition lock.c:558
bool LockCheckConflicts(LockMethod lockMethodTable, LOCKMODE lockmode, LOCK *lock, PROCLOCK *proclock)
Definition lock.c:1541
#define LockHashPartitionLock(hashcode)
Definition lock.h:357
#define InvalidLocalTransactionId
Definition lock.h:68
DeadLockState
Definition lock.h:340
@ DS_HARD_DEADLOCK
Definition lock.h:344
@ DS_BLOCKED_BY_AUTOVACUUM
Definition lock.h:345
@ DS_NO_DEADLOCK
Definition lock.h:342
@ DS_NOT_YET_CHECKED
Definition lock.h:341
@ DS_SOFT_DEADLOCK
Definition lock.h:343
#define LOCKBIT_ON(lockmode)
Definition lock.h:87
#define LockHashPartitionLockByProc(leader_pgproc)
Definition lock.h:372
#define LockHashPartitionLockByIndex(i)
Definition lock.h:360
int LOCKMODE
Definition lockdefs.h:26
#define AccessExclusiveLock
Definition lockdefs.h:43
int LOCKMASK
Definition lockdefs.h:25
#define DEFAULT_LOCKMETHOD
Definition locktag.h:25
#define USER_LOCKMETHOD
Definition locktag.h:26
bool LWLockHeldByMe(LWLock *lock)
Definition lwlock.c:1912
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1177
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1956
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1794
void LWLockReleaseAll(void)
Definition lwlock.c:1893
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition lwlock.c:699
void InitLWLockAccess(void)
Definition lwlock.c:551
@ LW_WS_NOT_WAITING
Definition lwlock.h:30
#define NUM_LOCK_PARTITIONS
Definition lwlock.h:95
@ LW_SHARED
Definition lwlock.h:113
@ LW_EXCLUSIVE
Definition lwlock.h:112
void pfree(void *pointer)
Definition mcxt.c:1616
#define RESUME_INTERRUPTS()
Definition miscadmin.h:136
#define AmAutoVacuumWorkerProcess()
Definition miscadmin.h:383
#define AmBackgroundWorkerProcess()
Definition miscadmin.h:384
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
#define AmWalSenderProcess()
Definition miscadmin.h:385
#define HOLD_INTERRUPTS()
Definition miscadmin.h:134
#define AmSpecialWorkerProcess()
Definition miscadmin.h:396
void SwitchToSharedLatch(void)
Definition miscinit.c:216
BackendType MyBackendType
Definition miscinit.c:65
void SwitchBackToLocalLatch(void)
Definition miscinit.c:243
static char * errmsg
static char buf[DEFAULT_XLOG_SEG_SIZE]
void pgstat_count_lock_waits(uint8 locktag_type, long msecs)
void RegisterPostmasterChildActive(void)
Definition pmsignal.c:290
Size PGSemaphoreShmemSize(int maxSemas)
Definition posix_sema.c:165
void PGReserveSemaphores(int maxSemas)
Definition posix_sema.c:196
void PGSemaphoreReset(PGSemaphore sema)
Definition posix_sema.c:290
PGSemaphore PGSemaphoreCreate(void)
Definition posix_sema.c:257
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
#define NON_EXEC_STATIC
Definition postgres.h:560
#define InvalidOid
unsigned int Oid
static int fb(int x)
#define NUM_AUXILIARY_PROCS
Definition proc.h:526
#define FastPathLockSlotsPerBackend()
Definition proc.h:96
#define GetPGProcByNumber(n)
Definition proc.h:503
#define FIRST_PREPARED_XACT_PROC_NUMBER
Definition proc.h:528
#define PROC_VACUUM_FOR_WRAPAROUND
Definition proc.h:63
#define GetNumberFromPGProc(proc)
Definition proc.h:504
#define NUM_SPECIAL_WORKER_PROCS
Definition proc.h:513
ProcWaitStatus
Definition proc.h:143
@ PROC_WAIT_STATUS_OK
Definition proc.h:144
@ PROC_WAIT_STATUS_WAITING
Definition proc.h:145
@ PROC_WAIT_STATUS_ERROR
Definition proc.h:146
#define PROC_IS_AUTOVACUUM
Definition proc.h:60
void ProcArrayAdd(PGPROC *proc)
Definition procarray.c:472
void ProcArrayRemove(PGPROC *proc, TransactionId latestXid)
Definition procarray.c:569
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
int ProcNumber
Definition procnumber.h:24
void set_spins_per_delay(int shared_spins_per_delay)
Definition s_lock.c:207
int update_spins_per_delay(int shared_spins_per_delay)
Definition s_lock.c:218
#define DEFAULT_SPINS_PER_DELAY
Definition s_lock.h:718
Size add_size(Size s1, Size s2)
Definition shmem.c:485
Size mul_size(Size s1, Size s2)
Definition shmem.c:500
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:381
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56
static void SpinLockInit(volatile slock_t *lock)
Definition spin.h:50
ProcWaitStatus JoinWaitQueue(LOCALLOCK *locallock, LockMethod lockMethodTable, bool dontWait)
Definition proc.c:1135
void ProcSendSignal(ProcNumber procNumber)
Definition proc.c:2015
bool log_lock_waits
Definition proc.c:66
int IdleSessionTimeout
Definition proc.c:65
PGPROC * MyProc
Definition proc.c:69
Size ProcGlobalShmemSize(void)
Definition proc.c:131
void ProcWakeup(PGPROC *proc, ProcWaitStatus waitStatus)
Definition proc.c:1736
int StatementTimeout
Definition proc.c:61
bool HaveNFreeProcs(int n, int *nfree)
Definition proc.c:776
static void RemoveProcFromArray(int code, Datum arg)
Definition proc.c:902
void InitAuxiliaryProcess(void)
Definition proc.c:607
PGPROC * PreparedXactProcs
Definition proc.c:74
int IdleInTransactionSessionTimeout
Definition proc.c:63
void GetLockHoldersAndWaiters(LOCALLOCK *locallock, StringInfo lock_holders_sbuf, StringInfo lock_waiters_sbuf, int *lockHoldersNum)
Definition proc.c:1929
NON_EXEC_STATIC PGPROC * AuxiliaryProcs
Definition proc.c:73
int GetStartupBufferPinWaitBufId(void)
Definition proc.c:760
ProcWaitStatus ProcSleep(LOCALLOCK *locallock)
Definition proc.c:1304
int DeadlockTimeout
Definition proc.c:60
static Size PGProcShmemSize(void)
Definition proc.c:89
int TransactionTimeout
Definition proc.c:64
void ProcLockWakeup(LockMethod lockMethodTable, LOCK *lock)
Definition proc.c:1764
PROC_HDR * ProcGlobal
Definition proc.c:72
static Size FastPathLockShmemSize(void)
Definition proc.c:107
int ProcGlobalSemas(void)
Definition proc.c:150
void ProcReleaseLocks(bool isCommit)
Definition proc.c:885
void LockErrorCleanup(void)
Definition proc.c:807
bool BecomeLockGroupMember(PGPROC *leader, int pid)
Definition proc.c:2060
void BecomeLockGroupLeader(void)
Definition proc.c:2030
static void ProcKill(int code, Datum arg)
Definition proc.c:913
void InitProcess(void)
Definition proc.c:381
void CheckDeadLockAlert(void)
Definition proc.c:1902
void InitProcessPhase2(void)
Definition proc.c:572
void InitProcGlobal(void)
Definition proc.c:185
static volatile sig_atomic_t got_deadlock_timeout
Definition proc.c:77
PGPROC * AuxiliaryPidGetProc(int pid)
Definition proc.c:1086
void SetStartupBufferPinWaitBufId(int bufid)
Definition proc.c:748
void ProcWaitForSignal(uint32 wait_event_info)
Definition proc.c:2003
int LockTimeout
Definition proc.c:62
static void AuxiliaryProcKill(int code, Datum arg)
Definition proc.c:1035
static DeadLockState CheckDeadLock(void)
Definition proc.c:1811
void CheckRecoveryConflictDeadlock(void)
Definition standby.c:907
bool log_recovery_conflict_waits
Definition standby.c:43
void LogRecoveryConflict(RecoveryConflictReason reason, TimestampTz wait_start, TimestampTz now, VirtualTransactionId *wait_list, bool still_waiting)
Definition standby.c:275
void ResolveRecoveryConflictWithLock(LOCKTAG locktag, bool logging_conflict)
Definition standby.c:626
@ RECOVERY_CONFLICT_LOCK
Definition standby.h:40
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
uint8 locktag_lockmethodid
Definition locktag.h:71
Definition lock.h:140
LOCKTAG tag
Definition lock.h:142
dclist_head waitProcs
Definition lock.h:148
LOCKMASK waitMask
Definition lock.h:146
dlist_head procLocks
Definition lock.h:147
Definition proc.h:178
LWLock fpInfoLock
Definition proc.h:323
TransactionId xmin
Definition proc.h:241
bool procArrayGroupMember
Definition proc.h:349
LocalTransactionId lxid
Definition proc.h:230
PROCLOCK * waitProcLock
Definition proc.h:305
dlist_node freeProcsLink
Definition proc.h:185
XLogRecPtr clogGroupMemberLsn
Definition proc.h:370
pg_atomic_uint32 procArrayGroupNext
Definition proc.h:351
uint8 lwWaitMode
Definition proc.h:283
dlist_head lockGroupMembers
Definition proc.h:298
uint32 wait_event_info
Definition proc.h:377
dlist_head * procgloballist
Definition proc.h:184
Oid * fpRelId
Definition proc.h:325
BackendType backendType
Definition proc.h:197
uint8 statusFlags
Definition proc.h:209
TransactionId clogGroupMemberXid
Definition proc.h:365
Oid databaseId
Definition proc.h:200
int64 clogGroupMemberPage
Definition proc.h:368
bool clogGroupMember
Definition proc.h:363
uint64 * fpLockBits
Definition proc.h:324
struct PGPROC::@133 vxid
pg_atomic_uint64 waitStart
Definition proc.h:310
bool fpVXIDLock
Definition proc.h:326
ProcNumber procNumber
Definition proc.h:225
int pid
Definition proc.h:196
XLogRecPtr waitLSN
Definition proc.h:340
dlist_node syncRepLinks
Definition proc.h:342
int syncRepState
Definition proc.h:341
pg_atomic_uint32 clogGroupNext
Definition proc.h:364
dlist_node lockGroupLink
Definition proc.h:299
XidStatus clogGroupMemberXidStatus
Definition proc.h:366
LOCK * waitLock
Definition proc.h:303
TransactionId xid
Definition proc.h:236
LOCKMODE waitLockMode
Definition proc.h:306
int delayChkptFlags
Definition proc.h:259
dlist_node waitLink
Definition proc.h:304
PGPROC * lockGroupLeader
Definition proc.h:297
pg_atomic_uint32 pendingRecoveryConflicts
Definition proc.h:269
LocalTransactionId fpLocalTransactionId
Definition proc.h:327
TransactionId procArrayGroupMemberXid
Definition proc.h:357
LOCKMASK heldLocks
Definition proc.h:307
PGSemaphore sem
Definition proc.h:257
dlist_head myProcLocks[NUM_LOCK_PARTITIONS]
Definition proc.h:320
Oid roleId
Definition proc.h:201
ProcWaitStatus waitStatus
Definition proc.h:313
Oid tempNamespaceId
Definition proc.h:203
uint8 lwWaiting
Definition proc.h:282
Latch procLatch
Definition proc.h:255
LOCKMASK holdMask
Definition lock.h:207
uint8 * statusFlags
Definition proc.h:455
XidCacheStatus * subxidStates
Definition proc.h:449
dlist_head autovacFreeProcs
Definition proc.h:472
dlist_head freeProcs
Definition proc.h:470
ProcNumber checkpointerProc
Definition proc.h:488
slock_t freeProcsLock
Definition proc.h:467
int startupBufferPinWaitBufId
Definition proc.h:493
PGPROC * allProcs
Definition proc.h:440
pg_atomic_uint32 clogGroupFirst
Definition proc.h:481
int spins_per_delay
Definition proc.h:491
TransactionId * xids
Definition proc.h:443
dlist_head walsenderFreeProcs
Definition proc.h:476
dlist_head bgworkerFreeProcs
Definition proc.h:474
ProcNumber walwriterProc
Definition proc.h:487
pg_atomic_uint32 procArrayGroupFirst
Definition proc.h:479
uint32 allProcCount
Definition proc.h:458
dlist_node * cur
Definition ilist.h:179
Definition type.h:96
void SyncRepCleanupAtProcExit(void)
Definition syncrep.c:417
#define SYNC_REP_NOT_WAITING
Definition syncrep.h:30
void enable_timeout_after(TimeoutId id, int delay_ms)
Definition timeout.c:560
TimestampTz get_timeout_start_time(TimeoutId id)
Definition timeout.c:813
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition timeout.c:685
void enable_timeouts(const EnableTimeoutParams *timeouts, int count)
Definition timeout.c:630
void disable_timeouts(const DisableTimeoutParams *timeouts, int count)
Definition timeout.c:718
@ LOCK_TIMEOUT
Definition timeout.h:28
@ DEADLOCK_TIMEOUT
Definition timeout.h:27
@ TMPARAM_AFTER
Definition timeout.h:53
#define InvalidTransactionId
Definition transam.h:31
int max_prepared_xacts
Definition twophase.c:117
#define PG_WAIT_LOCK
void pgstat_set_wait_event_storage(uint32 *wait_event_info)
Definition wait_event.c:350
void pgstat_reset_wait_event_storage(void)
Definition wait_event.c:362
#define WL_EXIT_ON_PM_DEATH
#define WL_LATCH_SET
int max_wal_senders
Definition walsender.c:130
#define kill(pid, sig)
Definition win32_port.h:490
bool RecoveryInProgress(void)
Definition xlog.c:6444
#define InvalidXLogRecPtr
Definition xlogdefs.h:28
bool InRecovery
Definition xlogutils.c:50
#define InHotStandby
Definition xlogutils.h:60
void WaitLSNCleanup(void)
Definition xlogwait.c:339