PostgreSQL Source Code git master
procnumber.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * procnumber.h
4 * definition of process number
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/storage/procnumber.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef PROCNUMBER_H
15#define PROCNUMBER_H
16
17/*
18 * ProcNumber uniquely identifies an active backend or auxiliary process.
19 * It's assigned at backend startup after authentication, when the process
20 * adds itself to the proc array. It is an index into the proc array,
21 * starting from 0. Note that a ProcNumber can be reused for a different
22 * backend immediately after a backend exits.
23 */
24typedef int ProcNumber;
25
26#define INVALID_PROC_NUMBER (-1)
27
28/*
29 * Note: MAX_BACKENDS_BITS is 18 as that is the space available for buffer
30 * refcounts in buf_internals.h. This limitation could be lifted by using a
31 * 64bit state; but it's unlikely to be worthwhile as 2^18-1 backends exceed
32 * currently realistic configurations. Even if that limitation were removed,
33 * we still could not a) exceed 2^23-1 because inval.c stores the ProcNumber
34 * as a 3-byte signed integer, b) INT_MAX/4 because some places compute
35 * 4*MaxBackends without any overflow check. We check that the configured
36 * number of backends does not exceed MAX_BACKENDS in InitializeMaxBackends().
37 */
38#define MAX_BACKENDS_BITS 18
39#define MAX_BACKENDS ((1U << MAX_BACKENDS_BITS)-1)
40
41/*
42 * Proc number of this backend (same as GetNumberFromPGProc(MyProc))
43 */
45
46/* proc number of our parallel session leader, or INVALID_PROC_NUMBER if none */
48
49/*
50 * The ProcNumber to use for our session's temp relations is normally our own,
51 * but parallel workers should use their leader's proc number.
52 */
53#define ProcNumberForTempRelations() \
54 (ParallelLeaderProcNumber == INVALID_PROC_NUMBER ? MyProcNumber : ParallelLeaderProcNumber)
55
56#endif /* PROCNUMBER_H */
#define PGDLLIMPORT
Definition: c.h:1291
int ProcNumber
Definition: procnumber.h:24
PGDLLIMPORT ProcNumber ParallelLeaderProcNumber
Definition: globals.c:91
PGDLLIMPORT ProcNumber MyProcNumber
Definition: globals.c:89