Automatically record the trigger of the machine and IP address of the database client login

zhaozj2021-02-16  95

Note that for DBA users are invalid

REM The following tables and triggers are used to record login information REM Create REM with SYS users if only on single tablespace is operated, and ON Schema trigger can be established.

Connect Sys

REM needs to be authorized based on basic tables (with SYS users with no need) GRANT SELECT ON V_ $ Session to USER /

drop table session_history / REM Session process history table REM records login information create table session_history (USERNAME varchar2 (20), SID number, AUDSID number, OSUSER varchar2 (30), ACTION varchar2 (100), LOGIN_TIME date, LOGOFF_TIME date, IP varchar2 (20), Terminal Varchar2 (30), Program varchar2 (100)) /

REM login information recording trigger CREATE OR REPLACE TRIGGER LOGON_HISTORY AFTER LOGON ON DATABASE --WHEN (USER = 'EQSP') --ONLY FOR USER 'EQSP' BEGIN insert into session_history select username, sid, AUDSID, OSUSER, ACTION, SYSDATE , NULL, SYS_CONTEXT ('useerenv', 'ip_address'), Terminal, Program from v $ session where audsid = @ernv ('sessionID'); end; /

REM exit time recording trigger CREATE OR REPLACE TRIGGER LOGOFF_HISTORY BEFORE LOGOFF ON DATABASE --WHEN (USER = 'EQSP') --ONLY FOR USER 'EQSP' BEGIN UPDATE SESSION_HISTORY SET LOGOFF_TIME = SYSDATE WHERE audsid = userenv ( 'sessionid') ; END; /

转载请注明原文地址:https://www.9cbs.com/read-11070.html

New Post(0)