Skip to content

Commit 134d41f

Browse files
author
Commitfest Bot
committed
[CF 4291] v8 - Logging parallel worker draught
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/4291 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAA5RZ0tHb_hpq472oMj6S8F5kgXiOE-mV9QYSJOjn4g+CvZXmA@mail.gmail.com Author(s): Benoit Lobréau
2 parents 042a662 + 2eb6426 commit 134d41f

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed

doc/src/sgml/config.sgml

+18
Original file line numberDiff line numberDiff line change
@@ -7912,6 +7912,24 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
79127912
</listitem>
79137913
</varlistentry>
79147914

7915+
<varlistentry id="guc-log-parallel-workers" xreflabel="log_parallel_workers">
7916+
<term><varname>log_parallel_workers</varname> (<type>enum</type>)
7917+
<indexterm>
7918+
<primary><varname>log_parallel_workers</varname> configuration parameter</primary>
7919+
</indexterm>
7920+
</term>
7921+
<listitem>
7922+
<para>
7923+
Controls whether a log message about the number of workers is emitted during the
7924+
execution of a parallel query or utility statement. The default value is
7925+
<literal>none</literal> which disables logging. <literal>all</literal> emits
7926+
information for all parallel queries or utilities, whereas <literal>shortage</literal>
7927+
emits information only when the number of workers launched is lower than the number
7928+
of planned workers.
7929+
</para>
7930+
</listitem>
7931+
</varlistentry>
7932+
79157933
<varlistentry id="guc-log-parameter-max-length" xreflabel="log_parameter_max_length">
79167934
<term><varname>log_parameter_max_length</varname> (<type>integer</type>)
79177935
<indexterm>

src/backend/access/brin/brin.c

+4
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,10 @@ _brin_end_parallel(BrinLeader *brinleader, BrinBuildState *state)
25522552
/* Shutdown worker processes */
25532553
WaitForParallelWorkersToFinish(brinleader->pcxt);
25542554

2555+
LogParallelWorkersIfNeeded(log_parallel_workers,
2556+
brinleader->pcxt->nworkers_to_launch,
2557+
brinleader->pcxt->nworkers_launched);
2558+
25552559
/*
25562560
* Next, accumulate WAL usage. (This must wait for the workers to finish,
25572561
* or we might get incomplete data.)

src/backend/access/nbtree/nbtsort.c

+4
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,10 @@ _bt_end_parallel(BTLeader *btleader)
16131613
/* Shutdown worker processes */
16141614
WaitForParallelWorkersToFinish(btleader->pcxt);
16151615

1616+
LogParallelWorkersIfNeeded(log_parallel_workers,
1617+
btleader->pcxt->nworkers_to_launch,
1618+
btleader->pcxt->nworkers_launched);
1619+
16161620
/*
16171621
* Next, accumulate WAL usage. (This must wait for the workers to finish,
16181622
* or we might get incomplete data.)

src/backend/access/transam/parallel.c

+19
Original file line numberDiff line numberDiff line change
@@ -1663,3 +1663,22 @@ LookupParallelWorkerFunction(const char *libraryname, const char *funcname)
16631663
return (parallel_worker_main_type)
16641664
load_external_function(libraryname, funcname, true, NULL);
16651665
}
1666+
1667+
/*
1668+
* If required, emit information about parallel workers usage in
1669+
* the logs.
1670+
*/
1671+
void
1672+
LogParallelWorkersIfNeeded(int log_parallel_workers,
1673+
int parallel_workers_to_launch,
1674+
int parallel_workers_launched)
1675+
{
1676+
if ((log_parallel_workers == LOG_PARALLEL_WORKERS_ALL &&
1677+
parallel_workers_to_launch > 0) ||
1678+
(log_parallel_workers == LOG_PARALLEL_WORKERS_SHORTAGE &&
1679+
parallel_workers_to_launch != parallel_workers_launched))
1680+
ereport(LOG,
1681+
(errmsg("launched %i parallel workers (planned: %i)",
1682+
parallel_workers_launched,
1683+
parallel_workers_to_launch)));
1684+
}

src/backend/commands/vacuumparallel.c

+13
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ struct ParallelVacuumState
208208
int nindexes_parallel_cleanup;
209209
int nindexes_parallel_condcleanup;
210210

211+
int nworkers_to_launch;
212+
int nworkers_launched;
213+
211214
/* Buffer access strategy used by leader process */
212215
BufferAccessStrategy bstrategy;
213216

@@ -362,6 +365,9 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes,
362365
if ((vacoptions & VACUUM_OPTION_PARALLEL_COND_CLEANUP) != 0)
363366
pvs->nindexes_parallel_condcleanup++;
364367
}
368+
pvs->nworkers_to_launch = 0;
369+
pvs->nworkers_launched = 0;
370+
365371
shm_toc_insert(pcxt->toc, PARALLEL_VACUUM_KEY_INDEX_STATS, indstats);
366372
pvs->indstats = indstats;
367373

