目录一、什么是临时表空间二、oracle创建临时表空间的方法三、如何在 Oracle 中检查临时表空间3.1 如何检查 Temp 表空间的大小3.2 oracle如何查看临时表空间的可用空间3.3 如何在实例级别检查临时表空间使用情况3.4 如何查看 Temp 表空间的使用百分比3.5 如何找到正在使用临时表空间的会话3.5 如何通过会话检查临时使用情况3.6 如果我们还想看到正在运行的 sql3.7 如何使用大量 TEMP 查找会话四、oracle如何增加临时表空间4.1 如何调整临时文件的大小4.2 如何删除临时文件
临时表空间用于 Oracle 中的排序操作。它也用于连接操作。基本上,它是临时存储,临时对象是在这里创建的。全局临时表也在这个表空间中创建。这是一个非常重要的表空间,如果管理不当,可能会出现问题。让我们看看临时表空间管理的各种查询
这是创建临时表空间的 SQL
–单个临时文件
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE ‘/u01/oracle/TEST/oradata/temp_1.dbf’ SIZE 1000M;
–多个临时文件
CREATE TABLESPACE TEMP TEMPFILE
‘/u01/oracle/TEST/oradata/temp_1.dbf’ SIZE 1000M
‘/u01/oracle/TEST/oradata/temp_2.dbf’ SIZE 1000M
;
–使用 ASM
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE ‘+DATA’ SIZE 1000M;
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE ‘/u01/oracle/TEST/oradata/temp_1.dbf’ SIZE 1000M;
–多个临时文件
CREATE TABLESPACE TEMP TEMPFILE
‘/u01/oracle/TEST/oradata/temp_1.dbf’ SIZE 1000M
‘/u01/oracle/TEST/oradata/temp_2.dbf’ SIZE 1000M
;
–使用 ASM
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE ‘+DATA’ SIZE 1000M;
Oracle 数据库可以有多个临时表空间
select tablespace_name,status,contents from dba_tablespaces where contents=’TEMPORARY’;
我们可以使用以下查询选择每个表空间中的文件
select file_name, tablespace_name, bytes from dba_temp_files
或
select a.name,b.name, a.bytes from v$tempfile a, v$tablespace b where a.ts#=b.ts#
或
select a.name,b.name, a.bytes from v$tempfile a, v$tablespace b where a.ts#=b.ts#
这是有关如何在 oracle 中检查以 GB 为单位的临时表空间大小的查询
select tablespace_name,sum(bytes)/1024/1024/1024 temp_gb
from dba_temp_files group by tablespace_name;
or
select b.name, sum(a.bytes)/1024/1024/1024 from v$tempfile a, v$tablespace b where a.ts#=b.ts# group by b.name;
from dba_temp_files group by tablespace_name;
or
select b.name, sum(a.bytes)/1024/1024/1024 from v$tempfile a, v$tablespace b where a.ts#=b.ts# group by b.name;
select tsh.tablespace_name,
dtf.bytes/1024/1024/1024 total_GB,
sum(nvl(tsh.bytes_used,0))/1024/1024/1024 used_GB,
sum(nvl(tsh.bytes_free,0))/1024/1024/1024 free_GB,
(1-sum(nvl(tsh.bytes_free,0))/dtf.bytes)*100 pct,
from v$temp_space_header tsh,
(select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name) dtf
where dtf.tablespace_name=tsh.tablespace_name(+)
group by tsh.tablespace_name, dtf.bytes/1024, dtf.bytes
order by 1
/
dtf.bytes/1024/1024/1024 total_GB,
sum(nvl(tsh.bytes_used,0))/1024/1024/1024 used_GB,
sum(nvl(tsh.bytes_free,0))/1024/1024/1024 free_GB,
(1-sum(nvl(tsh.bytes_free,0))/dtf.bytes)*100 pct,
from v$temp_space_header tsh,
(select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name) dtf
where dtf.tablespace_name=tsh.tablespace_name(+)
group by tsh.tablespace_name, dtf.bytes/1024, dtf.bytes
order by 1
/
在 11g 中,引入了一个新视图 dba_temp_free_space,因此我们也可以将其用作
SELECT * FROM dba_temp_free_space;
select inst_id, tablespace_name, segment_file, total_blocks,
used_blocks, free_blocks, max_used_blocks, max_sort_blocks
from gv$sort_segment;
?
select inst_id, tablespace_name, blocks_cached, blocks_used
from gv$temp_extent_pool;
?
select inst_id,tablespace_name, blocks_used, blocks_free
from gv$temp_space_header;
?
select inst_id,free_requests,freed_extents
from gv$sort_segment;
used_blocks, free_blocks, max_used_blocks, max_sort_blocks
from gv$sort_segment;
?
select inst_id, tablespace_name, blocks_cached, blocks_used
from gv$temp_extent_pool;
?
select inst_id,tablespace_name, blocks_used, blocks_free
from gv$temp_space_header;
?
select inst_id,free_requests,freed_extents
from gv$sort_segment;
select tablespace_name, ‘ %free=’|| round(sum(free_blocks) / sum(total_blocks) * 100 ,0)
from gv$sort_segment group by tablespace_name;
from gv$sort_segment group by tablespace_name;
set pagesize 50000 echo off verify off feedback off lines 80 heading on
col username format a15 head ‘Username’
col osuser format a15 head ‘OS User’
col sid format 99999 head ‘Sid’
col logon_time format a14 head ‘Logon Time’
col tablespace format a15 head ‘Tablespace Name’
select
tablespace
, a.osuser
, a.username
, a.sid
, to_char(logon_time,’MM/DD/YY HH24:MI’) logon_time
from v$session a, v$sort_usage b
where a.saddr=b.session_addr;
col username format a15 head ‘Username’
col osuser format a15 head ‘OS User’
col sid format 99999 head ‘Sid’
col logon_time format a14 head ‘Logon Time’
col tablespace format a15 head ‘Tablespace Name’
select
tablespace
, a.osuser
, a.username
, a.sid
, to_char(logon_time,’MM/DD/YY HH24:MI’) logon_time
from v$session a, v$sort_usage b
where a.saddr=b.session_addr;
SELECT s.sid、s.username、s.status、u.tablespace、u.segfile#、u.contents、u.extents、u.blocks
FROM v$session s、v$sort_usage u
WHERE s.saddr=u。 session_addr
ORDER BY u.tablespace, u.segfile#, u.segblk#, u.blocks;
FROM v$session s、v$sort_usage u
WHERE s.saddr=u。 session_addr
ORDER BY u.tablespace, u.segfile#, u.segblk#, u.blocks;
SELECT a.username, a.sid, a.serial#, a.osuser, b.tablespace, b.blocks, c.sql_text
FROM v$session a, v$tempseg_usage b, v$sqlarea c
WHERE a.saddr=b .session_addr
AND c.address=a.sql_address
AND c.hash_value=a.sql_hash_value
ORDER BY b.tablespace, b.blocks;
FROM v$session a, v$tempseg_usage b, v$sqlarea c
WHERE a.saddr=b .session_addr
AND c.address=a.sql_address
AND c.hash_value=a.sql_hash_value
ORDER BY b.tablespace, b.blocks;
col inst_id format 999
col sid format 99999
col status format a11
col program format a20 trunc
col machine format a17 trunc
col action format a39
col module format a39
col blocks heading “TEMP BLOCKS”
SELECT b.blocks, s.inst_id, s.sid, s.status,
s.action,
s.program,
s.machine,
s.module
FROM gv$session s,
gv$sort_usage b
WHERE s.saddr=b.session_addr
and s.inst_id=b.inst_id
and b.blocks > 100000
order by b.blocks desc;
col sid format 99999
col status format a11
col program format a20 trunc
col machine format a17 trunc
col action format a39
col module format a39
col blocks heading “TEMP BLOCKS”
SELECT b.blocks, s.inst_id, s.sid, s.status,
s.action,
s.program,
s.machine,
s.module
FROM gv$session s,
gv$sort_usage b
WHERE s.saddr=b.session_addr
and s.inst_id=b.inst_id
and b.blocks > 100000
order by b.blocks desc;
我们可以通过扩展现有文件或添加新的临时文件来增加临时表空间。
alter database tempfile ‘+DATA/test/tempfile01.dbf’ resize 10000m ;
or
alter tablespace TEMP add tempfile ‘+DATA/test/tempfile02.dbf’ resize 10000m ;
or
alter tablespace TEMP add tempfile ‘+DATA/test/tempfile02.dbf’ resize 10000m ;
alter database tempfile ‘+DATA/test/tempfile01.dbf’ resize 10000m ;
无法从普通表空间中删除数据文件,但可以从临时表空间中删除临时文件。这是sql
ALTER DATABASE TEMPFILE ‘<temp file>’ DROP INCLUDING DATAFILES;
到此这篇关于Oracle 中检查临时表空间的方法的文章就介绍到这了,更多相关Oracle 临时表空间内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:oracle临时表空间的作用与创建及相关操作详解Oracle临时表空间删除和重建实现过程Oracle 临时表空间SQL语句的实现oracle 临时表详解及实例对比Oracle临时表和SQL Server临时表的不同点
© 版权声明
文章版权归作者所有,未经允许请勿转载。