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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- sysaux 表空間爆滿處理方法UX
- oracle sysaux表空間滿了處理辦法OracleUX
- oracle中undo表空間丟失處理方法Oracle
- UNDO表空間空間回收及切換
- oracle系統表空間過大問題處理Oracle
- 表空間利用率及表空間的補充
- Oracle新建表空間、使用者及授權Oracle
- 當使用者無限制使用表空間配額且表空間有足夠空間時出現超出表空間的空間限額
- 刪除UNDO表空間並處理ORA-01548問題
- MySQL 磁碟空間滿導致表空間相關資料檔案損壞故障處理MySql
- 16、表空間 建立表空間
- mysql之 表空間傳輸MySql
- 關於丟失表空間資料檔案的處理方式
- Laravel 處理 MySQL geometry 空間型別LaravelMySql型別
- 18_深入解析Oracle undo原理(2)_undo表空間使用率100%問題處理Oracle
- Oracle新建使用者、表空間、表Oracle
- 臨時表空間和回滾表空間使用率查詢
- SYSAUX表空間清理之SM/OPTSTATUX
- Jenkins臨時空間不足處理辦法Jenkins
- OGG相關的CPATURE導致SYSAUX表空間異常暴增處理UX
- 對Oracle分割槽表進行表空間遷移並處理ORA-14511問題Oracle
- 查詢表空間使用情況
- 表空間使用量查詢
- SYSTEM 表空間管理及備份恢復
- PostgreSQL-表空間、資料庫、使用者之間的關係(七)SQL資料庫
- Oracle表空間Oracle
- oracle 表空間Oracle
- PostgreSQL 表空間SQL
- PostgreSQL:表空間SQL
- oracle 建立表空間和使用者Oracle
- Oracle建立表空間和使用者Oracle
- Oracle中新建表空間、使用者Oracle
- oracle表空間使用率查詢Oracle
- MySQL innodb表使用表空間物理檔案複製表MySql
- 檢查及設定合理的undo表空間
- 國產處理器龍芯地址空間詳解
- 伺服器儲存空間不足怎麼處理?伺服器
- SYSAUX表空間佔用過大情況下的處理(AWR資訊過多)UX
- oracle建立使用者,表空間,臨時表空間,分配許可權步驟詳解Oracle