Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b8e288f

Browse files
bloghCommitfest Bot
authored and
Commitfest Bot
committed
Add a guc for parallel worker logging
The new guc log_parallel_workers controls whether a log message is produced to display information on the number of workers spawned when a parallel query or utility is executed. The default value is `none` which disables logging. `all` displays information for all parallel queries, whereas `shortage` displays information only when the number of workers launched is lower than the number of planned workers. This new parameter can help database administrators and developers diagnose performance issues related to parallelism and optimize the configuration of the system accordingly.
1 parent 042a662 commit b8e288f

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

doc/src/sgml/config.sgml

Lines changed: 18 additions & 0 deletions
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/transam/parallel.c

Lines changed: 19 additions & 0 deletions
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/utils/misc/guc_tables.c

Lines changed: 19 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)