【临时表空间】11g中使用 SHRINK方法缩小临时表空间和临时文件(续)

在文章《【临时表空间】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 --
请使用浏览器的分享功能分享到微信等