1、查询表空间使用率
SQL> set linesize 400
SQL> set pagesize 400
SQL>
SELECT D.TABLESPACE_NAME 表空间名称,SPACE "表空间(MB)",BLOCKS 总块数,SPACE - NVL(FREE_SPACE, 0) "已使用(MB)",
ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "使用率(%)",FREE_SPACE "未使用(MB)"
FROM
(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_SPACE
FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+);


2、查询 sysaux 表空间详细占用情况
SQL>
col Schema for a25;
col Item for a25;
SELECT occupant_name "Item",
space_usage_kbytes / 1048576 "Space Used (GB)",
schema_name "Schema",
move_procedure "Move Procedure"
FROM v$sysaux_occupants
ORDER BY 1 ;

Item Space Used (GB) Schema Move Procedure
------------------------------ --------------- --------------------------- ------------------------------------------
AO .101318359 SYS DBMS_AW.MOVE_AWMETA
AUDIT_TABLES 0 SYS DBMS_AUDIT_MGMT.move_dbaudit_tables
AUTO_TASK .000915527 SYS
EM .11517334 SYSMAN emd_maintenance.move_em_tblspc
EM_MONITORING_USER .001953125 DBSNMP
EXPRESSION_FILTER .010620117 EXFSYS
JOB_SCHEDULER .002380371 SYS
LOGMNR .030822754 SYSTEM SYS.DBMS_LOGMNR_D.SET_TABLESPACE
LOGSTDBY .00402832 SYSTEM SYS.DBMS_LOGSTDBY.SET_TABLESPACE
ORDIM .001281738 ORDSYS ordsys.ord_admin.move_ordim_tblspc
ORDIM/ORDDATA .046875 ORDDATA ordsys.ord_admin.move_ordim_tblspc
ORDIM/ORDPLUGINS 0 ORDPLUGINS ordsys.ord_admin.move_ordim_tblspc
ORDIM/SI_INFORMTN_SCHEMA 0 SI_INFORMTN_SCHEMA ordsys.ord_admin.move_ordim_tblspc
PL/SCOPE .001831055 SYS
SDO .14440918 MDSYS MDSYS.MOVE_SDO
SM/ADVISOR .102294922 SYS
SM/AWR 1.22515869 SYS
SM/OPTSTAT 11.755188 SYS
SM/OTHER .020568848 SYS
SMON_SCN_TIME .004394531 SYS
SQL_MANAGEMENT_BASE .004943848 SYS
STATSPACK 0 PERFSTAT
STREAMS .002929688 SYS
TEXT .010437012 CTXSYS DRI_MOVE_CTXSYS
TSM 0 TSMSYS
ULTRASEARCH 0 WKSYS MOVE_WK
ULTRASEARCH_DEMO_USER 0 WK_TEST MOVE_WK
WM .010253906 WMSYS DBMS_WM.move_proc
XDB .317932129 XDB XDB.DBMS_XDB.MOVEXDB_TABLESPACE
XSAMD .015014648 OLAPSYS DBMS_AMD.Move_OLAP_Catalog
XSOQHIST .101318359 SYS DBMS_XSOQ.OlapiMoveProc

31 rows selected.

2.1、
SM/OPTSTAT:
这将存储更老版本的优化器统计信息。
我们在Oracle Database 10g中有了新的功能,可以让您恢复旧的统计数据,以防在刷新数据时遇到执行计划回归。此数据的默认保留时间为31天。关于如何使用这一点的更多细节可以在注释452011.1中找到。严格地说,这不是AWR的一部分,因此不受AWR保留参数的控制,相反,我们可以使用DBMS_STATS包的ALTER_STATS_HISTORY_RETENTION过程来设置和更改该数据的保留时间。例如,您可以先检查当前保留时间,然后将其更改为不同的数量(在几天内),例如10天:

select dbms_stats.get_stats_history_retention from dual;
exec dbms_stats.alter_stats_history_retention(10);

如果您喜欢在某个时间戳之前特别清除数据,您可以使用PURGE_STATS过程。例如:
exec DBMS_STATS.PURGE_STATS(to_timestamp_tz('01-01-2018 00:00:00 Europe/London','DD-MM-YYYY HH24:MI:SS TZR'));


2.2、 AWR部分
SQL>
col SNAP_INTERVAL for a20
col RETENTION for a20
select * from dba_hist_wr_control;

DBID SNAP_INTERVAL RETENTION TOPNSQL
---------- -------------------- -------------------- ----------
213111497 +00000 01:00:00.0 +00008 00:00:00.0 DEFAULT

说明:
SNAP_INTERVAL=+00000 01:00:00.0 :表示采样间隔是1小时
RETENTION=+00008 00:00:00.0 :表示采样数据保留期限是8天

SQL>
begin
dbms_workload_repository.modify_snapshot_settings (
interval => 60, --每小时一次
retention => 7*24*60, --保留7天
topnsql => 100
);
end;

注意:如果快照太多,占用太多空间,也可以删除一些快照:
select min(snap_id),max(snap_id) from dba_hist_snapshot; --查询最最小和最大快照ID

--删除 编号 10758至10900 快照
begin
dbms_workload_repository.drop_snapshot_range(
low_snap_id => 10758, --根据情况设置
high_snap_id => 10900,
dbid => 387090299); DBID根据实际情况
end;
/

说明:
(1)如果AWR没有用的话,可以将采样时间间隔调整为最长100年,同时,把采样数据保留时间调整到最小1天的方式实现“禁用”AWR。
SQL> BEGIN
DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(
interval => 36500*24*60,
retention => 1*24*60);
END;
/
select * from dba_hist_wr_control;
DBID SNAP_INTERVAL RETENTION TOPNSQL
---------- -------------------- -------------------- ----------
4134757407 +36500 00:00:00.0 +00001 00:00:00.0 DEFAULT