zoukankan      html  css  js  c++  java
  • EBS_DBA_问题:跟踪登陆db的用户

    用sys用户登陆db

    1.创建表:

    CREATE TABLE LOG$INFORMATION
    (
       ID        NUMBER(10),
       USERNAME VARCHAR2(30),
       LOGINTIME DATE,
       TERMINAL VARCHAR2(50),
       IPADRESS VARCHAR2(20),
       OSUSER    VARCHAR2(30),
       MACHINE   VARCHAR2(64),
       PROGRAM   VARCHAR2(64),
       SID       NUMBER,
       SERIAL#   NUMBER,
       AUSID     NUMBER
    );

    2.创建序列:

    CREATE SEQUENCE LOGIN_SEQ
    minvalue 1
    maxvalue 9999999999
    start with 1
    increment by 1
    cache 20;

    3.创建触发器:

    CREATE OR REPLACE TRIGGER LOGIN_RECORD_TR
    AFTER logon ON DATABASE
    DECLARE
    mtSession v$session%ROWTYPE;
    CURSOR cSession(iiQuerySid IN NUMBER) IS
        SELECT * FROM v$session
           WHERE audsid = iiQuerySid;
    BEGIN
    OPEN cSession(userenv('SESSIONID'));
       FETCH cSession INTO mtSession;
          IF cSession%FOUND AND SYS_CONTEXT ('USERENV','IP_ADDRESS') IS NOT NULL THEN
             INSERT INTO log$information(
                id,
                username,
                logintime,
                terminal,
                ipadress,
                osuser,
                machine,
                program,
                sid,
                serial#,
                ausid
             ) VALUES(
                login_seq.nextval,
                USER,
                SYSDATE,
                mtSession.Terminal,
                SYS_CONTEXT ('USERENV','IP_ADDRESS'),
                mtSession.Osuser,
                mtSession.Machine,
                mtSession.Program,
                mtSession.Sid,
                mtSession.Serial#,
                userenv('SESSIONID')
             );
          END IF;
       CLOSE cSession;
    EXCEPTION
       WHEN OTHERS THEN
         RAISE;
    END;

    4.查询:

    Select * from sys.LOG$INFORMATION
    Where USERNAME = 'PDM';

    5.查询sql

    SELECT lk.session_id sid,
          se.serial#,
           lpad(' ', decode(lk.xidusn, 0, 3, 0)) || lk.oracle_username User_name,
            lk.locked_mode,
          lk.oracle_username,
          se.user#,
          lk.os_user_name,
          se.machine,
          se.terminal,
          a.sql_text,
          a.action
    FROM v$sqlarea a, v$session se, v$locked_object lk
    WHERE lk.session_id = se.sid
     AND se.prev_sql_addr = a.address
      and sid= &sid      --利用sid找到相应的sql
    ORDER BY sid, se.serial#;

  • 相关阅读:
    [C++再学习系列] 深入new/delete:Operator new的全局重载
    [C++再学习系列] 函数模板和类模板
    [C++再学习系列] 模板函数的自定义点
    [C++再学习系列] STL容器删除操作总结
    How to create a sizelimited filesystem
    CodeSmith 破解和注册
    LINQ to SQL学习的几个问题
    SQLSERVER2005 分区表
    google工具栏和搜狗拼音叠加问题
    C#中构成函数重载有哪些条件和特征?
  • 原文地址:https://www.cnblogs.com/hopedba/p/5895106.html
Copyright © 2011-2022 走看看