*** a/src/interfaces/libpq/fe-connect.c
--- b/src/interfaces/libpq/fe-connect.c
***************
*** 5836,5854 **** PQhost(const PGconn *conn)
  {
  	if (!conn)
  		return NULL;
! 	if (conn->connhost != NULL &&
! 		conn->connhost[conn->whichhost].type != CHT_HOST_ADDRESS)
! 		return conn->connhost[conn->whichhost].host;
! 	else if (conn->pghost != NULL && conn->pghost[0] != '\0')
  		return conn->pghost;
! 	else
! 	{
! #ifdef HAVE_UNIX_SOCKETS
! 		return DEFAULT_PGSOCKET_DIR;
! #else
! 		return DefaultHost;
! #endif
! 	}
  }
  
  char *
--- 5836,5857 ----
  {
  	if (!conn)
  		return NULL;
! 
! 	/*
! 	 * We should try to avoid returning ip address. connhost[]->host stores IP
! 	 * address in the case of CHT_HOST_ADDRESS so try to use conn->pghost
! 	 * instead.
! 	 */
! 	if (conn->connhost == NULL ||
! 		(conn->connhost[conn->whichhost].type == CHT_HOST_ADDRESS &&
! 		 conn->pghost != NULL && conn->pghost[0] != '\0'))
  		return conn->pghost;
! 
! 	/*
! 	 * Otherwise we use this as host name even though it might be an IP
! 	 * address.
! 	 */
! 	return conn->connhost[conn->whichhost].host;
  }
  
  char *
