夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks

          標題:查看Oracle數(shù)據(jù)庫表空間大小,是否需要增加表空間的數(shù)據(jù)文件

          數(shù)據(jù)庫管理中,磁盤空間不足是DBA都會遇到的問題,問題比較常見。

           

          --1查看表空間已經(jīng)使用的百分比

              select   a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024   "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  
              
          from  
              (
          select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   a,  
              (
          select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)   b  
              
          where   a.tablespace_name=b.tablespace_name  
              
          order   by   ((a.bytes-b.bytes)/a.bytes)   desc  

           

          “Sum MB”表示表空間所有的數(shù)據(jù)文件總共在操作系統(tǒng)占用磁盤空間的大小
            比如:test表空間有2個數(shù)據(jù)文件,datafile1為300MB,datafile2為400MB,那么test表空間的“Sum MB”就是700MB
          “userd MB”表示表空間已經(jīng)使用了多少
          “free MB”表示表空間剩余多少
          “percent_user”表示已經(jīng)使用的百分比

           

          --2比如從1中查看到MLOG_NORM_SPACE表空間已使用百分比達到90%以上,可以查看該表空間總共有幾個數(shù)

          據(jù)文件,每個數(shù)據(jù)文件是否自動擴展,可以自動擴展的最大值。

              select   file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB"   from   dba_data_files  
                
          where tablespace_name='MLOG_NORM_SPACE';  

           

          --- 查看 xxx 表空間是否為自動擴展 

              select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc;  

           

           

          --3比如MLOG_NORM_SPACE表空間目前的大小為19GB,但最大每個數(shù)據(jù)文件只能為20GB,數(shù)據(jù)文件快要寫滿,可以增加表空間的數(shù)據(jù)文件
          用操作系統(tǒng)UNIX、Linux中的df   -g命令(查看下可以使用的磁盤空間大小)
          獲取創(chuàng)建表空間的語句:

              select   dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE')   from   dual;  

           


          --4確認磁盤空間足夠,增加一個數(shù)據(jù)文件

              alter   tablespace   MLOG_NORM_SPACE  
              
          add   datafile   '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'  
              size   10M   autoextend   
          on   maxsize   20G  

           

           


          --5驗證已經(jīng)增加的數(shù)據(jù)文件

              select   file_name,file_id,tablespace_name   from   dba_data_files  
              
          where   tablespace_name='MLOG_NORM_SPACE'  

           

           

          --6如果刪除表空間數(shù)據(jù)文件,如下:

              alter   tablespace   MLOG_NORM_SPACE  
              
          drop    datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'  

           

          轉(zhuǎn)自http://space.itpub.net/12778571/viewspace-582695

          posted on 2011-08-10 15:36 HUIKK 閱讀(4456) 評論(0)  編輯  收藏 所屬分類: DB-DailyMmaintenance
          主站蜘蛛池模板: 旬邑县| 两当县| 湖口县| 靖远县| 新绛县| 乐都县| 佛冈县| 嘉兴市| 若尔盖县| 南宁市| 班戈县| 和林格尔县| 治多县| 富裕县| 德化县| 崇义县| 长乐市| 连平县| 南雄市| 石泉县| 清远市| 深圳市| 溧水县| 武威市| 白河县| 汉川市| 永年县| 米泉市| 新泰市| 广宗县| 文昌市| 乌鲁木齐县| 临洮县| 孙吴县| 长武县| 恭城| 定南县| 长垣县| 绥阳县| 玉树县| 久治县|