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

Commitf7b0006

Browse files
committed
Avoid updating our PgBackendStatus entry when track_activities is off.
The point of turning off track_activities is to avoid this reportingoverhead, but a thinko in commit4f42b54caused pgstat_report_activity() to perform half of its updates anyway.Fix that, and also make sure that we clear all the now-disabled fieldswhen transitioning to the non-reporting state.
1 parent0f1345d commitf7b0006

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ pgstat_beshutdown_hook(int code, Datum arg)
25602560
* pgstat_report_activity() -
25612561
*
25622562
*Called from tcop/postgres.c to report what the backend is actually doing
2563-
*(usually "<IDLE>" or the start of the query to be executed).
2563+
*(but note cmd_str can be NULL for certain cases).
25642564
*
25652565
* All updates of the status entry follow the protocol of bumping
25662566
* st_changecount before and after. We use a volatile pointer here to
@@ -2580,36 +2580,40 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
25802580
if (!beentry)
25812581
return;
25822582

2583-
/*
2584-
* To minimize the time spent modifying the entry, fetch all the needed
2585-
* data first.
2586-
*/
2587-
current_timestamp=GetCurrentTimestamp();
2588-
2589-
if (!pgstat_track_activities&&beentry->st_state!=STATE_DISABLED)
2583+
if (!pgstat_track_activities)
25902584
{
2591-
/*
2592-
* Track activities is disabled, but we have a non-disabled state set.
2593-
* That means the status changed - so as our last update, tell the
2594-
* collector that we disabled it and will no longer update.
2595-
*/
2596-
beentry->st_changecount++;
2597-
beentry->st_state=STATE_DISABLED;
2598-
beentry->st_state_start_timestamp=current_timestamp;
2599-
beentry->st_changecount++;
2600-
Assert((beentry->st_changecount&1)==0);
2585+
if (beentry->st_state!=STATE_DISABLED)
2586+
{
2587+
/*
2588+
* track_activities is disabled, but we last reported a
2589+
* non-disabled state. As our final update, change the state and
2590+
* clear fields we will not be updating anymore.
2591+
*/
2592+
beentry->st_changecount++;
2593+
beentry->st_state=STATE_DISABLED;
2594+
beentry->st_state_start_timestamp=0;
2595+
beentry->st_activity[0]='\0';
2596+
beentry->st_activity_start_timestamp=0;
2597+
/* st_xact_start_timestamp and st_waiting are also disabled */
2598+
beentry->st_xact_start_timestamp=0;
2599+
beentry->st_waiting= false;
2600+
beentry->st_changecount++;
2601+
Assert((beentry->st_changecount&1)==0);
2602+
}
26012603
return;
26022604
}
26032605

26042606
/*
2605-
* Fetch more data before we start modifying the entry
2607+
* To minimize the time spent modifying the entry, fetch all the needed
2608+
* data first.
26062609
*/
26072610
start_timestamp=GetCurrentStatementStartTimestamp();
26082611
if (cmd_str!=NULL)
26092612
{
26102613
len=pg_mbcliplen(cmd_str,strlen(cmd_str),
26112614
pgstat_track_activity_query_size-1);
26122615
}
2616+
current_timestamp=GetCurrentTimestamp();
26132617

26142618
/*
26152619
* Now update the status entry

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
666666
nulls[4]= true;
667667
break;
668668
}
669-
if (beentry->st_state==STATE_UNDEFINED||
670-
beentry->st_state==STATE_DISABLED)
671-
{
672-
values[5]=CStringGetTextDatum("");
673-
}
674-
else
675-
{
676-
values[5]=CStringGetTextDatum(beentry->st_activity);
677-
}
669+
670+
values[5]=CStringGetTextDatum(beentry->st_activity);
678671
values[6]=BoolGetDatum(beentry->st_waiting);
679672

680673
if (beentry->st_xact_start_timestamp!=0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp