首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Oracle记录登录用户IP(触发器)

Oracle记录登录用户IP(触发器)

作者头像
Lucifer三思而后行
发布2021-08-17 15:32:14
发布2021-08-17 15:32:14
1.5K0
举报
代码语言:javascript
复制
--创建单独表空间存放记录
create tablespace setb;

--通过ctas从v$session创建session历史记录表指定表空间setb
create table session_history tablespace setb as (select sid,username,program,machine,'000.000.000.000'ipadd,sysdate moditime from v$session where 0=1);

--创建触发器,当有用户登录时,将记录插入session历史记录表
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;
/

--查询非SYS用户的登录记录
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
select * from  session_history q where q.username not in ('SYS');

参考自oracle 添加登陆数据库触发器--记录IP 地址

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/04/15 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档