ORACLE碎片整理 (2)
2024-08-29 13:42:36
供稿:網友
4、自由范圍的碎片整理
1)表空間的 pctincrease 值為非 0
可以將表空間的缺省存儲參數 pctincrease 改為非 0 。一般將其設為 1 ,如:
alter tablespace temp
default storage(pctincrease 1);
這樣 SMON 便會將自由范圍自動合并。也可以手工合并自由范圍:
alter tablespace temp coalesce;
5、段的碎片整理
我們知道,段由范圍組成。在有些情況下,有必要對段的碎片進行整理。要查看段的有關信息,可查看數據字典 dba_segments ,范圍的信息可查看數據字典 dba_extents 。假如段的碎片過多,將其數據壓縮到一個范圍的最簡單方法便是用正確的存儲參數將這個段重建,然后將舊表中的數據插入到新表,同時刪除舊表。這個過程可以用 Import/EXPort (輸入 / 輸出)工具來完成。
Export ()命令有一個(壓縮)標志,這個標志在讀表時會引發 Export 確定該表所分配的物理空間量,它會向輸出轉儲文件寫入一個新的初始化存儲參數 -- 等于全部所分配空間。若這個表關閉, 則使用 Import ()工具重新生成。這樣,它的數據會放入一個新的、較大的初始段中。例如:
exp user/passWord file=exp.dmp comPRess=Y grants=Y indexes=Y
tables=(table1,table2); 若輸出成功,則從庫中刪除已輸出的表,然后從輸出轉儲文件中輸入表:
imp user/password file=exp.dmp commit=Y buffer=64000 full=Y
這種方法可用于整個數據庫。
以上簡單分析了 Oracle 數據庫碎片的產生、計算方法及整理,僅供參考。數據庫的性能優化是一項技術含量高,同時又需要有足夠耐心、認真細致的工作。 對數據庫碎片的一點探討,
回復: ORACLE碎片整理[轉帖]
下面是一種如何自動處理表空間碎片的代碼,希望對上大家看上文有用
Coalesce Tablespace Automatically This technique comes from Sandeep Naik, a database administrator for GSXXI, Inc. in New York City, New York Here is a handy script which can be scheduled to automatically run and coalesces the tablespaces. This script is designed to run in NT but can be run in any Operating system by slight modifications in the path where the file spools from the SQLPLUS environment. It assumes that the user who runs the script has priviledges to view the data dictionary. Start of code -------------------------------------- sqlplus / prompt this script will coalesce the tablespace automatically set verify off; set termout off; set head off; spool c: empcoalesce.log select alter tablespace TABLESPACE_NAME coalesce ; from DBA_FREE_SPACE_COALESCED where PERCENT_EXTENTS_COALESCED <100 or PERCENT_BLOCKS_COALESCED<100 ; spool off; @ c: empcoalesce.log set head on; set termout on; set verify on; prompt Tablespaces are coalesced sUCcessfully