標籤:
一、Oracle RAC 調整資料表空間資料檔案大小
1、先尋找出資料表空間對應的資料檔案路徑:
select file_name,tablespace_name from dba_data_files ;
2、確認目前資料檔案的大小即資料表空間的大小
select tablespace_name ,sum(bytes)/1024/1024 total from dba_data_files 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、通過預設參數pctfree=10%,pctused確定資料表空間的大小是否滿足後續的使用
5、通過調整資料檔案的大小來增加資料表空間
alter database datafile ‘+DATA1/ora11g/datafile/system.262.760023469‘ resize 3G;
6、確認資料表空間大小是否更改成功
二、移動表到指定的資料表空間
1、首先,使用下面的命令移動:
alter table table_name move tablespace tablespace_name;
2、然後,如果有索引的話必須重建索引:
alter index index_name rebuild tablespace tablespace_name;
註:當然,可以使用spool來協助實現多個表的操作.
set header off;
spool /export/home/oracle/alter_tables.sql;
select ‘alter table ‘ || object_name || ‘ move tablespace users‘
from dba_object
where owner = ‘XXX‘ and object_type = ‘TABLE‘;
spool off;
之後執行此sql指令碼即可.
同樣對於index也做同樣的操作.
如果要使用sql指令碼批量執行的話可能會丟失一下索引資訊,使得原來建立在別的資料表空間上的 索引失效
三、批量處理的方法步驟:
首先考慮使用shell執行sql指令碼,產生對應的批量執行sql指令碼,然後再執行sq指令碼。
1、changeSpace.sql指令碼:這個主要是產生對應的Alter語句
set echo off set feedback off set newpage none set verify off set term off set trims on set heading off set timing off set verify off spool AlterchangeSpace.sql select ‘alter table ‘||owner||‘.‘||table_name||‘ move ‘||‘ tablespace ‘||‘ FAB ‘||‘;‘ from ( select * from dba_tables where owner=‘FAB‘ and tablespace_name not in (‘FAB‘) ); spool off 2、執行changeSpace.sql的指令碼changeSpaceFirst.sh: echo "begin `date ‘+%Y%m%d %H:%M:%S‘`" . ${HOME}/yz/env.sh . ${MIGRATE_PATH}/cfg/par_set.sh if [ $? -eq 1 ] then echo "初始化環境ERROR!" return 1 fi sqlplus $dbusr/[email protected]$dbsid << ! @changeSpace.sql; exit ! echo "end `date ‘+%Y%m%d %H:%M:%S‘`" 此時產生了對應的AlterChangeSpace.sql指令碼: 3、利用changeSpaceSecond.sh執行AlterChangeSpace.sql指令碼: echo "begin `date ‘+%Y%m%d %H:%M:%S‘`" . ${HOME}/yz/env.sh . ${MIGRATE_PATH}/cfg/par_set.sh if [ $? -eq 1 ] then echo "初始化環境ERROR!" return 1 fi sqlplus $dbusr/[email protected]$dbsid << ! @AlterchangeSpace.sql; exit ! echo "end `date ‘+%Y%m%d %H:%M:%S‘`" 註:基於原來資料表空間的建立在移動表上的索引必須重建 alter index index_name rebuild tablespace tablespace_name; 批量執行索引的重建方法類似於批量移動表 產生alter的select語句如下; select ‘alter index ‘|| t.object_name ||‘ rebuild tablespace FAB;‘ from dba_objects t,dba_indexes q where t.owner=‘FAB‘ and t.object_type=‘INDEX‘ and q.index_name=t.object_name and q.index_type!=‘LOB‘;
oracle RAC調整資料檔案大小並移動表到指定的資料表空間