Check_oracle_health之表空間使用及處理
Check_oracle_health之表空間使用及處理
1 檢視錶空間情況
--檢視所有表空間大小
select tablespace_name, sum(bytes) / 1024 / 1024 total_M
from dba_data_files
group by tablespace_name;
--已經使用的表空間大小
select tablespace_name, sum(bytes) / 1024 / 1024 used_M
from dba_free_space
group by tablespace_name;
--所以使用空間可以這樣計算
select a.tablespace_name, total_M, free_M, total_M - free_M used_M
from (select tablespace_name, sum(bytes) / 1024 / 1024 total_M
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) / 1024 / 1024 free_M
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name;
2 指令碼內命令
SELECT a.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
a.bytes bytes,
a.maxbytes bytes_max,
c.bytes_free bytes_free
FROM (
-- belegter und maximal verfuegbarer platz pro datafile
-- nach tablespacenamen zusammengefasst
-- => bytes
-- => maxbytes
SELECT a.tablespace_name,
SUM(a.bytes) / 1024 / 1024 bytes,
SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) / 1024 / 1024 / 1024 maxbytes
FROM dba_data_files a
GROUP BY tablespace_name) a,
sys.dba_tablespaces b,
(
-- freier platz pro tablespace
-- => bytes_free
SELECT a.tablespace_name, SUM(a.bytes) bytes_free
FROM dba_free_space a
GROUP BY tablespace_name) c
WHERE a.tablespace_name = c.tablespace_name(+)
AND a.tablespace_name = b.tablespace_name
UNION ALL
SELECT a.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
sum(a.bytes_free + a.bytes_used) bytes, -- allocated
SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max,
SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free
FROM sys.v_$TEMP_SPACE_HEADER a,
sys.dba_tablespaces b,
sys.v_$Temp_extent_pool c,
dba_temp_files d
WHERE c.file_id(+) = a.file_id
and c.tablespace_name(+) = a.tablespace_name
and d.file_id = a.file_id
and d.tablespace_name = a.tablespace_name
and b.tablespace_name = a.tablespace_name
GROUP BY a.tablespace_name,
b.status,
b.contents,
b.extent_management,
d.maxbytes
ORDER BY 1;
處理辦法:
方法1:為表空間增加資料檔案:
alter tablespace system add datafile '/app/oracle/oradata/testdb/system02.dbf' size 20M;
方法2:是增加表空間原有資料檔案尺寸:
alter database datafile '/app/oracle/oradata/testdb/system02.dbf' resize 200M;
建立表空間:
CREATE TABLESPACE 01 DATAFILE
'/oradata/grp/01_01.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_02.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_03.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_04.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_05.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_06.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
減小表空間大小:
alter database datafile '/app/oracle/oradata/testdb/system02.dbf' resize 20M;
指令碼check_oracle_health 計算表空間的方式是:
如果配置了auoextend on,就會採用maxbytes作為分母進行計算。
SELECT a.tablespace_name,
SUM(a.bytes)/1024/1024/1024 bytes,
SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes))/1024/1024/1024 maxbytes
FROM dba_data_files a
GROUP BY tablespace_name
if ($self->{bytes_max} == 0) {
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes} * 100;
$self->{real_bytes_max} = $self->{bytes};
$self->{real_bytes_free} = $self->{bytes_free};
} elsif ($self->{bytes_max} > $self->{bytes}) {
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes_max} * 100;
$self->{real_bytes_max} = $self->{bytes_max};
$self->{real_bytes_free} = $self->{bytes_free} + ($self->{bytes_max} - $self->{bytes});
} else {
# alter tablespace USERS add datafile 'users02.dbf'
# size 5M autoextend on next 200K maxsize 6M;
# bytes = 5M, maxbytes = 6M
# ..... data arriving...until ORA-01652: unable to extend temp segment
# bytes = 6M, maxbytes = 6M
# alter database datafile 5 resize 8M;
# bytes = 8M, maxbytes = 6M
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes} * 100;
$self->{real_bytes_max} = $self->{bytes};
$self->{real_bytes_free} = $self->{bytes_free};
}
}
1 檢視錶空間情況
--檢視所有表空間大小
select tablespace_name, sum(bytes) / 1024 / 1024 total_M
from dba_data_files
group by tablespace_name;
--已經使用的表空間大小
select tablespace_name, sum(bytes) / 1024 / 1024 used_M
from dba_free_space
group by tablespace_name;
--所以使用空間可以這樣計算
select a.tablespace_name, total_M, free_M, total_M - free_M used_M
from (select tablespace_name, sum(bytes) / 1024 / 1024 total_M
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) / 1024 / 1024 free_M
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name;
2 指令碼內命令
SELECT a.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
a.bytes bytes,
a.maxbytes bytes_max,
c.bytes_free bytes_free
FROM (
-- belegter und maximal verfuegbarer platz pro datafile
-- nach tablespacenamen zusammengefasst
-- => bytes
-- => maxbytes
SELECT a.tablespace_name,
SUM(a.bytes) / 1024 / 1024 bytes,
SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) / 1024 / 1024 / 1024 maxbytes
FROM dba_data_files a
GROUP BY tablespace_name) a,
sys.dba_tablespaces b,
(
-- freier platz pro tablespace
-- => bytes_free
SELECT a.tablespace_name, SUM(a.bytes) bytes_free
FROM dba_free_space a
GROUP BY tablespace_name) c
WHERE a.tablespace_name = c.tablespace_name(+)
AND a.tablespace_name = b.tablespace_name
UNION ALL
SELECT a.tablespace_name "Tablespace",
b.status "Status",
b.contents "Type",
b.extent_management "Extent Mgmt",
sum(a.bytes_free + a.bytes_used) bytes, -- allocated
SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max,
SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free
FROM sys.v_$TEMP_SPACE_HEADER a,
sys.dba_tablespaces b,
sys.v_$Temp_extent_pool c,
dba_temp_files d
WHERE c.file_id(+) = a.file_id
and c.tablespace_name(+) = a.tablespace_name
and d.file_id = a.file_id
and d.tablespace_name = a.tablespace_name
and b.tablespace_name = a.tablespace_name
GROUP BY a.tablespace_name,
b.status,
b.contents,
b.extent_management,
d.maxbytes
ORDER BY 1;
處理辦法:
方法1:為表空間增加資料檔案:
alter tablespace system add datafile '/app/oracle/oradata/testdb/system02.dbf' size 20M;
方法2:是增加表空間原有資料檔案尺寸:
alter database datafile '/app/oracle/oradata/testdb/system02.dbf' resize 200M;
建立表空間:
CREATE TABLESPACE 01 DATAFILE
'/oradata/grp/01_01.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_02.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_03.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_04.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_05.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G,
'/oradata/grp/01_06.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE 30G
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
減小表空間大小:
alter database datafile '/app/oracle/oradata/testdb/system02.dbf' resize 20M;
指令碼check_oracle_health 計算表空間的方式是:
如果配置了auoextend on,就會採用maxbytes作為分母進行計算。
SELECT a.tablespace_name,
SUM(a.bytes)/1024/1024/1024 bytes,
SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes))/1024/1024/1024 maxbytes
FROM dba_data_files a
GROUP BY tablespace_name
if ($self->{bytes_max} == 0) {
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes} * 100;
$self->{real_bytes_max} = $self->{bytes};
$self->{real_bytes_free} = $self->{bytes_free};
} elsif ($self->{bytes_max} > $self->{bytes}) {
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes_max} * 100;
$self->{real_bytes_max} = $self->{bytes_max};
$self->{real_bytes_free} = $self->{bytes_free} + ($self->{bytes_max} - $self->{bytes});
} else {
# alter tablespace USERS add datafile 'users02.dbf'
# size 5M autoextend on next 200K maxsize 6M;
# bytes = 5M, maxbytes = 6M
# ..... data arriving...until ORA-01652: unable to extend temp segment
# bytes = 6M, maxbytes = 6M
# alter database datafile 5 resize 8M;
# bytes = 8M, maxbytes = 6M
$self->{percent_used} =
($self->{bytes} - $self->{bytes_free}) / $self->{bytes} * 100;
$self->{real_bytes_max} = $self->{bytes};
$self->{real_bytes_free} = $self->{bytes_free};
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1354849/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 傳輸表空間及問題處理
- undo表空間故障處理
- 表空間使用情況查詢慢的處理
- SYSAUX表空間使用率高問題處理UX
- undo表空間佔用磁碟空間滿案例處理
- JAXB名稱空間及名稱空間字首處理
- sysaux 表空間爆滿處理方法UX
- sysaux 表空間不足問題處理UX
- Oracle Temp臨時表空間處理Oracle
- UNDO表空間損壞的處理
- oracle 表空間 不足時如何處理Oracle
- oracle表及表空間使用情況Oracle
- undo 表空間滿了的處理方法
- 表空間資料檔案故障處理
- 刪除臨時表空間hang處理
- 處理TEMP表空間滿的問題
- 批量處理時臨時增加回滾表空間臨時表空間檔案
- oracle中undo表空間丟失處理方法Oracle
- oracle sysaux表空間滿了處理辦法OracleUX
- Oracle undo表空間爆滿的處理方法Oracle
- undo表空間損壞的處理過程
- 索引表空間不足的幾個處理思路索引
- oracle系統表空間過大問題處理Oracle
- exp,imp 不同表空間大欄位處理方法
- 表空間無法擴充套件問題處理套件
- oracle臨時表空間過大的原因&&處理Oracle
- sysaux表空間檔案損壞的處理(zt)UX
- TEMP表空間報ORA-1652的處理
- 表空間管理之bigfile表空間設定
- 收縮臨時表空間收縮方法及ORA-03297錯誤處理
- 【儲存管理】建立臨時表空間組、建立臨時表空間組及使用
- 回滾段表空間損壞處理(ORA-01552)處理方法
- 查詢表的大小及表空間的使用情況
- Oracle - 表空間使用情況及相關字典Oracle
- Oracle新建表空間、使用者及授權Oracle
- Oracle查詢表佔磁碟空間大小及移動表空間Oracle
- 如何處理表空間級別,表級別,索引級別的碎片索引
- Oracle一次縮小表空間的處理過程Oracle