Commit a820b4c3 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Make local copy of client hostnames in backend status array.

The other strings, application_name and query string, were snapshotted to
local memory in pgstat_read_current_status(), but we forgot to do that for
client hostnames. As a result, the client hostname would appear to change in
the local copy, if the client disconnected.

Backpatch to all supported versions.

Author: Edmund Horner
Reviewed-by: Michael Paquier
Discussion: https://www.postgresql.org/message-id/CAMyN-kA7aOJzBmrYFdXcc7Z0NmW%2B5jBaf_m%3D_-77uRNyKC9r%3DA%40mail.gmail.com
parent 72cf7f31
...@@ -3224,6 +3224,7 @@ pgstat_read_current_status(void) ...@@ -3224,6 +3224,7 @@ pgstat_read_current_status(void)
LocalPgBackendStatus *localtable; LocalPgBackendStatus *localtable;
LocalPgBackendStatus *localentry; LocalPgBackendStatus *localentry;
char *localappname, char *localappname,
*localclienthostname,
*localactivity; *localactivity;
#ifdef USE_SSL #ifdef USE_SSL
PgBackendSSLStatus *localsslstatus; PgBackendSSLStatus *localsslstatus;
...@@ -3242,6 +3243,9 @@ pgstat_read_current_status(void) ...@@ -3242,6 +3243,9 @@ pgstat_read_current_status(void)
localappname = (char *) localappname = (char *)
MemoryContextAlloc(pgStatLocalContext, MemoryContextAlloc(pgStatLocalContext,
NAMEDATALEN * NumBackendStatSlots); NAMEDATALEN * NumBackendStatSlots);
localclienthostname = (char *)
MemoryContextAlloc(pgStatLocalContext,
NAMEDATALEN * NumBackendStatSlots);
localactivity = (char *) localactivity = (char *)
MemoryContextAlloc(pgStatLocalContext, MemoryContextAlloc(pgStatLocalContext,
pgstat_track_activity_query_size * NumBackendStatSlots); pgstat_track_activity_query_size * NumBackendStatSlots);
...@@ -3282,6 +3286,8 @@ pgstat_read_current_status(void) ...@@ -3282,6 +3286,8 @@ pgstat_read_current_status(void)
*/ */
strcpy(localappname, (char *) beentry->st_appname); strcpy(localappname, (char *) beentry->st_appname);
localentry->backendStatus.st_appname = localappname; localentry->backendStatus.st_appname = localappname;
strcpy(localclienthostname, (char *) beentry->st_clienthostname);
localentry->backendStatus.st_clienthostname = localclienthostname;
strcpy(localactivity, (char *) beentry->st_activity_raw); strcpy(localactivity, (char *) beentry->st_activity_raw);
localentry->backendStatus.st_activity_raw = localactivity; localentry->backendStatus.st_activity_raw = localactivity;
localentry->backendStatus.st_ssl = beentry->st_ssl; localentry->backendStatus.st_ssl = beentry->st_ssl;
...@@ -3313,6 +3319,7 @@ pgstat_read_current_status(void) ...@@ -3313,6 +3319,7 @@ pgstat_read_current_status(void)
localentry++; localentry++;
localappname += NAMEDATALEN; localappname += NAMEDATALEN;
localclienthostname += NAMEDATALEN;
localactivity += pgstat_track_activity_query_size; localactivity += pgstat_track_activity_query_size;
#ifdef USE_SSL #ifdef USE_SSL
localsslstatus++; localsslstatus++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment