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 4a25bc145),
so back-patch to 9.1.
pull/6/head
Tom Lane 12 years ago
parent 8bbbcb91ba
commit 682c5bbec5
  1. 9
      src/backend/postmaster/pgstat.c
  2. 3
      src/backend/utils/adt/pgstatfuncs.c

@ -2581,7 +2581,11 @@ pgstat_bestart(void)
beentry->st_databaseid = MyDatabaseId; beentry->st_databaseid = MyDatabaseId;
beentry->st_userid = userid; beentry->st_userid = userid;
beentry->st_clientaddr = clientaddr; beentry->st_clientaddr = clientaddr;
beentry->st_clienthostname[0] = '\0'; if (MyProcPort && MyProcPort->remote_hostname)
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname,
NAMEDATALEN);
else
beentry->st_clienthostname[0] = '\0';
beentry->st_waiting = false; beentry->st_waiting = false;
beentry->st_state = STATE_UNDEFINED; beentry->st_state = STATE_UNDEFINED;
beentry->st_appname[0] = '\0'; beentry->st_appname[0] = '\0';
@ -2594,9 +2598,6 @@ pgstat_bestart(void)
beentry->st_changecount++; beentry->st_changecount++;
Assert((beentry->st_changecount & 1) == 0); Assert((beentry->st_changecount & 1) == 0);
if (MyProcPort && MyProcPort->remote_hostname)
strlcpy(beentry->st_clienthostname, MyProcPort->remote_hostname, NAMEDATALEN);
/* Update app name to current GUC setting */ /* Update app name to current GUC setting */
if (application_name) if (application_name)
pgstat_report_appname(application_name); pgstat_report_appname(application_name);

@ -760,7 +760,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host); clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
values[11] = DirectFunctionCall1(inet_in, values[11] = DirectFunctionCall1(inet_in,
CStringGetDatum(remote_host)); CStringGetDatum(remote_host));
if (beentry->st_clienthostname) if (beentry->st_clienthostname &&
beentry->st_clienthostname[0])
values[12] = CStringGetTextDatum(beentry->st_clienthostname); values[12] = CStringGetTextDatum(beentry->st_clienthostname);
else else
nulls[12] = true; nulls[12] = true;

Loading…
Cancel
Save