我需要获取有关连接到我的DB2的用户的信息。如何获得(如果可以)计算机名称/登录或该用户的IP?我可以获得host_name
,current user
并登录DB2,但我想要更具体的信息,如IP或计算机名称。
我怎么能这样做?
答案 0 :(得分:2)
您可以从MON_GET_CONNECTION表函数中获取该信息。
表函数在最后的版本中发生了很大的变化,所以它取决于你的DB2版本你可以得到什么值。
SELECT application_handle,
CLIENT_USERID,
CLIENT_WRKSTNNAME,
CLIENT_HOSTNAME,
CLIENT_IPADDR
FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t
ORDER BY rows_returned DESC;
例如,CLIENT_HOSTNAME和CLIENT_IPADDR在v9.7
中不起作用http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0053938.html
答案 1 :(得分:1)
您可以使用MetaData获取一些有用的数据。 例如,以下代码:
ResultSet rS = dataSource.getConnection().getMetaData().getClientInfoProperties();
while(rS.next()){
System.out.println("**************************************************");
System.out.println("NAME: <" + rS.getString(1) + ">");
System.out.println("MAX_LEN: <" + rS.getInt(2) + ">");
System.out.println("DEFAULT_VALUE: <" + rS.getString(3) + ">");
System.out.println("DESCRIPTION: <" + rS.getString(4) + ">");
}
System.out.println("**************************************************");
应该给你一些接近这个的东西:
************************************************** NAME: ApplicationName MAX_LEN: 255 DEFAULT_VALUE: DESCRIPTION: The name of the application currently utilizing the connection. This is stored in DB2 special register CURRENT CLIENT_WRKSTNNAM. ************************************************** NAME: ClientAccountingInformation MAX_LEN: 255 DEFAULT_VALUE: DESCRIPTION: The value of the accounting string from the client information that is specified for the connection. This is stored in DB2 special register CURRENT CLINT_ACTNG ************************************************** NAME: ClientHostname MAX_LEN: 255 DEFAULT_VALUE: ADMIN-9XYZK DESCRIPTION: The hostname of the computer the application using the connection is running on. This is stored in DB2 special register CURRENT CLINT_WRKSTNNAM ************************************************** NAME: ClientUser MAX_LEN: 255 DEFAULT_VALUE: DESCRIPTION: The name of the user that the application using the connection is performing work for. This is stored in DB2 special register CURRENT CLINT_USRID. **************************************************
DB_MEMBERS表函数返回有关DB2实例的基本成员信息。
db2SelectStatement = "select * from table(SYSPROC.DB_MEMBERS()) as members";
这将输出如下内容:
MEMBER_NUMBER ----------- -------------- HOST_NAME ------ PARTITION_NUMBER MEMBER_TYPE
0 ------------------------- member1.mycompany.com ---------------- 0 -------------------------- d
1 ------------------------- member2.mycompany.com ---------------- 0-- ------------------------ç
7 ------------------------- member3.mycompany.com ---------------- 0-- ------------------------ D
您可以选择以下列:
我在DB 10上测试了它并且它正在工作,但是我没有在DB 9上测试它
答案 2 :(得分:0)
db2
select AGENT_ID as AGENT,
substr(APPL_NAME, 1, 30) as APP_NAME,
substr(APPL_ID, 1, 40)as APP_IP_ADD,
substr(CLIENT_NNAME, 1, 40)as CLIENT
from sysibmadm.snapappl_info order by CLIENT_NNAME
输出
AGENT APP_NAME APP_IP_ADD CLIENT
-------------------- ------------------------------ -------------------------------------- ----------------------------------------
.....................................................................................................................................
已选择341条记录。