2 实现方法
2.1 修改初始化参数AUDIT_TRAIL。
Alter system set audit_trail=DB scope=spfile;
或者手工修改数据库初始化文件。
1.1 AUDIT_TRAIL
Parameter type String
Syntax AUDIT_TRAIL = {NONE | FALSE | DB | TRUE | OS}
Default value There is no default value.
Parameter class Static
AUDIT_TRAIL enables or disables the automatic writing of rows to the audit trail.
Values:
? NONE or FALSE
Audit records are not written.
? OS
Enables system-wide auditing and causes audited records to be written to the operating system's audit trail.
? DB or TRUE
Enables system-wide auditing and causes audited records to be written to the database audit trail (the SYS.AUD$ table).
2.2 检查是否存在sys.aud$表
Select * from sys.aud$;
如果不存在,需要使用Oracle系统提供的脚本cataaud.sql创建。
2.3 重启数据库,使修改参数生效
Shutdown immediate;
Startup open;
Show parameter audit_trail;
SQL> connect / as sysdba
已连接。
SQL> show parameter audit_trail
NAME TYPE VALUE
------------------------------------ ----------- -----------------------------
audit_trail string DB_EXTENDED
SQL>
2.4 检查审计相关视图,确认是否存在审计项目。
Select * from dba_stmt_audit_opts;
Select * from dba_priv_audit_opts;
Select * from dba_obj_audit_opts;
如果上述结果为空,则表示数据库中无任何要审计的内容。
2.5 AUDIT审计功能使用。
Audit select on scott.emp
审计scott模式中emp表,所有这个查询这个表的操作都被对象审计功能记录在sys.aud$表中。
Audit使用语法如下:
AUDIT
{ sql_statement_clause | schema_object_clause | NETWORK }
[ BY { SESSION | ACCESS } ]
[ WHENEVER [ NOT ] SUCCESSFUL ] ;
缺省值为audit *** by session whenever successful
2.6 检查审计结果视图。
查询sys.aud$表或者dba_audit_trail视图,可得到审计结果记录。
Aud$表的记录会一直增大,而该表所在的表空间为system表空间。System表空间满会导致数据库挂起。所以,在数据库审计功能打开后,需要时刻关注aud$表的增长情况。
可移动aud$表到其他表空间,以避免system表空间满导致数据库系统挂起的问题。
Aud$表中的记录也需要定期清除,使用命令truncate table aud$;。
Aud$表结构如下:
SQL> desc aud$;
Name Type Nullable
SESSIONID NUMBER
ENTRYID NUMBER
STATEMENT NUMBER
TIMESTAMP# DATE Y
USERID VARCHAR2(30) Y
USERHOST VARCHAR2(128) Y
TERMINAL VARCHAR2(255) Y
ACTION# NUMBER
RETURNCODE NUMBER
OBJ$CREATOR VARCHAR2(30) Y
OBJ$NAME VARCHAR2(128) Y
AUTH$PRIVILEGES VARCHAR2(16) Y
AUTH$GRANTEE VARCHAR2(30) Y
NEW$OWNER VARCHAR2(30) Y
NEW$NAME VARCHAR2(128) Y
SES$ACTIONS VARCHAR2(19) Y
SES$TID NUMBER Y
LOGOFF$LREAD NUMBER Y
LOGOFF$PREAD NUMBER Y
LOGOFF$LWRITE NUMBER Y
LOGOFF$DEAD NUMBER Y
LOGOFF$TIME DATE Y
COMMENT$TEXT VARCHAR2(4000) Y
CLIENTID VARCHAR2(64) Y
SPARE1 VARCHAR2(255) Y
SPARE2 NUMBER Y
OBJ$LABEL RAW(255) Y
SES$LABEL RAW(255) Y
PRIV$USED NUMBER Y
SESSIONCPU NUMBER Y
NTIMESTAMP# TIMESTAMP(6) Y
PROXY$SID NUMBER Y
USER$GUID VARCHAR2(32) Y
INSTANCE# NUMBER Y
PROCESS# VARCHAR2(16) Y
XID RAW(8) Y
AUDITID VARCHAR2(64) Y
SCN NUMBER Y
DBID NUMBER Y
SQLBIND CLOB Y
SQLTEXT CLOB Y
dba_audit_trail视图结构如下:
Name Comments
OS_USERNAME Operating System logon user name of the user
whose actions were audited
USERNAME Name (not ID number) of the user
whose actions were audited
USERHOST Client host machine name
TERMINAL Identifier for the user's terminal
TIMESTAMP Date/Time of the creation of the audit trail entry
(Date/Time of the user's logon for entries created by AUDIT SESSION)
in session's time zone
OWNER Creator of object affected by the action
OBJ_NAME Name of the object affected by the action
ACTION Numeric action type code.
The corresponding name of the action type
(CREATE TABLE, INSERT, etc.)
is in the column ACTION_NAME
ACTION_NAME Name of the action type corresponding
to the numeric code in ACTION
NEW_OWNER The owner of the object named
in the NEW_NAME column
NEW_NAME New name of object after RENAME,
or name of underlying object
(e.g. CREATE INDEX owner.obj_name
ON new_owner.new_name)
OBJ_PRIVILEGE Object privileges granted/revoked
by a GRANT/REVOKE statement
SYS_PRIVILEGE System privileges granted/revoked
by a GRANT/REVOKE statement
ADMIN_OPTION If role/sys_priv was granted
WITH ADMIN OPTON, A/-
GRANTEE The name of the grantee specified
in a GRANT/REVOKE statement
AUDIT_OPTION Auditing option set
with the audit statement
SES_ACTIONS Session summary.
A string of 12 characters,
one for each action type,
in thisorder: Alter, Audit,
Comment, Delete, Grant, Index,
Insert, Lock, Rename, Select,
Update, Flashback.
Values: "-" = None, "S" = Success,
"F" = Failure, "B" = Both
LOGOFF_TIME Timestamp for user logoff
LOGOFF_LREAD Logical reads for the session
LOGOFF_PREAD Physical reads for the session
LOGOFF_LWRITE Logical writes for the session
LOGOFF_DLOCK Deadlocks detected during the session
COMMENT_TEXT Text comment on the audit trail entry.
Also indicates how the user was authenticated.
The meth od can be one of the following:
1. "DATABASE" - aut hentication was done by pass word.
2. "NETWORK" - aut hentication was done by Net8
or the Advanced Networking Option.
3. "PROXY" - the client was authenticated by another user.
The name of the proxy user follo ws the method type.
SESSIONID Numeric ID for each Oracle session
ENTRYID Numeric ID for each audit trail entry in the session
STATEMENTID Numeric ID for each statement run
(a statement may cause many actions)
RETURNCODE Oracle error code generated by the action.
Zero if the action succeeded
PRIV_USED System privilege used to execute the action
CLIENT_ID Client identifier in each Oracle session
ECONTEXT_ID Execution Context Identifier for each action
SESSION_CPU Amount of cpu time used
by each Oracle session
EXTENDED_TIMESTAMP Timestamp of the creation of audit trail entry
(Timestamp of the user's logon for entries created by AUDIT SESSION)
in session's time zone
PROXY_SESSIONID Proxy session serial number,
if enterprise user has logged through proxy mechanism
GLOBAL_UID Global user identifier for the user,
if the user had logged in as enterprise user
INSTANCE_NUMBER Instance number as specified
in the initialization parameter file 'init.ora'
OS_PROCESS Operating System process identifier
of the Oracle server process
TRANSACTIONID Transaction identifier of the transaction
in which the object is accessed or modified
SCN SCN (System Change Number) of the query
SQL_BIND Bind variable data of the query
SQL_TEXT SQL text of the query
2.7 解除对象的审计功能
在确认审计结束后,务必解除该对象的审计功能。命令如下:
Noaudit select on scott.emp;
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