@@ -437,6 +443,10 @@ parallel_vacuum_end(ParallelVacuumState *pvs, IndexBulkDeleteResult **istats)
437443
{
438444
Assert(!IsParallelWorker());
439445

446+
LogParallelWorkersIfNeeded(log_parallel_workers,
447+
pvs->nworkers_to_launch,
448+
pvs->nworkers_launched);
449+
440450
/* Copy the updated statistics */
441451
for (int i = 0; i < pvs->nindexes; i++)
442452
{
@@ -738,6 +748,9 @@ parallel_vacuum_process_all_indexes(ParallelVacuumState *pvs, int num_index_scan
738748

739749
for (int i = 0; i < pvs->pcxt->nworkers_launched; i++)
740750
InstrAccumParallelQuery(&pvs->buffer_usage[i], &pvs->wal_usage[i]);
751+
752+
pvs->nworkers_to_launch += pvs->pcxt->nworkers_to_launch;
753+
pvs->nworkers_launched += pvs->pcxt->nworkers_launched;
741754
}
742755

743756
/*

src/backend/executor/execMain.c

+4
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ standard_ExecutorEnd(QueryDesc *queryDesc)
560560
pgstat_update_parallel_workers_stats((PgStat_Counter) estate->es_parallel_workers_to_launch,
561561
(PgStat_Counter) estate->es_parallel_workers_launched);
562562

563+
LogParallelWorkersIfNeeded(log_parallel_workers,
564+
estate->es_parallel_workers_to_launch,
565+
estate->es_parallel_workers_launched);
566+
563567
/*
564568
* Check that ExecutorFinish was called, unless in EXPLAIN-only mode or if
565569
* execution was aborted.

src/backend/utils/misc/guc_tables.c

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "access/commit_ts.h"
3030
#include "access/gin.h"
31+
#include "access/parallel.h"
3132
#include "access/slru.h"
3233
#include "access/toast_compression.h"
3334
#include "access/twophase.h"
@@ -428,6 +429,13 @@ static const struct config_enum_entry debug_logical_replication_streaming_option
428429
{NULL, 0, false}
429430
};
430431

432+
static const struct config_enum_entry log_parallel_workers_options[] = {
433+
{"none", LOG_PARALLEL_WORKERS_NONE, false},
434+
{"all", LOG_PARALLEL_WORKERS_ALL, false},
435+
{"shortage", LOG_PARALLEL_WORKERS_SHORTAGE, false},
436+
{NULL, 0, false}
437+
};
438+
431439
StaticAssertDecl(lengthof(ssl_protocol_versions_info) == (PG_TLS1_3_VERSION + 2),
432440
"array length mismatch");
433441

@@ -531,6 +539,7 @@ int log_min_duration_statement = -1;
531539
int log_parameter_max_length = -1;
532540
int log_parameter_max_length_on_error = 0;
533541
int log_temp_files = -1;
542+
int log_parallel_workers = LOG_PARALLEL_WORKERS_NONE;
534543
double log_statement_sample_rate = 1.0;
535544
double log_xact_sample_rate = 0;
536545
char *backtrace_functions;
@@ -5340,6 +5349,16 @@ struct config_enum ConfigureNamesEnum[] =
53405349
NULL, NULL, NULL
53415350
},
53425351

5352+
{
5353+
{"log_parallel_workers", PGC_SUSET, LOGGING_WHAT,
5354+
gettext_noop("Log information about parallel worker usage"),
5355+
NULL
5356+
},
5357+
&log_parallel_workers,
5358+
LOG_PARALLEL_WORKERS_NONE, log_parallel_workers_options,
5359+
NULL, NULL, NULL
5360+
},
5361+
53435362
{
53445363
{"ssl_min_protocol_version", PGC_SIGHUP, CONN_AUTH_SSL,
53455364
gettext_noop("Sets the minimum SSL/TLS protocol version to use."),

src/backend/utils/misc/postgresql.conf.sample

+1
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@
638638
#log_temp_files = -1 # log temporary files equal or larger
639639
# than the specified size in kilobytes;
640640
# -1 disables, 0 logs all temp files
641+
#log_parallel_workers = none # none, all, shortage
641642
#log_timezone = 'GMT'
642643

643644
# - Process Title -

src/include/access/parallel.h

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ typedef struct ParallelWorkerContext
5353
shm_toc *toc;
5454
} ParallelWorkerContext;
5555

56+
typedef enum {
57+
LOG_PARALLEL_WORKERS_NONE=0,
58+
LOG_PARALLEL_WORKERS_ALL,
59+
LOG_PARALLEL_WORKERS_SHORTAGE,
60+
} log_parallel_workers_option_list;
61+
5662
extern PGDLLIMPORT volatile sig_atomic_t ParallelMessagePending;
5763
extern PGDLLIMPORT int ParallelWorkerNumber;
5864
extern PGDLLIMPORT bool InitializingParallelWorker;
@@ -78,4 +84,8 @@ extern void ParallelWorkerReportLastRecEnd(XLogRecPtr last_xlog_end);
7884

7985
extern void ParallelWorkerMain(Datum main_arg);
8086

87+
extern void LogParallelWorkersIfNeeded(int log_parallel_workers,
88+
int parallel_workers_to_launch,
89+
int parallel_workers_launched);
90+
8191
#endif /* PARALLEL_H */

src/include/utils/guc.h

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ extern PGDLLIMPORT int log_temp_files;
279279
extern PGDLLIMPORT double log_statement_sample_rate;
280280
extern PGDLLIMPORT double log_xact_sample_rate;
281281
extern PGDLLIMPORT char *backtrace_functions;
282+
extern PGDLLIMPORT int log_parallel_workers;
282283

283284
extern PGDLLIMPORT int temp_file_limit;
284285

0 commit comments

Comments
 (0)