Oracle查看表空間使用率以及爆滿(mǎn)解決方案詳解
一、查看表空間使用率
1.查看數(shù)據(jù)庫(kù)表空間文件:
--查看數(shù)據(jù)庫(kù)表空間文件 select * from dba_data_files;
2.查看所有表空間的總?cè)萘浚?/h3>
--查看所有表空間的總?cè)萘?
select dba.TABLESPACE_NAME, sum(bytes)/1024/1024 as MB
from dba_data_files dba
group by dba.TABLESPACE_NAME;
--查看所有表空間的總?cè)萘? select dba.TABLESPACE_NAME, sum(bytes)/1024/1024 as MB from dba_data_files dba group by dba.TABLESPACE_NAME;
3.查看數(shù)據(jù)庫(kù)表空間使用率
--查看數(shù)據(jù)庫(kù)表空間使用率 select total.tablespace_name,round(total.MB, 2) as Total_MB,round(total.MB - free.MB, 2) as Used_MB,round((1-free.MB / total.MB)* 100, 2) || '%' as Used_Pct from ( select tablespace_name, sum(bytes) /1024/1024 as MB from dba_free_space group by tablespace_name) free, (select tablespace_name, sum(bytes) / 1024 / 1024 as MB from dba_data_files group by tablespace_name) total where free.tablespace_name = total.tablespace_name order by used_pct desc;
4.1.查看表空間總大小、使用率、剩余空間
--查看表空間總大小、使用率、剩余空間 select a.tablespace_name, total, free, total-free as used, substr(free/total * 100, 1, 5) as "FREE%", substr((total - free)/total * 100, 1, 5) as "USED%" from (select tablespace_name, sum(bytes)/1024/1024 as total from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b where a.tablespace_name = b.tablespace_name order by a.tablespace_name
4.2.查看表空間使用率(包含temp臨時(shí)表空間)
--查看表空間使用率(包含臨時(shí)表空間) select * from ( Select a.tablespace_name, (a.bytes- b.bytes) "表空間使用大小(BYTE)", a.bytes/(1024*1024*1024) "表空間大小(GB)", b.bytes/(1024*1024*1024) "表空間剩余大小(GB)", (a.bytes- b.bytes)/(1024*1024*1024) "表空間使用大小(GB)", to_char((1 - b.bytes/a.bytes)*100,'99.99999') || '%' "使用率" from (select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) b where a.tablespace_name = b.tablespace_name union all select c.tablespace_name, d.bytes_used "表空間使用大小(BYTE)", c.bytes/(1024*1024*1024) "表空間大小(GB)", (c.bytes-d.bytes_used)/(1024*1024*1024) "表空間剩余大小(GB)", d.bytes_used/(1024*1024*1024) "表空間使用大小(GB)", to_char(d.bytes_used*100/c.bytes,'99.99999') || '%' "使用率" from (select tablespace_name,sum(bytes) bytes from dba_temp_files group by tablespace_name) c, (select tablespace_name,sum(bytes_cached) bytes_used from v$temp_extent_pool group by tablespace_name) d where c.tablespace_name = d.tablespace_name ) order by tablespace_name
5.查看具體表的占用空間大小
--查看具體表的占用空間大小 select * from ( select t.tablespace_name,t.owner, t.segment_name, t.segment_type, sum(t.bytes / 1024 / 1024) mb from dba_segments t where t.segment_type='TABLE' group by t.tablespace_name,t.OWNER, t.segment_name, t.segment_type ) t order by t.mb desc
二、擴(kuò)展大小或增加表空間文件
1.更改表空間的dbf數(shù)據(jù)文件分配空間大小
alter database datafile ‘...\system_01.dbf' autoextend on; alter database datafile ‘...\system_01.dbf' resize 1024M;
2.1 為表空間新增一個(gè)數(shù)據(jù)文件(表空間滿(mǎn)32G不能擴(kuò)展則增加表空間文件)
alter tablespace SYSTEM add datafile '/****' size 1000m autoextend on next 100m;
2.2 如果是temp臨時(shí)表新增表空間會(huì)報(bào)錯(cuò):
0RA-03217: 變更TEMPORARY TABLESPACE 無(wú)效的選項(xiàng)
解決方法: datafile改為tempfile
alter tablespace TEMP01 add tempfile'/****' size 1000m autoextend on next 100m;
針對(duì)temp臨時(shí)表空間使用率爆滿(mǎn)問(wèn)題
臨時(shí)表空間主要用途是在數(shù)據(jù)庫(kù)進(jìn)行排序運(yùn)算、管理索引、訪(fǎng)問(wèn)視圖等操作時(shí)提供臨時(shí)的運(yùn)算空間,當(dāng)運(yùn)算完成之后系統(tǒng)會(huì)自動(dòng)清理,但有些時(shí)候我們會(huì)遇到臨時(shí)段沒(méi)有被釋放,TEMP表空間幾乎滿(mǎn)使用率情況;
引起臨時(shí)表空間增大主要使用在以下幾種情況:
1、order by or group by (disc sort占主要部分);
2、索引的創(chuàng)建和重創(chuàng)建;
3、distinct操作;
4、union & intersect & minus sort-merge joins;
5、Analyze 操作;
6、有些異常也會(huì)引起TEMP的暴漲。
解決方法一:用上述方法給temp增加表空間文件
解決方法二:在服務(wù)器資源空間有限的情況下,重新建立新的臨時(shí)表空間替換當(dāng)前的表空間
--1.查看當(dāng)前的數(shù)據(jù)庫(kù)默認(rèn)表空間: select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE'; --2.創(chuàng)建新的臨時(shí)表空間 create temporary tablespace TEMP01 tempfile '/home/temp01.dbf' size 31G; --3.更改默認(rèn)臨時(shí)表空間 alter database default temporary tablespace TEMP01; --4.刪除原來(lái)的臨時(shí)表空間 drop tablespace TEMP02 including contents and datafiles; --如果刪除原來(lái)臨時(shí)表空間報(bào)錯(cuò)ORA-60100:由于排序段,已阻止刪除表空間... --(說(shuō)明有語(yǔ)句正在使用原來(lái)的臨時(shí)表空間,需要將其kill掉再刪除,此語(yǔ)句多為排序的語(yǔ)句) --查詢(xún)語(yǔ)句 Select se.username,se.sid,se.serial#,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; --刪除對(duì)應(yīng)的'sid,serial#' alter system kill session 'sid,serial#'
附:查看表空間是否具有自動(dòng)擴(kuò)展的能力
--查看表空間是否具有自動(dòng)擴(kuò)展的能力 SELECT T.TABLESPACE_NAME,D.FILE_NAME, D.AUTOEXTENSIBLE,D.BYTES,D.MAXBYTES,D.STATUS FROM DBA_TABLESPACES T,DBA_DATA_FILES D WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME ORDER BY TABLESPACE_NAME,FILE_NAME;
總結(jié)
到此這篇關(guān)于Oracle查看表空間使用率以及爆滿(mǎn)解決方案的文章就介紹到這了,更多相關(guān)Oracle查看表空間使用率內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Oracle數(shù)據(jù)庫(kù)tnsnames.ora文件的作用和配置
這篇文章主要給大家介紹了關(guān)于Oracle數(shù)據(jù)庫(kù)tnsnames.ora文件的作用和配置,tnsnames.ora 是一個(gè)oracle數(shù)據(jù)庫(kù)網(wǎng)絡(luò)配置文件,通過(guò)這個(gè)配置文件才能建立對(duì)數(shù)據(jù)庫(kù)的連接,需要的朋友可以參考下2024-06-06
oracle使用to_date查詢(xún)一周的第一天日期
項(xiàng)目的開(kāi)發(fā)中需要用到一個(gè)查詢(xún)一周的第一天日期的函數(shù)搜索N久很難找到解決的方法 只要自己寫(xiě)一個(gè)先用著 代碼如下 a_week格式為 'YYYYIW' 如 '200801'表示2008年的第一周2014-01-01
ORA-02298: 無(wú)法驗(yàn)證 (約束)提示未找到父項(xiàng)關(guān)鍵字的解決辦法
這篇文章主要介紹了ORA-02298: 無(wú)法驗(yàn)證 (約束)提示未找到父項(xiàng)關(guān)鍵字的解決辦法,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
ORACLE學(xué)習(xí)筆記-新建用戶(hù)及建表篇
Oracle系統(tǒng),即是以O(shè)racle關(guān)系數(shù)據(jù)庫(kù)為數(shù)據(jù)存儲(chǔ)和管理作為構(gòu)架基礎(chǔ),構(gòu)建出的數(shù)據(jù)庫(kù)管理系統(tǒng)。世界第一個(gè)支持SQL語(yǔ)言的商業(yè)數(shù)據(jù)庫(kù),定位于高端工作站,以及作為服務(wù)器的小型計(jì)算機(jī),Oracle公司的整個(gè)產(chǎn)品線(xiàn)包括數(shù)據(jù)庫(kù)服務(wù)器、企業(yè)商務(wù)應(yīng)用套件、應(yīng)用開(kāi)發(fā)和決策支持工具2014-08-08
ORACLE檢查找出損壞索引(Corrupt Indexes)的方法詳解
這篇文章主要給大家介紹了關(guān)于ORACLE如何檢查找出損壞索引(Corrupt Indexes)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09
oracle錯(cuò)誤ORA-00054資源正忙解決辦法
ORA-00054是Oracle數(shù)據(jù)庫(kù)中的一個(gè)常見(jiàn)錯(cuò)誤,表示用戶(hù)試圖在正在被鎖定的資源上執(zhí)行不允許的操作,導(dǎo)致資源處于忙碌狀態(tài),下面這篇文章主要給大家介紹了關(guān)于oracle錯(cuò)誤ORA-00054資源正忙的解決辦法,需要的朋友可以參考下2024-01-01

