Oracle Database View User login information for client including IP

Source: Internet
Author: User

By creating a trigger to log user login, audit the logged-in user, record the login user, host, system users and IP address:

1. Create a table in SYS mode that records the details of the client's login to the database server.

 create table login_history    (     username    VARCHAR2,   --user name       machine     VARCHAR2,   --machine name       login_time date,           --Login Time       ip          VARCHAR2 (   --ip address     );  or  sql > create table LOGON_TABLE as       select  Sysdate logon_time,           sys_context (' USERENV ', ' session_user ')  username,            sys_ Context (' USERENV ', ' HOST ')  host,             Sys_context (' USERENV ', ' Os_user')  os_user,            sys_context (' USERENV ', ' IP_Address ')  ip_address      from dual    /table  created.

2. Create a trigger in SYS mode.

Create or replace trigger login_log     after logon on  database   begin     insert into login_history        select username, machine, sysdate, sys_context (' Userenv ',  ' ip_address ')          from v$session         where audsid = userenv (' SessionID ');      commit;   end;    or  SQL> create or  replace trigger tri_logon after logon on database      begin         insert into logon_table                     ( logon_ Time,    &nbsP;                username,                       host,                      os_user,                      ip_address                    )               values                     ( sysdate,                     sys_context (' USERENV ',  ' session_user '),                     sys_context (' USERENV ', ' HOST '),                     sys_context (' USERENV ', ' os_user '),                     sys_ Context (' USERENV ', ' ip_address '));     end;    /trigger created.

3. Some instances of viewing session count (log in with SYS user)

--View login_history Table select * from Login_history;    --View all current session Count Select COUNT (*) from v$session;    --View the current client computer with all sessions named Rhel select COUNT (*) from v$session where machine = ' RHEL '; --View the current number of connections for each client computer select COUNT (*), machine from V$session Group by machine;

4. View the IP of the current session

Select Sys_context (' Userenv ', ' ip_address ') from dual;


This article is from the "Night" blog, please be sure to keep this source http://liuqun.blog.51cto.com/3544993/1984200

Oracle Database View User login information for client including IP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.