Reproduce debug_query_string==NULL on parallel workers.
Certain background workers initiate parallel queries while debug_query_string==NULL, at which point they attempted strlen(NULL) and died to SIGSEGV. Older debug_query_string observers allow NULL, so do likewise in these newer ones. Back-patch to v11, where commit 7de4a1bcc56f494acbd0d6e70781df877dc8ecb5 introduced the first of these. Discussion: https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
This commit is contained in:
parent
ee03baad26
commit
ab2e2ce466
@ -3203,7 +3203,6 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
|
|||||||
WalUsage *wal_usage;
|
WalUsage *wal_usage;
|
||||||
bool *can_parallel_vacuum;
|
bool *can_parallel_vacuum;
|
||||||
long maxtuples;
|
long maxtuples;
|
||||||
char *sharedquery;
|
|
||||||
Size est_shared;
|
Size est_shared;
|
||||||
Size est_deadtuples;
|
Size est_deadtuples;
|
||||||
int nindexes_mwm = 0;
|
int nindexes_mwm = 0;
|
||||||
@ -3300,9 +3299,14 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
|
|||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
|
||||||
/* Finally, estimate PARALLEL_VACUUM_KEY_QUERY_TEXT space */
|
/* Finally, estimate PARALLEL_VACUUM_KEY_QUERY_TEXT space */
|
||||||
|
if (debug_query_string)
|
||||||
|
{
|
||||||
querylen = strlen(debug_query_string);
|
querylen = strlen(debug_query_string);
|
||||||
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
querylen = 0; /* keep compiler quiet */
|
||||||
|
|
||||||
InitializeParallelDSM(pcxt);
|
InitializeParallelDSM(pcxt);
|
||||||
|
|
||||||
@ -3347,10 +3351,16 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
|
|||||||
lps->wal_usage = wal_usage;
|
lps->wal_usage = wal_usage;
|
||||||
|
|
||||||
/* Store query string for workers */
|
/* Store query string for workers */
|
||||||
|
if (debug_query_string)
|
||||||
|
{
|
||||||
|
char *sharedquery;
|
||||||
|
|
||||||
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
||||||
memcpy(sharedquery, debug_query_string, querylen + 1);
|
memcpy(sharedquery, debug_query_string, querylen + 1);
|
||||||
sharedquery[querylen] = '\0';
|
sharedquery[querylen] = '\0';
|
||||||
shm_toc_insert(pcxt->toc, PARALLEL_VACUUM_KEY_QUERY_TEXT, sharedquery);
|
shm_toc_insert(pcxt->toc,
|
||||||
|
PARALLEL_VACUUM_KEY_QUERY_TEXT, sharedquery);
|
||||||
|
}
|
||||||
|
|
||||||
pfree(can_parallel_vacuum);
|
pfree(can_parallel_vacuum);
|
||||||
return lps;
|
return lps;
|
||||||
@ -3493,7 +3503,7 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
|
|||||||
elog(DEBUG1, "starting parallel vacuum worker for bulk delete");
|
elog(DEBUG1, "starting parallel vacuum worker for bulk delete");
|
||||||
|
|
||||||
/* Set debug_query_string for individual workers */
|
/* Set debug_query_string for individual workers */
|
||||||
sharedquery = shm_toc_lookup(toc, PARALLEL_VACUUM_KEY_QUERY_TEXT, false);
|
sharedquery = shm_toc_lookup(toc, PARALLEL_VACUUM_KEY_QUERY_TEXT, true);
|
||||||
debug_query_string = sharedquery;
|
debug_query_string = sharedquery;
|
||||||
pgstat_report_activity(STATE_RUNNING, debug_query_string);
|
pgstat_report_activity(STATE_RUNNING, debug_query_string);
|
||||||
|
|
||||||
|
@ -1465,7 +1465,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
WalUsage *walusage;
|
WalUsage *walusage;
|
||||||
BufferUsage *bufferusage;
|
BufferUsage *bufferusage;
|
||||||
bool leaderparticipates = true;
|
bool leaderparticipates = true;
|
||||||
char *sharedquery;
|
|
||||||
int querylen;
|
int querylen;
|
||||||
|
|
||||||
#ifdef DISABLE_LEADER_PARTICIPATION
|
#ifdef DISABLE_LEADER_PARTICIPATION
|
||||||
@ -1532,9 +1531,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
|
||||||
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
|
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
|
||||||
|
if (debug_query_string)
|
||||||
|
{
|
||||||
querylen = strlen(debug_query_string);
|
querylen = strlen(debug_query_string);
|
||||||
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
querylen = 0; /* keep compiler quiet */
|
||||||
|
|
||||||
/* Everyone's had a chance to ask for space, so now create the DSM */
|
/* Everyone's had a chance to ask for space, so now create the DSM */
|
||||||
InitializeParallelDSM(pcxt);
|
InitializeParallelDSM(pcxt);
|
||||||
@ -1598,9 +1602,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Store query string for workers */
|
/* Store query string for workers */
|
||||||
|
if (debug_query_string)
|
||||||
|
{
|
||||||
|
char *sharedquery;
|
||||||
|
|
||||||
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
||||||
memcpy(sharedquery, debug_query_string, querylen + 1);
|
memcpy(sharedquery, debug_query_string, querylen + 1);
|
||||||
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
|
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate space for each worker's WalUsage and BufferUsage; no need to
|
* Allocate space for each worker's WalUsage and BufferUsage; no need to
|
||||||
@ -1805,7 +1814,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
|
|||||||
#endif /* BTREE_BUILD_STATS */
|
#endif /* BTREE_BUILD_STATS */
|
||||||
|
|
||||||
/* Set debug_query_string for individual workers first */
|
/* Set debug_query_string for individual workers first */
|
||||||
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, false);
|
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
|
||||||
debug_query_string = sharedquery;
|
debug_query_string = sharedquery;
|
||||||
|
|
||||||
/* Report the query string from leader */
|
/* Report the query string from leader */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user