重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
sqlplus "/ as sysdba"
創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,包括網(wǎng)站建設(shè)、成都做網(wǎng)站、SEO優(yōu)化、網(wǎng)絡(luò)推廣、整站優(yōu)化營銷策劃推廣、電子商務(wù)、移動互聯(lián)網(wǎng)營銷等。創(chuàng)新互聯(lián)為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制及解決方案,創(chuàng)新互聯(lián)核心團(tuán)隊十余年專注互聯(lián)網(wǎng)開發(fā),積累了豐富的網(wǎng)站經(jīng)驗,為廣大企業(yè)客戶提供一站式企業(yè)網(wǎng)站建設(shè)服務(wù),在網(wǎng)站建設(shè)行業(yè)內(nèi)樹立了良好口碑。
show parameter audit
alter system set audit_sys_operations=TRUE scope=spfile;
alter system set audit_trail=DB scope=spfile;
shutdown immediate;
startup force;
Oracle 11g起audit是自動開啟的。我很煩這個審計開啟,審計日志半個月10G,煩煩煩。我一把都關(guān)閉Oracle的審計功能,提高Oracle的空閑率。
1 、如何啟用審計?
修改數(shù)據(jù)庫的初始化參數(shù)audit_trail ,從none 修改為你需要的值。
它的可選項有很多,如下所示:
AUDIT_TRAIL = { none | os | db | db,extended | xml | xml,extended }
我們選擇db 值作為該參數(shù)值。使得審計功能處于打開狀態(tài),將審計記錄保存在數(shù)據(jù)庫sys.aud$表中。
修改初始化參數(shù)文件spfile 中的此參數(shù)配置值
ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE sid='*';
注意,這個參數(shù)需要數(shù)據(jù)庫實例重啟之后才能生效。
2 、審計有哪些功能
可以審計數(shù)據(jù)庫對象的DML 和DDL 操作,以及查詢、執(zhí)行和一些系統(tǒng)事件如登錄和退出。
如下所示:
DDL (CREATE, ALTER DROP of objects)
DML (INSERT UPDATE, DELETE)
SELECT
EXECUTE
SYSTEM EVENTS (LOGON, LOGOFF etc)
每個功能還有選項,如在每個會話還是每個訪問中審計,是成功或不成功時審計。
完整的audit 的語法如下:
AUDIT
{ sql_statement_clause | schema_object_clause | NETWORK }
[ BY { SESSION | ACCESS } ]
[ WHENEVER [ NOT ] SUCCESSFUL ] ;
3 、如何審計某表的數(shù)據(jù)插入操作
現(xiàn)在的問題是找出什么應(yīng)用向表插入了記錄。在應(yīng)用程序的邏輯上,這個表的數(shù)據(jù)只會更新,不會插入。
因此,在審計功能打開后,使用這個下列命令審計某表的插入操作。
audit insert on table_name by access;
執(zhí)行成功后,此表上每一次插入操作都會被記錄在sys.aud$ 表中。
4 、如何查看審計結(jié)果
可以查詢dba_audit_trail 系統(tǒng)視圖,該視圖顯示就是sys.aud$ 表保存的審計結(jié)果。這個表的存儲空間是system ,如果你需要大量長期審計某些操作,請注意維護(hù)這張表。
一般維護(hù)方法有兩個,定期執(zhí)行truncate 操作和將表的存儲表空間移植到一個新建的獨立表空間上。
5 、如何取消審計
使用noaudit 代替audit 命令符就可, 如noaudit insert on table_name by access;
在oracle11g中,數(shù)據(jù)庫的審計功能是默認(rèn)開啟的(這和oracle10g的不一樣,10g默認(rèn)是關(guān)閉的),
oracle11gr2的官方文檔上寫的是錯的,當(dāng)上說default是none,而且是審計到db級別的,這樣就會
往aud$表里記錄統(tǒng)計信息。
1.如果審計不是必須的,可以關(guān)掉審計功能;
sql
show
parameter
audit_trail;
name
type
value
------------------------------------
-----------
------------------------------
audit_trail
string
db
sql
alter
system
set
audit_trail=none
scope=spfile;
sql
shut
immediate;
sqlstartup
2.刪除已有的審計信息
可以直接truncate表aud$,
truncate
table
sys.aud$;
3.或者將aud$表移到另外一個表空間下,以減少system表空間的壓力和被撐爆的風(fēng)險。
附:11g中有關(guān)audit_trail參數(shù)的設(shè)置說明:
audit_trail
property
description
parameter
type
string
syntax
audit_trail
=
{
none
|
os
|
db
[,
extended]
|
xml
[,
extended]
}
default
value
none
modifiable
no
basic
no
audit_trail
enables
or
disables
database
auditing.
values:
none
disables
standard
auditing.
this
value
is
the
default
if
the
audit_trail
parameter
was
not
set
in
the
initialization
parameter
file
or
if
you
created
the
database
using
a
method
other
than
database
configuration
assistant.
if
you
created
the
database
using
database
configuration
assistant,
then
the
default
is
db.
os
directs
all
audit
records
to
an
operating
system
file.
oracle
recommends
that
you
use
the
os
setting,
particularly
if
you
are
using
an
ultra-secure
database
configuration.
db
directs
audit
records
to
the
database
audit
trail
(the
sys.aud$
table),
except
for
records
that
are
always
written
to
the
operating
system
audit
trail.
use
this
setting
for
a
general
database
for
manageability.
if
the
database
was
started
in
read-only
mode
with
audit_trail
set
to
db,
then
oracle
database
internally
sets
audit_trail
to
os.
check
the
alert
log
for
details.
db,
extended
performs
all
actions
of
audit_trail=db,
and
also
populates
the
sql
bind
and
sql
text
clob-type
columns
of
the
sys.aud$
table,
when
available.
these
two
columns
are
populated
only
when
this
parameter
is
specified.
if
the
database
was
started
in
read-only
mode
with
audit_trail
set
to
db,
extended,
then
oracle
database
internally
sets
audit_trail
to
os.
check
the
alert
log
for
details.
xml
writes
to
the
operating
system
audit
record
file
in
xml
format.
records
all
elements
of
the
auditrecord
node
except
sql_text
and
sql_bind
to
the
operating
system
xml
audit
file.
xml,
extended
performs
all
actions
of
audit_trail=xml,
and
populates
the
sql
bind
and
sql
text
clob-type
columns
of
the
sys.aud$
table,
wherever
possible.
these
columns
are
populated
only
when
this
parameter
is
specified.
you
can
use
the
sql
audit
statement
to
set
auditing
options
regardless
of
the
setting
of
this
parameter.
1、什么是審計
審計(Audit)用于監(jiān)視用戶所執(zhí)行的數(shù)據(jù)庫操作,并且Oracle會將審計跟蹤結(jié)果存放到OS文件(默認(rèn)位置為$ ORACLE_BASE/admin/$ORACLE_SID/adump/)或數(shù)據(jù)庫(存儲在system表空間中的SYS.AUD$表中,可通過視圖 dba_audit_trail查看)中。默認(rèn)情況下審計是沒有開啟的。
不管你是否打開數(shù)據(jù)庫的審計功能,以下這些操作系統(tǒng)會強制記錄:用管理員權(quán)限連接Instance;啟動數(shù)據(jù)庫;關(guān)閉數(shù)據(jù)庫。
2、和審計相關(guān)的兩個主要參數(shù)
Audit_sys_operations:
默認(rèn)為false,當(dāng)設(shè)置為true時,所有sys用戶(包括以sysdba,sysoper身份登錄的用戶)的操作都會被記錄,audit trail不會寫在aud$表中,這個很好理解,如果數(shù)據(jù)庫還未啟動aud$不可用,那么像conn /as sysdba這樣的連接信息,只能記錄在其它地方。如果是windows平臺,audti trail會記錄在windows的事件管理中,如果是linux/unix平臺則會記錄在audit_file_dest參數(shù)指定的文件中。
Audit_trail:
None:是默認(rèn)值,不做審計;
DB:將audit trail 記錄在數(shù)據(jù)庫的審計相關(guān)表中,如aud$,審計的結(jié)果只有連接信息;
DB,Extended:這樣審計結(jié)果里面除了連接信息還包含了當(dāng)時執(zhí)行的具體語句;
OS:將audit trail 記錄在操作系統(tǒng)文件中,文件名由audit_file_dest參數(shù)指定;
XML:10g里新增的。
注:這兩個參數(shù)是static參數(shù),需要重新啟動數(shù)據(jù)庫才能生效。
3、審計級別
當(dāng)開啟審計功能后,可在三個級別對數(shù)據(jù)庫進(jìn)行審計:Statement(語句)、Privilege(權(quán)限)、object(對象)。
Statement:
按語句來審計,比如audit table 會審計數(shù)據(jù)庫中所有的create table,drop table,truncate table語句,alter session by cmy會審計cmy用戶所有的數(shù)據(jù)庫連接。
Privilege:
按權(quán)限來審計,當(dāng)用戶使用了該權(quán)限則被審計,如執(zhí)行g(shù)rant select any table to a,當(dāng)執(zhí)行了audit select any table語句后,當(dāng)用戶a 訪問了用戶b的表時(如select * from b.t)會用到select any table權(quán)限,故會被審計。注意用戶是自己表的所有者,所以用戶訪問自己的表不會被審計。
Object:
按對象審計,只審計on關(guān)鍵字指定對象的相關(guān)操作,如aduit alter,delete,drop,insert on cmy.t by scott; 這里會對cmy用戶的t表進(jìn)行審計,但同時使用了by子句,所以只會對scott用戶發(fā)起的操作進(jìn)行審計。注意Oracle沒有提供對schema中所有對象的審計功能,只能一個一個對象審計,對于后面創(chuàng)建的對象,Oracle則提供on default子句來實現(xiàn)自動審計,比如執(zhí)行audit drop on default by access;后,對于隨后創(chuàng)建的對象的drop操作都會審計。但這個default會對之后創(chuàng)建的所有數(shù)據(jù)庫對象有效,似乎沒辦法指定只對某個用戶創(chuàng)建的對象有效,想比 trigger可以對schema的DDL進(jìn)行“審計”,這個功能稍顯不足。
在oracle11g中,數(shù)據(jù)庫的審計功能是默認(rèn)開啟的(這和oracle10g的不一樣,10g默認(rèn)是關(guān)閉的),\x0d\x0aoracle11gR2的官方文檔上寫的是錯的,當(dāng)上說default是none,而且是審計到DB級別的,這樣就會\x0d\x0a往aud$表里記錄統(tǒng)計信息。\x0d\x0a \x0d\x0a1.如果審計不是必須的,可以關(guān)掉審計功能;\x0d\x0a\x0d\x0aSQL show parameter audit_trail;\x0d\x0a\x0d\x0aNAME TYPE VALUE\x0d\x0a------------------------------------ ----------- ------------------------------\x0d\x0aaudit_trail string DB\x0d\x0a\x0d\x0aSQL alter system set audit_trail=none scope=spfile;\x0d\x0aSQL shut immediate;\x0d\x0aSQLstartup\x0d\x0a2.刪除已有的審計信息\x0d\x0a可以直接truncate表aud$,\x0d\x0atruncate table SYS.AUD$;\x0d\x0a\x0d\x0a3.或者將aud$表移到另外一個表空間下,以減少system表空間的壓力和被撐爆的風(fēng)險。\x0d\x0a \x0d\x0a附:11g中有關(guān)audit_trail參數(shù)的設(shè)置說明:\x0d\x0aAUDIT_TRAIL\x0d\x0aProperty Description\x0d\x0aParameter type String\x0d\x0aSyntaxAUDIT_TRAIL = { none | os | db [, extended] | xml [, extended] }\x0d\x0aDefault valuenone\x0d\x0aModifiable No\x0d\x0aBasic No\x0d\x0aAUDIT_TRAIL enables or disables database auditing.\x0d\x0aValues:\x0d\x0anone\x0d\x0aDisables standard auditing. This value is the default if the AUDIT_TRAIL parameter was not set \x0d\x0ain the initialization parameter file or if you created the database using a method other than \x0d\x0aDatabase Configuration Assistant. If you created the database using Database Configuration \x0d\x0aAssistant, then the default is db.\x0d\x0aos\x0d\x0aDirects all audit records to an operating system file. Oracle recommends that you use the os \x0d\x0asetting, particularly if you are using an ultra-secure database configuration.\x0d\x0adb\x0d\x0aDirects audit records to the database audit trail (the SYS.AUD$ table), except for records \x0d\x0athat are always written to the operating system audit trail. Use this setting for a general \x0d\x0adatabase for manageability.\x0d\x0aIf the database was started in read-only mode with AUDIT_TRAIL set to db, then Oracle Database \x0d\x0ainternally sets AUDIT_TRAIL to os. Check the alert log for details.\x0d\x0adb, extended\x0d\x0aPerforms all actions of AUDIT_TRAIL=db, and also populates the SQL bind and SQL text CLOB-type \x0d\x0acolumns of the SYS.AUD$ table, when available. These two columns are populated only when this \x0d\x0aparameter is specified.\x0d\x0aIf the database was started in read-only mode with AUDIT_TRAIL set to db, extended, then Oracle \x0d\x0aDatabase internally sets AUDIT_TRAIL to os. Check the alert log for details.\x0d\x0axml\x0d\x0aWrites to the operating system audit record file in XML format. Records all elements of the \x0d\x0aAuditRecord node except Sql_Text and Sql_Bind to the operating system XML audit file.\x0d\x0axml, extended\x0d\x0aPerforms all actions of AUDIT_TRAIL=xml, and populates the SQL bind and SQL text CLOB-type columns\x0d\x0a of the SYS.AUD$ table, wherever possible. These columns are populated only when this parameter \x0d\x0ais specified.\x0d\x0aYou can use the SQL AUDIT statement to set auditing options regardless of the setting of this \x0d\x0aparameter.