查看oracle数据库对应session的IP地址等信息

1、以dba的身份登陆至系统,创建登陆触发器

create or replace trigger login_on_record_ip
after logon on database
begin   
dbms_application_info.set_client_info(sys_context('userenv', 'ip_address'));
end;
/

2、查询v$session视图信息

select username,sid,serial#,client_info,client_identifier from v$session 


3、查看锁表情况语句

SELECT ls.osuser os_user_name, --操作系统用户名
       ls.machine,       --主机名
       ls.client_info,   --ip地址
       ls.username user_name,
       DECODE(ls.TYPE,
              'RW',
              'Row wait enqueue lock',
              'TM',
              'DML enqueue lock',
              'TX',
              'Transaction enqueue lock',
              'UL',
              'User supplied lock') lock_type,
       o.object_name object,  --
       DECODE(ls.lmode, 1, NULL, 2, 'Row Share', 3, 'Row Exclusive', 4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive', NULL) lock_mode,
       o.owner,
       ls.sid,   --session_id 
       ls.serial# serial_num,
       ls.id1,  --数据库object_id
       ls.id2
  FROM sys.dba_objects o,
       (SELECT s.osuser, s.MACHINE, s.SADDR, s.username, s.CLIENT_INFO, l.TYPE, l.lmode, s.sid, s.serial#, l.id1, l.id2
          FROM v$session s, v$lock l
         WHERE s.sid = l.sid) ls
 WHERE o.object_id = ls.id1
   AND o.owner <> 'SYS'
 ORDER BY o.owner, o.object_name;


你可能感兴趣的:(oracle)