oracle中如何查看錶空間

來源:互聯網
上載者:User

1. 查看所有資料表空間大小

select tablespace_name,sum(bytes)/1024/1024 from dba_data_files

group by tablespace_name;

2. 未使用的資料表空間大小

select tablespace_name,sum(bytes)/1024/1024 from dba_free_space

group by tablespace_name;

3. 所以使用空間可以這樣計算

select a.tablespace_name,total,free,total-free used from

( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files

group by tablespace_name) a,

( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space

group by tablespace_name) b

where a.tablespace_name=b.tablespace_name;

4. 下面這條語句查看所有segment的大小

Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name

5. 還有在命令列情況下如何將結果放到一個檔案裡

SQL> spool out.txt

SQL> select * from v$database;

SQL> spool off

6.如何查看oracle暫存資料表空間當前使用了多少空間的大小?

不是佔用量,是當前正在使用的暫存資料表空間大小

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;

7.查詢所有的資料表空間

select tablespace_name from dba_tablespaces ;

8. 查看錶空間中分布的使用者資訊

select tablespace_name, owner,sum(bytes) from dba_segments

group by tablespace_name, owner

------------------

1.查看錶空間已經使用的百分比

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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”表示資料表空間所有的資料檔案總共在作業系統佔用磁碟空間的大小

比如:test資料表空間有2個資料檔案,datafile1為300MB,datafile2為400MB,那麼test資料表空間的“Sum MB”就是700MB

“userd MB”表示資料表空間已經使用了多少

“free MB”表示資料表空間剩餘多少

“percent_user”表示已經使用的百分比

2.比如從1中查看到MLOG_NORM_SPACE資料表空間已使用百分比達到90%以上,可以查看該資料表空間總共有幾個資料檔案,每個資料檔案是否自動擴充,可以自動擴充的最大值。

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';

2.1 查看 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,但最大每個資料檔案只能為20GB,資料檔案快要寫滿,可以增加資料表空間的資料檔案

用作業系統UNIX、Linux中的df   -g命令(查看下可以使用的磁碟空間大小)

擷取建立資料表空間的語句:

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

4.確認磁碟空間足夠,增加一個資料檔案

alter   tablespace   MLOG_NORM_SPACE

add   datafile   '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'

size   10M   autoextend   on   maxsize   20G

5.驗證已經增加的資料檔案

select   file_name,file_id,tablespace_name   from   dba_data_files

where   tablespace_name='MLOG_NORM_SPACE'

6.刪除資料表空間資料檔案

alter   tablespace   MLOG_NORM_SPACE

drop    datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.