【臨時表空間】11g中使用 SHRINK方法縮小臨時表空間和臨時檔案(續)

secooler發表於2010-05-16
在文章《【臨時表空間】11g中使用 SHRINK方法縮小臨時表空間和臨時檔案》(http://space.itpub.net/519536/viewspace-662833)中介紹了包含一個臨時檔案的臨時表空間的SHRINK方法,如果臨時表空間包含多個臨時檔案,效果會是什麼樣子呢?

1.系統當前臨時表空間的臨時檔案資訊
sys@11gR2> select file#,name,bytes/1024/1024 MB from v$tempfile;

     FILE# NAME                                                 MB
---------- -------------------------------------------- ----------
         1 /oracle/ora11gR2/oradata/secooler/temp01.dbf 10.9921875

2.在此基礎上為臨時表空間temp增加兩個臨時檔案
sys@11gR2> alter tablespace temp add tempfile '/oracle/ora11gR2/oradata/secooler/temp02.dbf' size 20m;

Tablespace altered.

sys@11gR2> alter tablespace temp add tempfile '/oracle/ora11gR2/oradata/secooler/temp03.dbf' size 20m;

Tablespace altered.

3.此時臨時表空間temp包含三個臨時檔案
sys@11gR2> select file#,name,bytes/1024/1024 MB from v$tempfile;

     FILE# NAME                                                 MB
---------- -------------------------------------------- ----------
         1 /oracle/ora11gR2/oradata/secooler/temp01.dbf 10.9921875
         2 /oracle/ora11gR2/oradata/secooler/temp02.dbf         20
         3 /oracle/ora11gR2/oradata/secooler/temp03.dbf         20

4.使用預設的臨時表空間收縮方法
sys@11gR2> alter tablespace temp shrink space;

Tablespace altered.

sys@11gR2> select file#,name,bytes/1024/1024 MB from v$tempfile;

     FILE# NAME                                                 MB
---------- -------------------------------------------- ----------
         1 /oracle/ora11gR2/oradata/secooler/temp01.dbf  1.9921875
         2 /oracle/ora11gR2/oradata/secooler/temp02.dbf  1.9921875
         3 /oracle/ora11gR2/oradata/secooler/temp03.dbf  1.9921875

可見,每個臨時檔案都被縮小到了不到2M的大小。

5.調整每個臨時檔案大小到200M
sys@11gR2> alter database tempfile '/oracle/ora11gR2/oradata/secooler/temp01.dbf' resize 200m;

Database altered.

sys@11gR2> alter database tempfile '/oracle/ora11gR2/oradata/secooler/temp02.dbf' resize 200m;

Database altered.

sys@11gR2> alter database tempfile '/oracle/ora11gR2/oradata/secooler/temp03.dbf' resize 200m;

Database altered.

sys@11gR2> select file#,name,bytes/1024/1024 MB from v$tempfile;

     FILE# NAME                                                 MB
---------- -------------------------------------------- ----------
         1 /oracle/ora11gR2/oradata/secooler/temp01.dbf        200
         2 /oracle/ora11gR2/oradata/secooler/temp02.dbf        200
         3 /oracle/ora11gR2/oradata/secooler/temp03.dbf        200

6.我們使用包含keep子句的shrink命令收縮臨時表空間
sys@11gR2> alter tablespace temp shrink space keep 100m;

Tablespace altered.

sys@11gR2> select file#,name,bytes/1024/1024 MB from v$tempfile;

     FILE# NAME                                                 MB
---------- -------------------------------------------- ----------
         1 /oracle/ora11gR2/oradata/secooler/temp01.dbf  97.015625
         2 /oracle/ora11gR2/oradata/secooler/temp02.dbf  1.9921875
         3 /oracle/ora11gR2/oradata/secooler/temp03.dbf  1.9921875

從結果上可以看出,Oracle將逐一的將臨時表空間中包含的臨時檔案進行收縮,直到臨時檔案大小總和為100M為止(注意,不是“平均收縮”)。

7.小結
在本例中,只是簡單展示了一下使用包含keep語句的收縮臨時表空間的效果。在生產環境中,建議使用指定具體臨時檔案進行收縮的方法完成臨時表空間的收縮。

Good luck.

secooler
10.05.16

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-662835/,如需轉載,請註明出處,否則將追究法律責任。

相關文章