……天天向上

          好的想法總是無(wú)窮無(wú)盡

          統(tǒng)計(jì)

          留言簿(1)

          閱讀排行榜

          評(píng)論排行榜

          oracle 臨時(shí)表空間的增刪改查

          oracle 臨時(shí)表空間的增刪改查

          1、查看臨時(shí)表空間 (dba_temp_files視圖)(v_$tempfile視圖)
          select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
          select status,enabled, name, bytes/1024/1024 file_size from v_$tempfile;--sys用戶(hù)查看

          2、縮小臨時(shí)表空間大小
          alter database tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\TELEMT\TEMP01.DBF' resize 100M;

          3、擴(kuò)展臨時(shí)表空間:
          方法一、增大臨時(shí)文件大?。?br />SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ resize 100m;
          方法二、將臨時(shí)數(shù)據(jù)文件設(shè)為自動(dòng)擴(kuò)展:
          SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ autoextend on next 5m maxsize unlimited;
          方法三、向臨時(shí)表空間中添加數(shù)據(jù)文件:
          SQL> alter tablespace temp add tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ size 100m;

          4、創(chuàng)建臨時(shí)表空間
          SQL> create temporary tablespace temp1 tempfile ‘/u01/app/oracle/oradata/orcl/temp11.dbf’ size 10M;

          5、更改系統(tǒng)的默認(rèn)臨時(shí)表空間:
          --查詢(xún)默認(rèn)臨時(shí)表空間
          select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
          --修改默認(rèn)臨時(shí)表空間
          alter database default temporary tablespace temp1;
          所有用戶(hù)的默認(rèn)臨時(shí)表空間都將切換為新的臨時(shí)表空間:
          select username,temporary_tablespace,default_ from dba_users;
          --更改某一用戶(hù)的臨時(shí)表空間:
          alter user scott temporary tablespace temp;

          6、刪除臨時(shí)表空間
          刪除臨時(shí)表空間的一個(gè)數(shù)據(jù)文件:
          SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ drop;
          刪除臨時(shí)表空間(徹底刪除):
          SQL> drop tablespace temp1 including contents and datafiles cascade constraints;

          7、查看臨時(shí)表空間的使用情況(GV_$TEMP_SPACE_HEADER視圖必須在sys用戶(hù)下才能查詢(xún))
          GV_$TEMP_SPACE_HEADER視圖記錄了臨時(shí)表空間的使用大小與未使用的大小
          dba_temp_files視圖的bytes字段記錄的是臨時(shí)表空間的總大小
          SELECT temp_used.tablespace_name,
                 total - used as "Free",
                 total as "Total",
                 round(nvl(total - used, 0) * 100 / total, 3) "Free percent"
            FROM (SELECT tablespace_name, SUM(bytes_used) / 1024 / 1024 used
                    FROM GV_$TEMP_SPACE_HEADER
                   GROUP BY tablespace_name) temp_used,
                 (SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total
                    FROM dba_temp_files
                   GROUP BY tablespace_name) temp_total
           WHERE temp_used.tablespace_name = temp_total.tablespace_name

          8、查找消耗資源比較的sql語(yǔ)句
          Select se.username,
                 se.sid,
                 su.extents,
                 su.blocks * to_number(rtrim(p.value)) as Space,
                 tablespace,
                 segtype,
                 sql_text
            from v$sort_usage su, v$parameter p, v$session se, v$sql s
           where p.name = 'db_block_size'
             and su.session_addr = se.saddr
             and s.hash_value = su.sqlhash
             and s.address = su.sqladdr
           order by se.username, se.sid
           
          9、查看當(dāng)前臨時(shí)表空間使用大小與正在占用臨時(shí)表空間的sql語(yǔ)句
          select sess.SID, segtype, blocks * 8 / 1000 "MB", sql_text
            from v$sort_usage sort, v$session sess, v$sql sql
           where sort.SESSION_ADDR = sess.SADDR
             and sql.ADDRESS = sess.SQL_ADDRESS
           order by blocks desc;

          10、臨時(shí)表空間組介紹
            1)創(chuàng)建臨時(shí)表空間組:
          create temporary tablespace tempts1 tempfile '/home/oracle/temp1_02.dbf' size 2M tablespace group group1;
          create temporary tablespace tempts2 tempfile '/home/oracle/temp2_02.dbf' size 2M tablespace group group2;
           
           2)查詢(xún)臨時(shí)表空間組:dba_tablespace_groups視圖
          select * from dba_tablespace_groups;
          GROUP_NAME                     TABLESPACE_NAME
          ------------------------------ ------------------------------
          GROUP1                         TEMPTS1
          GROUP2                         TEMPTS2

           3)將表空間從一個(gè)臨時(shí)表空間組移動(dòng)到另外一個(gè)臨時(shí)表空間組:
          alter tablespace tempts1 tablespace group GROUP2 ;
          select * from dba_tablespace_groups;

          GROUP_NAME                     TABLESPACE_NAME
          ------------------------------ ------------------------------
          GROUP2                         TEMPTS1
          GROUP2                         TEMPTS2

           4)把臨時(shí)表空間組指定給用戶(hù)
          alter user scott temporary tablespace GROUP2;

           5)在數(shù)據(jù)庫(kù)級(jí)設(shè)置臨時(shí)表空間
          alter database <db_name> default temporary tablespace GROUP2;

           6)刪除臨時(shí)表空間組 (刪除組成臨時(shí)表空間組的所有臨時(shí)表空間)
          drop tablespace tempts1 including contents and datafiles;
          select * from dba_tablespace_groups;
          GROUP_NAME                     TABLESPACE_NAME
          ------------------------------ ------------------------------
          GROUP2                         TEMPTS2

          drop tablespace tempts2 including contents and datafiles;
          select * from dba_tablespace_groups;
          GROUP_NAME                     TABLESPACE_NAME

          11、對(duì)臨時(shí)表空間進(jìn)行shrink(11g新增的功能)
          --將temp表空間收縮為20M
          alter tablespace temp shrink space keep 20M;
          --自動(dòng)將表空間的臨時(shí)文件縮小到最小可能的大小
          ALTER TABLESPACE temp SHRINK TEMPFILE ’/u02/oracle/data/lmtemp02.dbf’;

          臨時(shí)表空間作用
          Oracle臨時(shí)表空間主要用來(lái)做查詢(xún)和存放一些緩沖區(qū)數(shù)據(jù)。臨時(shí)表空間消耗的主要原因是需要對(duì)查詢(xún)的中間結(jié)果進(jìn)行排序。
          重啟數(shù)據(jù)庫(kù)可以釋放臨時(shí)表空間,如果不能重啟實(shí)例,而一直保持問(wèn)題sql語(yǔ)句的執(zhí)行,temp表空間會(huì)一直增長(zhǎng)。直到耗盡硬盤(pán)空間。
          網(wǎng)上有人猜測(cè)在磁盤(pán)空間的分配上,oracle使用的是貪心算法,如果上次磁盤(pán)空間消耗達(dá)到1GB,那么臨時(shí)表空間就是1GB。
          也就是說(shuō)當(dāng)前臨時(shí)表空間文件的大小是歷史上使用臨時(shí)表空間最大的大小。

          臨時(shí)表空間的主要作用:
            索引create或rebuild;
            Order by 或 group by;
            Distinct 操作;
            Union 或 intersect 或 minus;
            Sort-merge joins;
            analyze.

          posted on 2012-06-28 14:54 japper 閱讀(31514) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): Oracle

          評(píng)論

          # re: oracle 臨時(shí)表空間的增刪改查 2015-07-02 21:12 2345

          23452345   回復(fù)  更多評(píng)論   

          # re: oracle 臨時(shí)表空間的增刪改查 2015-07-02 21:13 2345

          八戒咖啡該事故覅亞瑟規(guī)范勞務(wù)啊惡化  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 曲周县| 榆林市| 拉萨市| 麻栗坡县| 浪卡子县| 余姚市| 阿图什市| 镇安县| 赞皇县| 儋州市| 翼城县| 三台县| 江油市| 扎鲁特旗| 登封市| 聂拉木县| 贡嘎县| 陕西省| 远安县| 镇安县| 云浮市| 泰宁县| 馆陶县| 连山| 北碚区| 通山县| 黑河市| 汤原县| 仪陇县| 七台河市| 镇远县| 三门峡市| 安平县| 安仁县| 年辖:市辖区| 托克逊县| 高州市| 乐至县| 晋州市| 特克斯县| 荔浦县|