PostgreSQL Source Code git master
Loading...
Searching...
No Matches
backend_progress.c
Go to the documentation of this file.
1/* ----------
2 * backend_progress.c
3 *
4 * Command progress reporting infrastructure.
5 *
6 * Copyright (c) 2001-2026, PostgreSQL Global Development Group
7 *
8 * src/backend/utils/activity/backend_progress.c
9 * ----------
10 */
11#include "postgres.h"
12
13#include "access/parallel.h"
14#include "libpq/pqformat.h"
15#include "storage/proc.h"
18
19
20/*-----------
21 * pgstat_progress_start_command() -
22 *
23 * Set st_progress_command (and st_progress_command_target) in own backend
24 * entry. Also, zero-initialize st_progress_param array.
25 *-----------
26 */
27void
29{
31
33 return;
34
36 beentry->st_progress_command = cmdtype;
37 beentry->st_progress_command_target = relid;
38 MemSet(&beentry->st_progress_param, 0, sizeof(beentry->st_progress_param));
40}
41
42/*-----------
43 * pgstat_progress_update_param() -
44 *
45 * Update index'th member in st_progress_param[] of own backend entry.
46 *-----------
47 */
48void
62
63/*-----------
64 * pgstat_progress_incr_param() -
65 *
66 * Increment index'th member in st_progress_param[] of own backend entry.
67 *-----------
68 */
69void
83
84/*-----------
85 * pgstat_progress_parallel_incr_param() -
86 *
87 * A variant of pgstat_progress_incr_param to allow a worker to poke at
88 * a leader to do an incremental progress update.
89 *-----------
90 */
91void
93{
94 /*
95 * Parallel workers notify a leader through a PqMsg_Progress message to
96 * update progress, passing the progress index and incremented value.
97 * Leaders can just call pgstat_progress_incr_param directly.
98 */
99 if (IsParallelWorker())
100 {
102
107 }
108 else
110}
111
112/*-----------
113 * pgstat_progress_update_multi_param() -
114 *
115 * Update multiple members in st_progress_param[] of own backend entry.
116 * This is atomic; readers won't see intermediate states.
117 *-----------
118 */
119void
121 const int64 *val)
122{
124 int i;
125
126 if (!beentry || !pgstat_track_activities || nparam == 0)
127 return;
128
130
131 for (i = 0; i < nparam; ++i)
132 {
134
135 beentry->st_progress_param[index[i]] = val[i];
136 }
137
139}
140
141/*-----------
142 * pgstat_progress_end_command() -
143 *
144 * Reset st_progress_command (and st_progress_command_target) in own backend
145 * entry. This signals the end of the command.
146 *-----------
147 */
148void
150{
152
154 return;
155
156 if (beentry->st_progress_command == PROGRESS_COMMAND_INVALID)
157 return;
158
160 beentry->st_progress_command = PROGRESS_COMMAND_INVALID;
161 beentry->st_progress_command_target = InvalidOid;
163}
void pgstat_progress_parallel_incr_param(int index, int64 incr)
void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)
void pgstat_progress_incr_param(int index, int64 incr)
void pgstat_progress_update_param(int index, int64 val)
void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)
void pgstat_progress_end_command(void)
#define PGSTAT_NUM_PROGRESS_PARAM
ProgressCommandType
@ PROGRESS_COMMAND_INVALID
PgBackendStatus * MyBEEntry
bool pgstat_track_activities
#define PGSTAT_END_WRITE_ACTIVITY(beentry)
#define PGSTAT_BEGIN_WRITE_ACTIVITY(beentry)
#define Assert(condition)
Definition c.h:943
int64_t int64
Definition c.h:621
#define MemSet(start, val, len)
Definition c.h:1107
#define IsParallelWorker()
Definition parallel.h:62
long val
Definition informix.c:689
int i
Definition isn.c:77
#define InvalidOid
unsigned int Oid
void pq_endmessage(StringInfo buf)
Definition pqformat.c:296
void pq_beginmessage(StringInfo buf, char msgtype)
Definition pqformat.c:88
static void pq_sendint32(StringInfo buf, uint32 i)
Definition pqformat.h:144
static void pq_sendint64(StringInfo buf, uint64 i)
Definition pqformat.h:152
static int fb(int x)
#define PqMsg_Progress
Definition protocol.h:70
Definition type.h:97