共计 2892 个字符,预计需要花费 8 分钟才能阅读完成。
这篇文章主要讲解了“Oracle 怎么查看和修改临时表空间”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“Oracle 怎么查看和修改临时表空间”吧!
– 查表空间使用率情况(含临时表空间)
SELECT d.tablespace_name Name , d.status Status ,
TO_CHAR (NVL (a.BYTES / 1024 / 1024, 0), 99,999,990.90 ) Size (M) ,
TO_CHAR (NVL (a.BYTES – NVL (f.BYTES, 0), 0) / 1024 / 1024,
99999999.99
) USE,
TO_CHAR (NVL ((a.BYTES – NVL (f.BYTES, 0)) / a.BYTES * 100, 0),
990.00
) Used %
FROM SYS.dba_tablespaces d,
(SELECT tablespace_name, SUM (BYTES) BYTES
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM (BYTES) BYTES
FROM dba_free_space
GROUP BY tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND NOT (d.extent_management LIKE LOCAL AND d.CONTENTS LIKE TEMPORARY)
UNION ALL
SELECT d.tablespace_name Name , d.status Status ,
TO_CHAR (NVL (a.BYTES / 1024 / 1024, 0), 99,999,990.90 ) Size (M) ,
TO_CHAR (NVL (t.BYTES, 0) / 1024 / 1024, 99999999.99 ) USE,
TO_CHAR (NVL (t.BYTES / a.BYTES * 100, 0), 990.00 ) Used %
FROM SYS.dba_tablespaces d,
(SELECT tablespace_name, SUM (BYTES) BYTES
FROM dba_temp_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM (bytes_cached) BYTES
FROM v$temp_extent_pool
GROUP BY tablespace_name) t
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.extent_management LIKE LOCAL
AND d.CONTENTS LIKE TEMPORARY
1. 查询表空间剩余字节大小
SELECT TABLESPACE_NAME, SUM(BYTES)/1024/1024 AS FREE SPACE(M)
FROM DBA_FREE_SPACE
WHERE TABLESPACE_NAME = tablespace_name
GROUP BY TABLESPACE_NAME;
注:如果是临时表空间,请查询 DBA_TEMP_FREE_SPACE
SELECT TABLESPACE_NAME, FREE_SPACE/1024/1024 AS FREE SPACE(M)
FROM DBA_TEMP_FREE_SPACE
WHERE TABLESPACE_NAME = tablespace_name
2. 查询表空间所有数据文件路径
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS BYTES(M)
FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME = tablespace_name
注:如果是临时表空间,请查询 DBA_TEMP_FILES
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS SPACE(M)
FROM DBA_TEMP_FILES
WHERE TABLESPACE_NAME = tablespace_name
3. 为空间不足的表空间增加数据文件
ALTER TABLESPACE tablespace_name ADD DATAFILE datafile_name SIZE 2G;
注:如果要为临时表空间扩容,使用下面的语句
ALTER TABLESPACE tablespace_name ADD TEMPFILE datafile_name SIZE 2G;
4. 查看临时表空间的大小 和 数据文件路径
SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, BYTES/1024/1024 AS SPACE(M)
FROM DBA_TEMP_FILES
WHERE TABLESPACE_NAME = TEMP
或者
select name, bytes/1024/1024 as 大小(M) from v$tempfile order by bytes;
5. 重建并修改默认临时表空间办法:
– 查询当前数据库默认临时表空间名
select * from database_properties where property_name= DEFAULT_TEMP_TABLESPACE
– 创建新的临时表空间
create temporary tablespace temp02 tempfile E:\oracle\oradata\lims\TEMP02.DBF size 1024M autoextend on;
– 修改默认表空间为刚刚建立的临时表空间
alter database default temporary tablespace temp02;
– 查看用户所用临时表空间的情况
SELECT USERNAME,TEMPORARY_TABLESPACE FROM DBA_USERS;
– 删除原来的临时表空间
drop tablespace temp including contents and datafiles;
– 查看所有表空间名确认临时表空间是否已删除
select tablespace_name from dba_tablespaces;
感谢各位的阅读,以上就是“Oracle 怎么查看和修改临时表空间”的内容了,经过本文的学习后,相信大家对 Oracle 怎么查看和修改临时表空间这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!