Skip to content

Commit 2b52069

Browse files
committed
Fix bugs in manipulation of PgBackendStatus.st_clienthostname.
Initialization of this field was not being done according to the st_changecount protocol (it has to be done within the changecount increment range, not outside). And the test to see if the value should be reported as null was wrong. Noted while perusing uses of Port.remote_hostname. This was wrong from the introduction of this code (commit 4a25bc1), so back-patch to 9.1.
1 parent b924d4c commit 2b52069

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,11 @@ pgstat_bestart(void)
24042404
beentry->st_databaseid = MyDatabaseId;
24052405
beentry->st_userid = userid;
24062406
beentry->st_clientaddr = clientaddr;
2407-
beentry->st_clienthostname[0] = '\0';
2407+
if (MyProcPort && MyProcPort->remote_hostname)
2408+
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname,
2409+
NAMEDATALEN);
2410+
else
2411+
beentry->st_clienthostname[0] = '\0';
24082412
beentry->st_waiting = false;
24092413
beentry->st_appname[0] = '\0';
24102414
beentry->st_activity[0] = '\0';
@@ -2416,9 +2420,6 @@ pgstat_bestart(void)
24162420
beentry->st_changecount++;
24172421
Assert((beentry->st_changecount & 1) == 0);
24182422

2419-
if (MyProcPort && MyProcPort->remote_hostname)
2420-
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname, NAMEDATALEN);
2421-
24222423
/* Update app name to current GUC setting */
24232424
if (application_name)
24242425
pgstat_report_appname(application_name);

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
694694
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
695695
values[9] = DirectFunctionCall1(inet_in,
696696
CStringGetDatum(remote_host));
697-
if (beentry->st_clienthostname)
697+
if (beentry->st_clienthostname &&
698+
beentry->st_clienthostname[0])
698699
values[10] = CStringGetTextDatum(beentry->st_clienthostname);
699700
else
700701
nulls[10] = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy