Oracle使用audit_trail參數(shù)控制審計是否啟用
成都創(chuàng)新互聯(lián)長期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為巴里坤哈薩克企業(yè)提供專業(yè)的成都網(wǎng)站制作、做網(wǎng)站,巴里坤哈薩克網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
audit_trail的參數(shù)有下面幾種:
NONE:不開啟審計
OS:說明審計信息放在系統(tǒng)匯總,如果是Linux那么由audit_file_dest決定,如果是Windows 那么由事件查看器決定
DB 或 TRUE :表示審計信息存放在數(shù)據(jù)庫里,也就是sys 用戶的aud$ 表。
audit_sys_operations參數(shù)的含義:
false:不審計sys用戶,默認不審計
true:審計sys用戶
審計范圍分為session 和 access兩種
session:表示用戶登錄之后執(zhí)行的相同SQL只記錄一次,其他相同SQL不再記錄;
access:表示每次執(zhí)行的SQL都進行審計記錄。
詳細參考官方文檔
http://docs.oracle.com/cd/B19306_01/network.102/b14266/cfgaudit.htm#CIHDICID
1、開啟審計參數(shù)
SQL> show parameter audit NAME TYPE VALUE ----------------------------------------------- ------------------------------ audit_file_dest string /u01/app/oracle/admin/mydb/adump audit_sys_operations boolean FALSE audit_syslog_level string audit_trail string NONE SQL> alter system setaudit_trail=db,extended scope=spfile;
2、重啟數(shù)據(jù)庫
靜態(tài)參數(shù),為了使參數(shù)生效,需要重啟數(shù)據(jù)庫
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 599785472 bytes Fixed Size 2085776 bytes Variable Size 192941168 bytes Database Buffers 398458880 bytes Redo Buffers 6299648 bytes Database mounted. Database opened. SQL> show parameter audit NAME TYPE VALUE ----------------------------------------------- ------------------------------ audit_file_dest string /u01/app/oracle/admin/mydb/adump audit_sys_operations boolean FALSE audit_syslog_level string audit_trail string DB, EXTENDED
3、設(shè)置對表進行審計
這樣每次有用戶對表進行操作,那么都會有相應(yīng)的記錄被添加到aud$中,而Oracle為了方便讀取數(shù)據(jù),創(chuàng)建了視圖。
雖然會記錄每個用戶對表的操作,但是不會記錄sys用戶的操作,其他所有用戶都會做記錄。
SQL> conn / as sysdba Connected. SQL> audit all on zx.num_t by accesswhenever successful; Audit succeeded. SQL> set linesize 200 SQL> select * from dba_obj_audit_opts; OWNER OBJECT_NAME OBJECT_TYPE ALT AUD COM DEL GRA IND INS LOC REN SEL UPD REF EXE CRE REA WRI FBK ------------------------------------------------------------ ----------------- ----- ----- ----- ----- ---------- ----- ----- ----- ----- ----- --- ----- ----- ----- ----- ----- ZX NUM_T TABLE A/- A/- A/- A/- A/- A/- A/- A/- A/- A/- A/- -/- -/- -/- -/- -/- A/-
前面列中
A表示access,每次被審計的操作都會記錄,比如開啟了scott.emp的select審計,那么任何人select這張表都會觸發(fā)一次審計,并且記錄在aud$中。
S表示session,每個會話被審計的操作都記錄一次。
使用不同用戶對zx.num_t表做不同訪問:
SQL> conn zx/zx Connected. SQL> select count(*) from zx.num_t; COUNT(*) ---------- 0 SQL> insert into zx.num_t (id1)values(1); 1 row created. SQL> commit; Commit complete. SQL> conn scott/tiger Connected. SQL> select count(*) from zx.num_t; COUNT(*) ---------- 1 SQL> delete from zx.num_t; 1 row deleted. SQL> commit; Commit complete. SQL> insert into zx.num_t (id2)values(2); 1 row created. SQL> rollback; Rollback complete.
4、查詢審計記錄
SQL> alter session setnls_date_format='yyyymmdd hh34:mi:ss'; Session altered. SQL> set lines 200 col OS_USERNAME for a10 col USERNAME for a11 col USERHOST for a10 col TERMINAL for a10 col TIMESTAMP for a20 col obj_name for a10 col OWNER for a10 col ACTION_NAME for a11 col TRANSACTIONID for a16 col sql_text for a50 SELECT USERNAME, USERHOST, TIMESTAMP, OWNER, OBJ_NAME, ACTION_NAME, SQL_TEXT FROM DBA_AUDIT_TRAIL WHERE OBJ_NAME='NUM_T' ORDER BY TIMESTAMP; USERNAME USERHOST TIMESTAMP OWNER OBJ_NAME ACTION_NAME SQL_TEXT ----------- ---------- ------------------------------ ---------- ------------------------------------------------------------- ZX rhel5 20161107 11:57:55 ZX NUM_T NOAUDIT OBJ noaudit all on num_t ECT ZX rhel5 20161107 12:00:07 ZX NUM_T SELECT select count(*) from zx.num_t ZX rhel5 20161107 12:00:21 ZX NUM_T INSERT insert into zx.num_t (id1) values(1) SCOTT rhel5 20161107 12:00:37 ZX NUM_T SELECT select count(*) from zx.num_t SCOTT rhel5 20161107 12:00:45 ZX NUM_T DELETE delete from zx.num_t SCOTT rhel5 20161107 12:01:27 ZX NUM_T INSERT insert into zx.num_t (id2) values(2) 6 rows selected.
5、取消審計
SQL> noaudit all on num_t; Noaudit succeeded.
6、清空aud$
這張系統(tǒng)表是可以使用TRUNCATE命令截斷的。把它刪掉之后那么視圖中的記錄也就相應(yīng)消失了。
SQL> truncate table aud$; SQL> SELECT * FROM DBA_FGA_AUDIT_TRAIL; no rows selected
更多詳細信息參考官方文檔
http://docs.oracle.com/cd/B19306_01/network.102/b14266/cfgaudit.htm#BABCFIHB