Skip to content

Commit 310d137

Browse files
committed
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
1 parent f530af8 commit 310d137

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,7 @@ pgstat_read_current_status(void)
28422842
LocalPgBackendStatus *localtable;
28432843
LocalPgBackendStatus *localentry;
28442844
char *localappname,
2845+
*localclienthostname,
28452846
*localactivity;
28462847
int i;
28472848

@@ -2857,6 +2858,9 @@ pgstat_read_current_status(void)
28572858
localappname = (char *)
28582859
MemoryContextAlloc(pgStatLocalContext,
28592860
NAMEDATALEN * MaxBackends);
2861+
localclienthostname = (char *)
2862+
MemoryContextAlloc(pgStatLocalContext,
2863+
NAMEDATALEN * MaxBackends);
28602864
localactivity = (char *)
28612865
MemoryContextAlloc(pgStatLocalContext,
28622866
pgstat_track_activity_query_size * MaxBackends);
@@ -2888,6 +2892,8 @@ pgstat_read_current_status(void)
28882892
*/
28892893
strcpy(localappname, (char *) beentry->st_appname);
28902894
localentry->backendStatus.st_appname = localappname;
2895+
strcpy(localclienthostname, (char *) beentry->st_clienthostname);
2896+
localentry->backendStatus.st_clienthostname = localclienthostname;
28912897
strcpy(localactivity, (char *) beentry->st_activity);
28922898
localentry->backendStatus.st_activity = localactivity;
28932899
}
@@ -2910,6 +2916,7 @@ pgstat_read_current_status(void)
29102916

29112917
localentry++;
29122918
localappname += NAMEDATALEN;
2919+
localclienthostname += NAMEDATALEN;
29132920
localactivity += pgstat_track_activity_query_size;
29142921
localNumBackends++;
29152922
}

0 commit comments

Comments
 (0)