--UNDO表空间汇总
--查看所有的表空间名字
SELECT NAME FROM V$TABLESPACE;
--创建新的UNDO表空间,并设置自动扩展参数;
CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE ‘D:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\UNDOTBS02.DBF‘ SIZE 10M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;
--注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间:
ALTER SYSTEM SET UNDO_TABLESPACE = UNDO2;
--修改为自动管理
ALTER SYSTEM SET UNDO_MANAGEMENT = AUTO SCOPE = SPFILE;
修改UNDO的表空间管理方式为MANUAL ALTER SYSTEM SET UNDO_MANAGEMENT = MANUAL SCOPE = SPFILE;
--修改
--等待原UNDO表空间所有UNDO SEGMENT OFFLINE;
SELECT USN,
XACTS,
STATUS,
RSSIZE / 1024 / 1024 / 1024,
HWMSIZE / 1024 / 1024 / 1024,
SHRINKS
FROM V$ROLLSTAT
ORDER BY RSSIZE;
--删除表空间
DROP TABLESPACE UNDO1 INCLUDING CONTENTS AND DATAFILES;
--更改UODO表空间的大小
ALTER DATABASE DATAFILE ‘/U2/ORADATA/SPRING/UNDOTBS01.DBF‘ RESIZE 1024M;
SELECT TABLESPACE_NAME, SEGMENT_TYPE, OWNER, SEGMENT_NAME
FROM DBA_EXTENTS
WHERE FILE_ID = 8
AND 565129 BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1;
1, 临时表空间的主要作用: 索引CREATE或REBUILD; ORDER BY 或 GROUP BY; DISTINCT 操作; UNION 或 INTERSECT 或 MINUS; SORT - MERGE JOINS; ANALYZE.
SELECT USERNAME, TEMPORARY_TABLESPACE FROM DBA_USERS;
查看默认临时表空间
SELECT *
FROM DATABASE_PROPERTIES
WHERE PROPERTY_NAME = ‘DEFAULT_TEMP_TABLESPACE‘;
--建立临时表空间
SELECT A.PROPERTY_NAME, A.PROPERTY_VALUE
FROM DATABASE_PROPERTIES A
WHERE A.PROPERTY_NAME LIKE ‘%DEFAULT%‘;
6, /*查看临时表空间总体使用情况*/
SELECT TMP_TBS.TABLESPACE_NAME,
SUM(TMP_TBS.TOTAL_MB) TOTAL_MB,
SUM(USED_TOT.USED_MB) USED_MB,
SUM(USED_TOT.USED_MB) / SUM(TMP_TBS.TOTAL_MB) * 100 USED_PERSENT
FROM (SELECT TABLESPACE_NAME, SUM(BYTES) / 1024 / 1024 TOTAL_MB
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) TMP_TBS,
(SELECT TMP_USED.TABLESPACE,
SUM(TMP_USED.BLOCKS * PARA.DB_BLOCK_SIZE) / 1024 / 1024 USED_MB
FROM V$SORT_USAGE TMP_USED,
(SELECT VALUE DB_BLOCK_SIZE
FROM V$PARAMETER
WHERE NAME = ‘DB_BLOCK_SIZE‘) PARA
GROUP BY TMP_USED.TABLESPACE) USED_TOT
WHERE TMP_TBS.TABLESPACE_NAME = USED_TOT.TABLESPACE(+)
GROUP BY TMP_TBS.TABLESPACE_NAME;
7, /*查看临时表空间中排序段和数据段的使用情况*/
SELECT TMP_TBS.TABLESPACE_NAME,
USED_TOT.SEGTYPE TEMP_SEG_TYPE,
SUM(TMP_TBS.TOTAL_MB) TOTAL_MB,
SUM(USED_TOT.USED_MB) USED_MB,
SUM(USED_TOT.USED_MB) / SUM(TMP_TBS.TOTAL_MB) * 100 USED_PERSENT
FROM (SELECT TABLESPACE_NAME, SUM(BYTES) / 1024 / 1024 TOTAL_MB
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) TMP_TBS,
(SELECT TMP_USED.TABLESPACE,
TMP_USED.SEGTYPE,
SUM(TMP_USED.BLOCKS * PARA.DB_BLOCK_SIZE) / 1024 / 1024 USED_MB
FROM V$SORT_USAGE TMP_USED,
(SELECT VALUE DB_BLOCK_SIZE
FROM V$PARAMETER
WHERE NAME = ‘DB_BLOCK_SIZE‘) PARA
GROUP BY TMP_USED.TABLESPACE, TMP_USED.SEGTYPE) USED_TOT
WHERE TMP_TBS.TABLESPACE_NAME = USED_TOT.TABLESPACE(+)
GROUP BY TMP_TBS.TABLESPACE_NAME, USED_TOT.SEGTYPE;