Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab2e2ce

Browse files
committed
Reproduce debug_query_string==NULL on parallel workers.
Certain background workers initiate parallel queries whiledebug_query_string==NULL, at which point they attempted strlen(NULL) anddied to SIGSEGV. Older debug_query_string observers allow NULL, so dolikewise in these newer ones. Back-patch to v11, where commit7de4a1b introduced the first of these.Discussion:https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
1 parentee03baa commitab2e2ce

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

‎src/backend/access/heap/vacuumlazy.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,6 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
32033203
WalUsage*wal_usage;
32043204
bool*can_parallel_vacuum;
32053205
longmaxtuples;
3206-
char*sharedquery;
32073206
Sizeest_shared;
32083207
Sizeest_deadtuples;
32093208
intnindexes_mwm=0;
@@ -3300,9 +3299,14 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
33003299
shm_toc_estimate_keys(&pcxt->estimator,1);
33013300

33023301
/* Finally, estimate PARALLEL_VACUUM_KEY_QUERY_TEXT space */
3303-
querylen=strlen(debug_query_string);
3304-
shm_toc_estimate_chunk(&pcxt->estimator,querylen+1);
3305-
shm_toc_estimate_keys(&pcxt->estimator,1);
3302+
if (debug_query_string)
3303+
{
3304+
querylen=strlen(debug_query_string);
3305+
shm_toc_estimate_chunk(&pcxt->estimator,querylen+1);
3306+
shm_toc_estimate_keys(&pcxt->estimator,1);
3307+
}
3308+
else
3309+
querylen=0;/* keep compiler quiet */
33063310

33073311
InitializeParallelDSM(pcxt);
33083312

@@ -3347,10 +3351,16 @@ begin_parallel_vacuum(Oid relid, Relation *Irel, LVRelStats *vacrelstats,
33473351
lps->wal_usage=wal_usage;
33483352

33493353
/* Store query string for workers */
3350-
sharedquery= (char*)shm_toc_allocate(pcxt->toc,querylen+1);
3351-
memcpy(sharedquery,debug_query_string,querylen+1);
3352-
sharedquery[querylen]='\0';
3353-
shm_toc_insert(pcxt->toc,PARALLEL_VACUUM_KEY_QUERY_TEXT,sharedquery);
3354+
if (debug_query_string)
3355+
{
3356+
char*sharedquery;
3357+
3358+
sharedquery= (char*)shm_toc_allocate(pcxt->toc,querylen+1);
3359+
memcpy(sharedquery,debug_query_string,querylen+1);
3360+
sharedquery[querylen]='\0';
3361+
shm_toc_insert(pcxt->toc,
3362+
PARALLEL_VACUUM_KEY_QUERY_TEXT,sharedquery);
3363+
}
33543364

33553365
pfree(can_parallel_vacuum);
33563366
returnlps;
@@ -3493,7 +3503,7 @@ parallel_vacuum_main(dsm_segment *seg, shm_toc *toc)
34933503
elog(DEBUG1,"starting parallel vacuum worker for bulk delete");
34943504

34953505
/* Set debug_query_string for individual workers */
3496-
sharedquery=shm_toc_lookup(toc,PARALLEL_VACUUM_KEY_QUERY_TEXT,false);
3506+
sharedquery=shm_toc_lookup(toc,PARALLEL_VACUUM_KEY_QUERY_TEXT,true);
34973507
debug_query_string=sharedquery;
34983508
pgstat_report_activity(STATE_RUNNING,debug_query_string);
34993509

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
14651465
WalUsage*walusage;
14661466
BufferUsage*bufferusage;
14671467
boolleaderparticipates= true;
1468-
char*sharedquery;
14691468
intquerylen;
14701469

14711470
#ifdefDISABLE_LEADER_PARTICIPATION
@@ -1532,9 +1531,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
15321531
shm_toc_estimate_keys(&pcxt->estimator,1);
15331532

15341533
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
1535-
querylen=strlen(debug_query_string);
1536-
shm_toc_estimate_chunk(&pcxt->estimator,querylen+1);
1537-
shm_toc_estimate_keys(&pcxt->estimator,1);
1534+
if (debug_query_string)
1535+
{
1536+
querylen=strlen(debug_query_string);
1537+
shm_toc_estimate_chunk(&pcxt->estimator,querylen+1);
1538+
shm_toc_estimate_keys(&pcxt->estimator,1);
1539+
}
1540+
else
1541+
querylen=0;/* keep compiler quiet */
15381542

15391543
/* Everyone's had a chance to ask for space, so now create the DSM */
15401544
InitializeParallelDSM(pcxt);
@@ -1598,9 +1602,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
15981602
}
15991603

16001604
/* Store query string for workers */
1601-
sharedquery= (char*)shm_toc_allocate(pcxt->toc,querylen+1);
1602-
memcpy(sharedquery,debug_query_string,querylen+1);
1603-
shm_toc_insert(pcxt->toc,PARALLEL_KEY_QUERY_TEXT,sharedquery);
1605+
if (debug_query_string)
1606+
{
1607+
char*sharedquery;
1608+
1609+
sharedquery= (char*)shm_toc_allocate(pcxt->toc,querylen+1);
1610+
memcpy(sharedquery,debug_query_string,querylen+1);
1611+
shm_toc_insert(pcxt->toc,PARALLEL_KEY_QUERY_TEXT,sharedquery);
1612+
}
16041613

16051614
/*
16061615
* 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)
18051814
#endif/* BTREE_BUILD_STATS */
18061815

18071816
/* Set debug_query_string for individual workers first */
1808-
sharedquery=shm_toc_lookup(toc,PARALLEL_KEY_QUERY_TEXT,false);
1817+
sharedquery=shm_toc_lookup(toc,PARALLEL_KEY_QUERY_TEXT,true);
18091818
debug_query_string=sharedquery;
18101819

18111820
/* Report the query string from leader */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp