设为首页 收藏本站
查看: 559|回复: 0

[经验分享] Oracle 11g Shrink Temporary Tablespace and Temporary Table Enhancement(原创)

[复制链接]

尚未签到

发表于 2016-8-4 11:56:26 | 显示全部楼层 |阅读模式
  Shrinking Temporary Tablespaces
When a large job that uses a temporary tablespace finishes executing, the database doesn’t immediately release the space used by the job in the temporary tablespace, even after the job completes. You can get the free space back faster sometimes by dropping the temporary tablespace and creating a smaller one instead, but then it may not be easy to do this on a live database because users may require the temporary tablespace for various operations. Oracle Database 11g lets you shrink a locally managed temporary tablespace online, thus enabling you to control the space allocated to temporary operations in the database. You can shrink both temporary tablespaces and individual tempfiles.
Use the shrink space clause within an alter tablespace command to shrink a temporary tablespace, as shown here:
SQL> alter tablespace temp shrink space;
To shrink a tempfile, use the shrink tempfile clause, as shown here:
SQL> alter tablespace temp shrink
     tempfile '/u01/app/oracle/oradata/or11/temp01.dbf';
The shrink space command in the first example shrinks all tempfiles to a database-determined minimum size, 1 MB. The database takes into account the temporary tablespace storage requirements when determining the minimum size of the tempfiles. You can override this default behavior by specifying a minimum size for the temporary tablespace after a shrink operation, as shown here:
SQL> alter tablespace temp shrink space keep 100m;
The keep clause lets you specify the minimum value for the temporary tablespace named TEMP. The following examples illustrate how Oracle approaches a temporary tablespace shrinking operation. In this example, the temporary tablespace TEMP has two tempfiles, each sized at 1 GB, thus making the total size of the temporary tablespace 2 GB. You issue the following alter tablespace statement to shrink the temporary tablespace to 1 GB.
SQL> alter tablespace temp shrink space keep 1000m;
Tablespace altered.
Because the combined size of the two tempfiles in the TEMP tablespace is 2 GB, you’d assume that Oracle would shrink both tempfiles to about 500 MB each, to get a total of 1 GB, when you issue the alter tablespace statement shown here. However, this isn’t what happens, as you can see by issuing the following query:
SQL> select file#, name, bytes/1024/1024 MB from v$tempfile;
FILE#   NAME                                           MB
------  ------------------------------------        --------
1      /u01/app/oracle/temp/temp01.dbf              999.9375
2      /u01/app/oracle/temp/temp02.dbf
Oracle does shrink the TEMP tablespace from 2 GB to 1 GB, but not by shrinking both tempfiles by an equal amount. It shrinks the file temp01.dbf by less than 1 MB and the file temp02.dbf by over 999 MB. You can specify a minimum space that the database must retain in a specific tempfile, by specifying the keep clause in the alter tablespace . . . shrink statement, as follows:
SQL> alter tablespace temp shrink space
     tempfile '/u01/app/oracle/temp02.dbf'
     keep 500m;
Tablespace altered.
This statement will shrink just the datafile temp02 and leave the other tempfiles in the tablespace alone.
You can query the new DBA_TEMP_FREE_SPACE view to get information about temporary tablespace usage, as shown in this example:
SQL> select * from dba_temp_free_space;
TABLESPACE_NAME  TABLESPACE_SIZE  ALLOCATED_SPACE  FREE_SPACE
---------------  ---------------  ---------------  -----------
TEMP             41943040         41943040         40894464
The column definiton as following:
  TABLESPACE_SIZE NUMBER: Total size of the tablespace, in bytes
ALLOCATED_SPACE NUMBER: Total allocated space, in bytes, including space that is currently allocated and used and space that is currently allocated and available for reuse
FREE_SPACE NUMBER: Total free space available, in bytes, including space that is currently allocated and available for reuse and space that is currently unallocated
Tablespace Option for Creating Temporary Tables
When you created a global temporary table in Oracle Database 10g, you didn’t have to specify a tablespace. In Oracle Database 11g, you can specify a tablespace clause when creating a temporary table. If you omit the tablespace clause, the database creates the global temporary table in the default temporary tablespace for the database. The database also stores the indexes you create on the global temporary table in the same tablespace as the temporary table, you can't designate other tablespace for tempoary index.
The ability to specify the tablespace when creating a global temporary table means that you can now assign a proper extent size for a temporary table to deal with its sort usage. Different tables might use the temporary space differently, and the capability to assign different extent sizes to them leads to better performance.
  
  参 考至: 《McGraw.Hill.OCP.Oracle.Database.11g.New.Features.for.Administrators.Exam.Guide.Apr.2008》
  《Oracle® Database Reference 11g Release 1 (11.1)》
  http://www.oracle-base.com/articles/11g/temporary-tablespace-enhancements-11gr1.php
  本文原创,转载请注明出处、作者
  如有错误,欢迎指正
  邮箱:czmcj@163.com

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-252719-1-1.html 上篇帖子: Access数据迁移到Oracle的java代码 下篇帖子: Oracle调优总结--1(经典实践 重要)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表