Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6cb229d

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 d747c6d commit 6cb229d

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
@@ -2518,7 +2518,11 @@ pgstat_bestart(void)
25182518
beentry->st_databaseid = MyDatabaseId;
25192519
beentry->st_userid = userid;
25202520
beentry->st_clientaddr = clientaddr;
2521-
beentry->st_clienthostname[0] = '\0';
2521+
if (MyProcPort && MyProcPort->remote_hostname)
2522+
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname,
2523+
NAMEDATALEN);
2524+
else
2525+
beentry->st_clienthostname[0] = '\0';
25222526
beentry->st_waiting = false;
25232527
beentry->st_state = STATE_UNDEFINED;
25242528
beentry->st_appname[0] = '\0';
@@ -2531,9 +2535,6 @@ pgstat_bestart(void)
25312535
beentry->st_changecount++;
25322536
Assert((beentry->st_changecount & 1) == 0);
25332537

2534-
if (MyProcPort && MyProcPort->remote_hostname)
2535-
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname, NAMEDATALEN);
2536-
25372538
/* Update app name to current GUC setting */
25382539
if (application_name)
25392540
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
@@ -724,7 +724,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
724724
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
725725
values[11] = DirectFunctionCall1(inet_in,
726726
CStringGetDatum(remote_host));
727-
if (beentry->st_clienthostname)
727+
if (beentry->st_clienthostname &&
728+
beentry->st_clienthostname[0])
728729
values[12] = CStringGetTextDatum(beentry->st_clienthostname);
729730
else
730731
nulls[12] = true;

0 commit comments

Comments
 (0)