]> granicus.if.org Git - postgresql/commitdiff
Fix bugs in manipulation of PgBackendStatus.st_clienthostname.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2014 01:30:18 +0000 (21:30 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2014 01:30:18 +0000 (21:30 -0400)
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.

src/backend/postmaster/pgstat.c
src/backend/utils/adt/pgstatfuncs.c

index 77e195e554d1beb1fdbe966c59228f762e5770a7..e1e60294ea0419fcde0c7c47a994b3ed0ba6f4cd 100644 (file)
@@ -2404,7 +2404,11 @@ pgstat_bestart(void)
        beentry->st_databaseid = MyDatabaseId;
        beentry->st_userid = userid;
        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_appname[0] = '\0';
        beentry->st_activity[0] = '\0';
@@ -2416,9 +2420,6 @@ pgstat_bestart(void)
        beentry->st_changecount++;
        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 */
        if (application_name)
                pgstat_report_appname(application_name);
index c75b9420264f5c03f2061f16ff7a23812f46e40a..e0ec08e4b47bfb3275b2ef364b15ce12a1f5e300 100644 (file)
@@ -694,7 +694,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
                                                clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
                                                values[9] = DirectFunctionCall1(inet_in,
                                                                                           CStringGetDatum(remote_host));
-                                               if (beentry->st_clienthostname)
+                                               if (beentry->st_clienthostname &&
+                                                       beentry->st_clienthostname[0])
                                                        values[10] = CStringGetTextDatum(beentry->st_clienthostname);
                                                else
                                                        nulls[10] = true;