oracle 添加登錄數據庫觸發器--記錄IP 地址

----觸發器--- ---建立中間插入的表數據庫

create table session_history tablespace bap_data as (select sid,username,program,machine,'000.000.000.000'ipadd,sysdate moditime from v$session where 0=1);session

---建立觸發器---只要登錄數據庫就觸發app

create or replace trigger on_logon_trigger  after logon on database  begin insert into session_history select sid,username,program,machine,sys_context('userenv','ip_address'),sysdate from v$session where audsid = userenv('sessionid'); end;ide

---查詢登錄信息spa

select * from  session_history q where q.username not in ('SYS')ip

------------直接在數據庫SYS用戶層面修改----(實際操做是步驟3)it

-- 1. 利用trigerio

begin    table

dbms_application_info.set_client_info(sys_context( 'userenv', 'ip_address' ) );cli

end;

2. 利用 DBMS_SESSION 過程包.

BEGIN

DBMS_SESSION.set_identifier(SYS_CONTEXT('USERENV', 'IP_ADDRESS'));

END;

3.咱們能夠經過觸發器

create or replace trigger on_logon_trigger

after logon on database

begin    

dbms_application_info.set_client_info(sys_context( 'userenv', 'ip_address' ) );

end;

/

4.驗證 這樣當客戶端登錄後,在v$session的client_info列會記錄其相應的IP信息。

這裏才查詢v$session ,你會發現 v$session 多了一列 記錄客戶端的IP.

select client_info from v$session;

select count(client_info) from v$session;

 set pagesize 1000 line 1000 select a.description,a.trigger_body from dba_triggers a where a.owner='SYS' AND A.status='ENABLED';

select count(1) from dba_triggers a where a.owner='SYS' AND A.status='ENABLED';

select client_info from v$session where client_info is not  null ;

 

----11G 直接添加就行;12C 須要給 CDB 和每一個PDB 單獨添加

相關文章
相關標籤/搜索