背景说明:
刚接手一个数据库的时候,发现该数据库的system表空间居然有21G,按照之前的数据库管理经验,目前管理过2TB的数据,SYSTEM表空间也没有超过2GB,所以出于谨慎的态度,对当前system的表空间的内容进行了相应的了解。
问题排查:
通过执行以下语句可以查看每个表空间所存放数据段的情况,脚本如下:
select A.SEGMENT_NAME,SUM(A.BYTES)/1024/1024/1024 GB,A.SEGMENT_TYPE
from dba_extents a,v$datafile b,v$tablespace C
where b.TS#=C.TS# AND C.NAME='SYSTEM' AND A.FILE_ID=B.FILE#
GROUP BY A.SEGMENT_NAME,A.SEGMENT_TYPE ORDER BY GB DESC
终于找到真相了,表AUD$占用了20.4G的空间;
深入了解:关于aud$表
1、AUD$的介绍
When standard auditing is enabled (that is, you set AUDIT_TRAIL to DB or DB,EXTENDED), Oracle Database audits all data manipulation language (DML) operations, such as INSERT, UPDATE, MERGE, and DELETE on the SYS.AUD$ and SYS.FGA_LOG$ tables by non-SYS users. (It performs this audit even if you have not set audit options for the AUD$ and FGA_LOGS$ tables.) Typically, non-SYS users do not have access to these tables, except if they have been explicitly granted access. If a non-SYS user tampers with the data in the SYS.FGA_LOG$ and SYS.AUD$ tables, then Oracle Database writes an audit record for each action.Oracle Database audits SYS user's DELETE, INSERT, UPDATE, and MERGE operations on the SYS.FGA_LOG$ and SYS.AUD$ tables if you have set the AUDIT_SYS_OPERATIONS initialization parameter to TRUE. In this case the audit records of all SYS operations are written to whatever directory the AUDIT_FILE_DEST initialization parameter points to. If AUDIT_FILE_DEST is not set, then it writes the records to an operating system-dependent location.
AUD$是数据库开启审计后,记录所有相关操作的表,所以可以确定数据库开启了审计的功能;
2、查看数据库的审计,show parameter aud;
发现数据库启用了DB级别的审计功能,相关审计级别如下:
None:是默认值,不做审计;
DB:将audit trail 记录在数据库的审计相关表中,如aud$,审计的结果只有连接信息;
DB,Extended:这样审计结果里面除了连接信息还包含了当时执行的具体语句;
OS:将audit trail 记录在操作系统文件中,文件名由audit_file_dest参数指定;
XML:10g里新增的。
备注:ORACLE11G中审计是默认开启的,而且是对DB进行审计;
解决方法:
1、关闭数据库的审计功能,一般都不建议在数据库层面打开审计功能,除非有要求;
关闭脚本:alter system set audit_trail=none scope=spfile; 该参数为静态参数,需要重启;
2、完成后可以对整个表空间进行收缩,具体的操作方法,请查看另外一个文档.......................................