Hi,

$SUBJECT says it all, patch attached.

Comments?


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
>From 70aca1efa36395fba2bc0c2e3c6c935142ae3713 Mon Sep 17 00:00:00 2001
From: Guillaume Lelarge <guilla...@lelarge.info>
Date: Sat, 12 Mar 2011 21:22:31 +0100
Subject: [PATCH] Use client_hostname field of pg_stat_activity

---
 pgadmin/frm/frmStatus.cpp   |    6 ++++--
 pgadmin/schema/pgServer.cpp |   13 ++++++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/pgadmin/frm/frmStatus.cpp b/pgadmin/frm/frmStatus.cpp
index b9fb883..7c8e31c 100644
--- a/pgadmin/frm/frmStatus.cpp
+++ b/pgadmin/frm/frmStatus.cpp
@@ -1262,8 +1262,10 @@ void frmStatus::OnRefreshStatusTimer(wxTimerEvent &event)
 	q += wxT("datname, usename");
 	if (connection->BackendMinimumVersion(8, 1))
 	{
-		q += wxT(",\nCASE WHEN client_port=-1 THEN 'local pipe' ")
-		     wxT("     ELSE textin(inet_out(client_addr))||':'||client_port END AS client, ")
+		q += wxT(",\nCASE WHEN client_port=-1 THEN 'local pipe' ");
+	    if (connection->BackendMinimumVersion(8, 1))
+		     q += wxT("        WHEN client_hostname IS NOT NULL THEN client_hostname||':'||client_port ");
+		q += wxT("     ELSE textin(inet_out(client_addr))||':'||client_port END AS client, ")
 		     wxT("backend_start");
 	}
 	if (connection->BackendMinimumVersion(7, 4))
diff --git a/pgadmin/schema/pgServer.cpp b/pgadmin/schema/pgServer.cpp
index 4facef8..ef2b208 100644
--- a/pgadmin/schema/pgServer.cpp
+++ b/pgadmin/schema/pgServer.cpp
@@ -1097,11 +1097,14 @@ void pgServer::ShowStatistics(frmMain *form, ctlListView *statistics)
 		}
 		statistics->AddColumn(_("Current Query"), 300);
 
-		sql = wxT("SELECT procpid, usename, datname, backend_start, client_addr, client_port, current_query FROM pg_stat_activity\n");
+		sql = wxT("SELECT procpid, usename, datname, backend_start, client_addr, ");
+		if (GetConnection()->BackendMinimumVersion(9, 1))
+            sql += wxT("client_hostname, ");
+        sql += wxT("client_port, current_query FROM pg_stat_activity\n");
 		if (GetConnection()->BackendMinimumVersion(9, 1))
 		{
 			sql += wxT("UNION\n")
-			       wxT("SELECT procpid, usename, '' AS datname, backend_start, client_addr, client_port, ")
+			       wxT("SELECT procpid, usename, '' AS datname, backend_start, client_addr, client_hostname, client_port, ")
 			       + replication_query + wxT(" AS current_query FROM pg_stat_replication");
 		}
 
@@ -1118,7 +1121,11 @@ void pgServer::ShowStatistics(frmMain *form, ctlListView *statistics)
 				if (GetConnection()->BackendMinimumVersion(8, 1))
 				{
 					statistics->SetItem(pos, colpos++, stats->GetVal(wxT("backend_start")));
-					wxString client = stats->GetVal(wxT("client_addr")) + wxT(":") + stats->GetVal(wxT("client_port"));
+					wxString client;
+				    if (GetConnection()->BackendMinimumVersion(9, 1) && !stats->GetVal(wxT("client_hostname")).IsEmpty())
+                        client = stats->GetVal(wxT("client_hostname")) + wxT(":") + stats->GetVal(wxT("client_port"));
+                    else
+                        client = stats->GetVal(wxT("client_addr")) + wxT(":") + stats->GetVal(wxT("client_port"));
 					if (client == wxT(":-1"))
 						client = _("local pipe");
 					statistics->SetItem(pos, colpos++, client);
-- 
1.7.1

-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to