前景
為了數據安全,生產環境開數據庫審計的話會有很大的消耗,一般不建議開啟。于是根據dba_hist_active_sess_history寫了個shell 腳本,每天產生一個簡單的審計報告。
審計腳本:audit_db.sh
#!/bin/sh
export ORACLE_SID=two
export ORACLE_UNQNAME=two
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/11.2.0.3/product
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export con_user='sqlplus -s / as dba'
export au_dir='/u01/report/audit_db'
audit_date=`date +%Y-%m-%d -d "1 day ago"`
if [ ! -d ${au_dir}/${audit_date} ];then
mkdir -p ${au_dir}/${audit_date}
fi
result=`$con_user <<EOF
set colsep',';
set echo off;
set feedback off;
set heading off;
set pagesize 0;
set linesize 1000;
set numwidth 12;
set termout off;
set timing off;
set trimout on;
set trimspool on;
set trims on;
col username format a15
col machine format a30
col program format a50
col sql_opname format a20
spool ${au_dir}/${audit_date}/${audit_date}.txt
select to_char(h.sample_time, 'yyyy-mm-dd hh24:mi:ss') exec_time,
u.username,
h.machine,
h.program,
h.sql_opname
from sys.dba_hist_active_sess_history h
left join sys.all_users u
on u.user_id = h.user_id
where h.module is not null
and h.sql_opname is not null
and to_char(h.sample_time, 'yyyy-mm-dd') = '$audit_date';
spool off
EOF`
result_report=`$con_user <<EOF
set colsep',';
set echo off;
set feedback off;
set heading off;
set pagesize 0;
set linesize 800;
set numwidth 12;
set termout off;
set timing off;
set trimout on;
set trimspool on;
set trims on;
col username format a15
col machine format a30
col program format a50
col sql_opname format a20
spool ${au_dir}/${audit_date}/${audit_date}.report
select u.username, h.machine, h.program, h.sql_opname, count(*)
from sys.dba_hist_active_sess_history h
left join sys.all_users u
on u.user_id = h.user_id
where h.module is not null
and h.sql_opname is not null
and to_char(h.sample_time, 'yyyy-mm-dd') = '$audit_date'
group by username, machine, program, h.sql_opname
order by 5 desc;
spool off
EOF`
輸出日志:
[oracle@localhost 2022-08-02]$ cat 2022-08-02.report 業務用戶 主機名 連接方式 操作類型 操作次數 two ,app.tomcat.com ,JDBC Thin Client ,SELECT, 8610 two ,app1.tomcat.com ,JDBC Thin Client ,INSERT, 8610
?????????????????????????文章推薦
| PostgreSQL | URL |
|---|---|
| 《課程筆記:PostgreSQL深入淺出》之 初識PostgreSQL(一) | http://www.sunline.cc/db/475817 |
| 《課程筆記:PostgreSQL深入淺出》之 PostgreSQL源碼安裝(二) | http://www.sunline.cc/db/475933 |
| 《課程筆記:PostgreSQL深入淺出》之初始化PostgreSQL(三) | http://www.sunline.cc/db/479524 |
| 《課程筆記:PostgreSQL深入淺出》之PSQL管理工具-常用(四) | http://www.sunline.cc/db/479560 |
| 《課程筆記:PostgreSQL深入淺出》之PSQL管理工具-高級命令(四) | http://www.sunline.cc/db/479559 |
| 《課程筆記:PostgreSQL深入淺出》之內存與進程(五) | http://www.sunline.cc/db/489936 |
| 《課程筆記:PostgreSQL深入淺出》之外存&永久存儲(六) | http://www.sunline.cc/db/502267 |
| Oracle: | URL |
| 《Oracle 自動收集統計信息機制》 | http://www.sunline.cc/db/403670 |
| 《Oracle_索引重建—優化索引碎片》 | http://www.sunline.cc/db/399543 |
| 《DBA_TAB_MODIFICATIONS表的刷新策略測試》 | http://www.sunline.cc/db/414692 |
| 《FY_Recover_Data.dbf》 | http://www.sunline.cc/doc/74682 |
| 《Oracle RAC 集群遷移文件操作.pdf》 | http://www.sunline.cc/doc/72985 |
| 《Oracle Date 字段索引使用測試.dbf》 | http://www.sunline.cc/doc/72521 |
| 《Oracle 診斷案例 :因應用死循環導致的CPU過高》 | http://www.sunline.cc/db/483047 |
| 《Oracle 慢SQL監控腳本》 | http://www.sunline.cc/db/479620 |
| 《Oracle 慢SQL監控測試及監控腳本.pdf》 | http://www.sunline.cc/doc/76068 |
| 《Oracle 腳本實現簡單的審計功能》 | http://www.sunline.cc/db/450052 |
| 《記錄一起索引rebuild與收集統計信息的事故》 | http://www.sunline.cc/db/408934 |
| Greenplum: | URL |
| 《PL/Java.pdf》 | http://www.sunline.cc/doc/70867 |
| 《GP的資源隊列.pdf》 | http://www.sunline.cc/doc/67644 |
| 《Greenplum psql客戶端免交互執行SQL.pdf》 | http://www.sunline.cc/doc/69806 |
最后修改時間:2022-09-27 21:32:53
「喜歡這篇文章,您的關注和贊賞是給作者最好的鼓勵」
關注作者
【版權聲明】本文為墨天輪用戶原創內容,轉載時必須標注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權追究責任。如果您發現墨天輪中有涉嫌抄襲或者侵權的內容,歡迎發送郵件至:contact@modb.pro進行舉報,并提供相關證據,一經查實,墨天輪將立刻刪除相關內容。




