<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ……天天向上

    好的想法總是無(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用戶查看

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

    3、擴(kuò)展臨時(shí)表空間:
    方法一、增大臨時(shí)文件大小:
    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í)表空間:
    --查詢默認(rèn)臨時(shí)表空間
    select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
    --修改默認(rèn)臨時(shí)表空間
    alter database default temporary tablespace temp1;
    所有用戶的默認(rèn)臨時(shí)表空間都將切換為新的臨時(shí)表空間:
    select username,temporary_tablespace,default_ from dba_users;
    --更改某一用戶的臨時(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用戶下才能查詢)
    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)查詢臨時(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í)表空間組指定給用戶
    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)做查詢和存放一些緩沖區(qū)數(shù)據(jù)。臨時(shí)表空間消耗的主要原因是需要對(duì)查詢的中間結(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 閱讀(31509) 評(píng)論(2)  編輯  收藏 所屬分類: 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)論   

    主站蜘蛛池模板: 免费成人福利视频| 午夜两性色视频免费网站| 亚洲视频在线免费| 免费无码看av的网站| 亚洲精品日韩一区二区小说| 日韩免费a级在线观看| 亚洲精品精华液一区二区| 在线观看永久免费视频网站| 亚洲中文字幕精品久久| 中文字幕成人免费高清在线 | 成年人免费视频观看| 麻豆狠色伊人亚洲综合网站| 中文字幕不卡高清免费| 亚洲韩国精品无码一区二区三区| 亚洲国产品综合人成综合网站| 久久国产乱子伦精品免费午夜| 亚洲免费观看视频| 看亚洲a级一级毛片| 日本亚洲免费无线码| 亚洲av无码专区在线电影天堂 | 午夜两性色视频免费网站| 美女被免费视频网站| 国产亚洲一区二区手机在线观看| 日本高清高色视频免费| 亚洲一区二区三区在线| 免费吃奶摸下激烈视频| 亚洲人妖女同在线播放| 国产精品国产免费无码专区不卡 | 亚洲春黄在线观看| 最近免费中文字幕MV在线视频3| 国产精品美女自在线观看免费| 人人爽人人爽人人片A免费| 国产成人涩涩涩视频在线观看免费| 猫咪免费人成网站在线观看入口 | 久久爰www免费人成| 国产婷婷综合丁香亚洲欧洲| 亚洲AV无码乱码在线观看| 亚洲av日韩精品久久久久久a| 久久精品国产亚洲精品| 在线看片v免费观看视频777| 亚洲va在线va天堂va四虎|