oracle表空單清理常用代碼段整理
更新時(shí)間:2013年06月03日 15:20:10 作者:
清理TEMP臨時(shí)表空間、清理UNDO表空間、清理TEMPTABS表空間等等,有類似需求的朋友可以參考下哈
1.查詢表空間使用情況:
sqlplus system/manager@topprod
SQL>@q_tbsFREE
2.查詢temp使用方法:
sqlplus system/manager@topprod
SQL>SELECT
d.tablespace_name tablespace_name
, d.status tablespace_status
, NVL(a.bytes, 0) tablespace_size
, NVL(t.bytes, 0) used
, TRUNC(NVL(t.bytes / a.bytes * 100, 0)) used_pct
, NVL(s.current_users, 0) current_users
FROM
sys.dba_tablespaces d
, ( select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name
) a
, ( select tablespace_name, sum(bytes_cached) bytes
from v$temp_extent_pool
group by tablespace_name
) t
, v$sort_segment s
WHERE
d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = s.tablespace_name(+)
AND d.extent_management like 'LOCAL'
AND d.contents like 'TEMPORARY';
2.清理TEMP臨時(shí)表空間:(在無用戶連接的狀況下操作,最好在清理之前重啟一下數(shù)據(jù)庫)
#重啟數(shù)據(jù)庫
sqlplus '/as sysdba'
SQL>shutdown immediate
SQL>startup
#創(chuàng)建一個(gè)臨時(shí)表空間temp02,用作臨時(shí)替換
SQL>create temporary tablespace temp02 tempfile '/u2/oradb/oradata/topprod/temp02.dbf' size 10M autoextend on next 10M;
#將系統(tǒng)臨時(shí)表空間指向temp02
SQL>alter database default temporary tablespace temp02;
#刪除原來的臨時(shí)表空間temp
SQL>drop tablespace temp including contents and datafiles;
#創(chuàng)建新的臨時(shí)表空間temp
SQL>create temporary tablespace temp tempfile '/u2/oradb/oradata/topprod/temp01.dbf' size 4096M autoextend on next 100M;
#將系統(tǒng)臨時(shí)表空間指回temp
SQL>alter database default temporary tablespace temp;
#刪除臨時(shí)表空間temp02
SQL>drop tablespace temp02 including contents and datafiles;
3.清理UNDO表空間:(在無用戶連接的狀況下操作,最好在清理之前重啟一下數(shù)據(jù)庫)
#重啟數(shù)據(jù)庫
sqlplus '/as sysdba'
SQL>shutdown immediate
SQL>startup
#創(chuàng)建一個(gè)UNDO表空間undotbs2,用作臨時(shí)替換
SQL>create undo tablespace undotbs2 datafile '/u2/oradb/oradata/topprod/undotbs02.dbf' size 10M autoextend on next 10M;
#將系統(tǒng)UNDO表空間指向undotbs2
SQL>alter system set undo_tablespace=undotbs2 scope=both;
#確保所有在UNDOTBS1的undo segment都已offline
SQL> select SEGMENT_NAME ,STATUS ,TABLESPACE_NAME from dba_rollback_segs;
#刪除原來的UNDO表空間undotbs1
SQL>drop tablespace undotbs1 including contents and datafiles;
#創(chuàng)建新的臨時(shí)表空間undotbs1
SQL>create undo tablespace undotbs1 datafile '/u2/oradb/oradata/topprod/undotbs01.dbf' size 4096M;
#將系統(tǒng)UNDO表空間指回undotbs1
SQL>alter system set undo_tablespace=undotbs1 scope=both;
#刪除UNDO表空間undotbs2
SQL>drop tablespace undotbs2 including contents and datafiles;
3.清理TEMPTABS表空間:
#刪除TEMPTABS表空間
SQL>drop tablespace temptabs including contents and datafiles;
#創(chuàng)建TEMPTABS表空間
SQL>create tablespace temptabs datafile '/u2/oradb/oradata/topprod/temptabs.dbf' size 4096M autoextend on next 100M;
或者刪除表
[code]
select 'drop table '||segment_name ||';' from dba_segments where tablespace_name='TEMPTABS' and segment_name like 'TT%' and segment_name not like '%_FILE';
4.增加系統(tǒng)表空間:
alter tablespace SYSTEM add datafile '/u2/oradb/oradata/topprod/system02.dbf' size 2000M autoextend on next 10M;
alter tablespace SYSAUX add datafile '/u2/oradb/oradata/topprod/sysaux02.dbf' size 2000M autoextend on next 10M;
sqlplus system/manager@topprod
復(fù)制代碼 代碼如下:
SQL>@q_tbsFREE
2.查詢temp使用方法:
sqlplus system/manager@topprod
復(fù)制代碼 代碼如下:
SQL>SELECT
d.tablespace_name tablespace_name
, d.status tablespace_status
, NVL(a.bytes, 0) tablespace_size
, NVL(t.bytes, 0) used
, TRUNC(NVL(t.bytes / a.bytes * 100, 0)) used_pct
, NVL(s.current_users, 0) current_users
FROM
sys.dba_tablespaces d
, ( select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name
) a
, ( select tablespace_name, sum(bytes_cached) bytes
from v$temp_extent_pool
group by tablespace_name
) t
, v$sort_segment s
WHERE
d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = s.tablespace_name(+)
AND d.extent_management like 'LOCAL'
AND d.contents like 'TEMPORARY';
2.清理TEMP臨時(shí)表空間:(在無用戶連接的狀況下操作,最好在清理之前重啟一下數(shù)據(jù)庫)
復(fù)制代碼 代碼如下:
#重啟數(shù)據(jù)庫
sqlplus '/as sysdba'
SQL>shutdown immediate
SQL>startup
#創(chuàng)建一個(gè)臨時(shí)表空間temp02,用作臨時(shí)替換
SQL>create temporary tablespace temp02 tempfile '/u2/oradb/oradata/topprod/temp02.dbf' size 10M autoextend on next 10M;
#將系統(tǒng)臨時(shí)表空間指向temp02
SQL>alter database default temporary tablespace temp02;
#刪除原來的臨時(shí)表空間temp
SQL>drop tablespace temp including contents and datafiles;
#創(chuàng)建新的臨時(shí)表空間temp
SQL>create temporary tablespace temp tempfile '/u2/oradb/oradata/topprod/temp01.dbf' size 4096M autoextend on next 100M;
#將系統(tǒng)臨時(shí)表空間指回temp
SQL>alter database default temporary tablespace temp;
#刪除臨時(shí)表空間temp02
SQL>drop tablespace temp02 including contents and datafiles;
3.清理UNDO表空間:(在無用戶連接的狀況下操作,最好在清理之前重啟一下數(shù)據(jù)庫)
復(fù)制代碼 代碼如下:
#重啟數(shù)據(jù)庫
sqlplus '/as sysdba'
SQL>shutdown immediate
SQL>startup
#創(chuàng)建一個(gè)UNDO表空間undotbs2,用作臨時(shí)替換
SQL>create undo tablespace undotbs2 datafile '/u2/oradb/oradata/topprod/undotbs02.dbf' size 10M autoextend on next 10M;
#將系統(tǒng)UNDO表空間指向undotbs2
SQL>alter system set undo_tablespace=undotbs2 scope=both;
#確保所有在UNDOTBS1的undo segment都已offline
SQL> select SEGMENT_NAME ,STATUS ,TABLESPACE_NAME from dba_rollback_segs;
#刪除原來的UNDO表空間undotbs1
SQL>drop tablespace undotbs1 including contents and datafiles;
#創(chuàng)建新的臨時(shí)表空間undotbs1
SQL>create undo tablespace undotbs1 datafile '/u2/oradb/oradata/topprod/undotbs01.dbf' size 4096M;
#將系統(tǒng)UNDO表空間指回undotbs1
SQL>alter system set undo_tablespace=undotbs1 scope=both;
#刪除UNDO表空間undotbs2
SQL>drop tablespace undotbs2 including contents and datafiles;
3.清理TEMPTABS表空間:
復(fù)制代碼 代碼如下:
#刪除TEMPTABS表空間
SQL>drop tablespace temptabs including contents and datafiles;
#創(chuàng)建TEMPTABS表空間
SQL>create tablespace temptabs datafile '/u2/oradb/oradata/topprod/temptabs.dbf' size 4096M autoextend on next 100M;
或者刪除表
[code]
select 'drop table '||segment_name ||';' from dba_segments where tablespace_name='TEMPTABS' and segment_name like 'TT%' and segment_name not like '%_FILE';
4.增加系統(tǒng)表空間:
復(fù)制代碼 代碼如下:
alter tablespace SYSTEM add datafile '/u2/oradb/oradata/topprod/system02.dbf' size 2000M autoextend on next 10M;
alter tablespace SYSAUX add datafile '/u2/oradb/oradata/topprod/sysaux02.dbf' size 2000M autoextend on next 10M;
相關(guān)文章
ORA-12514及ORA-28547錯(cuò)誤解決方案
Oracle安裝好修改配置NET Manager就可以連接了卻出現(xiàn)了ORA-12514及ORA-28547錯(cuò)誤,本文將介紹如何解決2012-11-11查看oracle數(shù)據(jù)庫的編碼及修改編碼格式的方法
本節(jié)主要介紹了如何查看oracle數(shù)據(jù)庫的編碼及修改編碼格式,需要的朋友可以參考下2014-07-07Oracle 插入超4000字節(jié)的CLOB字段的處理方法
我們可以通過創(chuàng)建單獨(dú)的OracleCommand來進(jìn)行指定的插入,即可獲得成功,這里僅介紹插入clob類型的數(shù)據(jù),blob與此類似,這里就不介紹了,下面介紹兩種辦法2009-07-07Oracle數(shù)據(jù)庫表名支持的最大長度是多少
這篇文章主要介紹了Oracle數(shù)據(jù)庫表名支持的最大長度,本文通過Oracle標(biāo)識(shí)符確認(rèn)了表名的最大支持字符串為30個(gè)字符,需要的朋友可以參考下2014-08-08Oracle臨時(shí)表空間刪除和重建實(shí)現(xiàn)過程
這篇文章主要介紹了Oracle臨時(shí)表空間刪除和重建實(shí)現(xiàn)過程,臨時(shí)表空間是NOLOGGING模式以及它不保存永久類型對(duì)象,因此即使數(shù)據(jù)庫損毀,做Recovery也不需要恢復(fù)Temporary?Tablespace。下文更多詳細(xì)內(nèi)容介紹需要的小伙伴可以參考一下2022-03-03Windows下編寫批處理腳本來啟動(dòng)和重置Oracle數(shù)據(jù)庫
這篇文章主要介紹了Windows下編寫cmd腳本來對(duì)Oracle數(shù)據(jù)庫執(zhí)行啟動(dòng)和重置的方法,只需在bat文件中保存cmd shell之后就可以雙擊使用,簡單粗暴,需要的朋友可以參考下2016-03-03Oracle數(shù)據(jù)庫對(duì)象的使用詳解
這篇文章主要介紹了Oracle數(shù)據(jù)庫對(duì)象的使用,文章中涉及到的命令希望大家認(rèn)真學(xué)習(xí),對(duì)大家今后的工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-07-07Oracle SQL性能優(yōu)化系列學(xué)習(xí)一
Oracle SQL性能優(yōu)化系列學(xué)習(xí)一...2007-03-03