以下總結(jié)了關(guān)于 Oracle 數(shù)據(jù)庫臨時表空間的相關(guān) SQL 語句: Oracle 臨時表空間創(chuàng)建和添加數(shù)據(jù)文件: --創(chuàng)建臨時表空間 tempdatacreate temporary tablespace tempdata tempfile '/oradata/orcl/tempdata01.dbf' size 30g autoextend off;--新增臨時表空間數(shù)據(jù)文件alter tablespace tempdata add tempfile '/oradata/orcl/tempdata02.dbf' size 30g autoextend off;--刪除臨時表空間數(shù)據(jù)文件alter tablespace tempdata drop tempfile '/oradata/orcl/tempdata02.dbf' including datafiles;--調(diào)整臨時表空間數(shù)據(jù)文件大小alter database tempfile '/oradata/orcl/tempdata01.dbf' resize 2G;--設(shè)置自動擴(kuò)展alter database tempfile '/oradata/orcl/tempdata01.dbf' autoextend on;--切換默認(rèn)臨時表空間alter database default temporary tablespace tempdata;--刪除臨時表空間drop tablespace temp including contents and datafiles cascade constraints;--收縮臨時表空間alter tablespace temp shrink space keep 8G;alter tablespace temp shrink tempfile '/oradata/orcl/tempdata01.dbf'; 查看當(dāng)前默認(rèn)臨時表空間: SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE'; 查詢temp表空間使用率: select df.tablespace_name "Tablespace", df.totalspace "Total(MB)", nvl(FS.UsedSpace, 0) "Used(MB)", (df.totalspace - nvl(FS.UsedSpace, 0)) "Free(MB)", round(100 * (1-( nvl(fs.UsedSpace, 0) / df.totalspace)), 2) "Pct. Free(%)"FROM (SELECT tablespace_name, round(SUM(bytes) / 1048576) TotalSpaceFROM dba_TEMP_filesGROUP BY tablespace_name) df, (SELECT tablespace_name, ROUND(SUM(bytes_used) / 1024 / 1024) UsedSpaceFROM gV$temp_extent_poolGROUP BY tablespace_name) fs WHERE df.tablespace_name = fs.tablespace_name(+) 查看臨時表空間對應(yīng)的臨時文件的使用情況: SELECT TABLESPACE_NAME AS TABLESPACE_NAME ,BYTES_USED/1024/1024/1024 AS TABLESAPCE_USED ,BYTES_FREE/1024/1024/1024 AS TABLESAPCE_FREEFROM V$TEMP_SPACE_HEADERORDER BY 1 DESC; 查詢實時使用temp表空間的sql_id和sid: set linesize 260 pagesize 1000col machine for a40 col program for a40SELECT se.username, sid, serial#, se.sql_id machine, program, tablespace, segtype, (su.BLOCKS*8/1024/1024) GB FROM v$session se, v$sort_usage su WHERE se.saddr = su.session_addr order by su.BLOCKS desc;/*需要注意的是這里查詢sql_id要用v$session視圖的sql_id,,而不要用v$sort_usage視圖的sql_id,,v$sort_usage視圖里面的sql_id是不準(zhǔn)確的*/ 查詢歷史的temp表空間的使用的SQL_ID: select a.SQL_ID, a.SAMPLE_TIME, a.program, sum(trunc(a.TEMP_SPACE_ALLOCATED / 1024 / 1024)) MB from v$active_session_history a where TEMP_SPACE_ALLOCATED is not null and sample_time between to_date('&date1', 'yyyy-mm-dd hh24:mi:ss') and to_date('&date2', 'yyyy-mm-dd hh24:mi:ss') group by a.sql_id,a.SAMPLE_TIME,a.PROGRAM order by 2 asc,4 desc; 本次分享到此結(jié)束啦~ 如果覺得文章對你有幫助,,點贊,、收藏,、關(guān)注,、評論,一鍵四連支持,,你的支持就是我創(chuàng)作最大的動力,。 |
|
來自: LuciferLiu > 《待分類》