postgres.git / summary / log / commit / refs

commit    fd2efda5d6f16a0476b41fe14de954549236f76a
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Wed Apr 11 20:39:48 2018 +0000
First released in: 11.0, 9.3.23, 9.4.18, 9.5.13, 9.6.9, 10.4

    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


src/backend/postmaster/pgstat.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 64616a24139..3ec23d76ddc 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -2985,6 +2985,7 @@ pgstat_read_current_status(void) LocalPgBackendStatus *localtable; LocalPgBackendStatus *localentry; char *localappname, + *localclienthostname, *localactivity; #ifdef USE_SSL PgBackendSSLStatus *localsslstatus; @@ -3003,6 +3004,9 @@ pgstat_read_current_status(void) localappname = (char *) MemoryContextAlloc(pgStatLocalContext, NAMEDATALEN * MaxBackends); + localclienthostname = (char *) + MemoryContextAlloc(pgStatLocalContext, + NAMEDATALEN * MaxBackends); localactivity = (char *) MemoryContextAlloc(pgStatLocalContext, pgstat_track_activity_query_size * MaxBackends); @@ -3043,6 +3047,8 @@ pgstat_read_current_status(void) */ strcpy(localappname, (char *) beentry->st_appname); localentry->backendStatus.st_appname = localappname; + strcpy(localclienthostname, (char *) beentry->st_clienthostname); + localentry->backendStatus.st_clienthostname = localclienthostname; strcpy(localactivity, (char *) beentry->st_activity); localentry->backendStatus.st_activity = localactivity; localentry->backendStatus.st_ssl = beentry->st_ssl; @@ -3074,6 +3080,7 @@ pgstat_read_current_status(void) localentry++; localappname += NAMEDATALEN; + localclienthostname += NAMEDATALEN; localactivity += pgstat_track_activity_query_size; #ifdef USE_SSL localsslstatus++; [parent: 2224d1ce1447]