审计数据库登陆登出触发器

1.  登陆触发器

CREATE OR REPLACE TRIGGER DB_LOGON
AFTER LOGON ON DATABASE
BEGIN
  insert into user_logon values(sys_context('userenv','host'),
   sys_context('userenv','session_user'),
   sys_context('userenv','ip_address'),
   sys_context('userenv','os_user'),
   sys_context('userenv','bg_job_id'),
   sys_context('userenv','fg_job_id'),
   sysdate);
 commit;
exception
 when others then
 rollback;
END;
/
 
2.登出触发器
CREATE OR REPLACE TRIGGER DB_LOGOFF
BEFORE LOGOFF ON DATABASE
BEGIN
  insert into user_logoff values(sys_context('userenv','host'),
   sys_context('userenv','session_user'),
   sys_context('userenv','ip_address'),
   sys_context('userenv','os_user'),
   sys_context('userenv','bg_job_id'),
   sys_context('userenv','fg_job_id'),
   sysdate);
 commit;
exception
 when others then
 rollback;
 
END;
/
 
3.记录登陆用户表
create table user_logon(
hostname varchar2(100),
username varchar2(40),
ipaddress varchar2(30),
osuser varchar2(30),
bg_job_id varchar2(20),
fg_job_id varchar2(20),
time date);
 
4. 记录登出用户表
create table user_logoff(
hostname varchar2(100),
username varchar2(30),
ipaddress varchar2(30),
osuser varchar2(30),
bg_job_id varchar2(20),
fg_job_id varchar2(20),
time date);

col hostname for a30
col USERNAME for a10
col IPADDRESS for a15
col OSUSER for a10
col bg_job_id for a10
col fg_job_id for a10
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
select * from user_logon;

col hostname for a30
col USERNAME for a10
col IPADDRESS for a15
col OSUSER for a10
col bg_job_id for a10
col fg_job_id for a10
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
select * from user_logoff;

5. 建测试用的JOB
variable jobno number;
begin
 DBMS_JOB.SUBMIT(:jobno,'INSERT_T1;',to_date('2011-06-30 15:03:00','yyyy-mm-dd hh24:mi:ss'),'trunc(sysdate+1/1440,''MI'')');
 commit;
end;
/
 
create or replace procedure insert_t1
as
begin
 insert into t1 values(7369,'SMITH','CLERK',7902,to_date('1980-12-17 00:00:00','yyyy-mm-dd hh24:mi:ss'),800,0,20);
 commit;
end;
/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9252210/viewspace-701116/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9252210/viewspace-701116/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值