zoukankan      html  css  js  c++  java
  • ArcSDE for Oracle表空间管理——暂时(TEMP)表空间



    Oracle暂时表空间主要用来做查询和存放一些缓冲区数据。暂时表空间消耗的主要原因是须要对查询的中间结果进行排序。


    重新启动数据库能够释放暂时表空间,假设不能重新启动实例,而一直保持问题sql语句的运行,temp表空间会一直增长。直到耗尽硬盘空间。


    下面操作会占用大量的temporary:
        1、用户运行imp/exp 导入导出操作时,会使用大量的temporary段
        2、用户在Create 或者 rebuild index时
        3、运行create table ...... as 语句时
        4、移动用户下的数据到别的表空间时
        5、用户运行排序Order by 或 group by
        6、用户运行Distinct 操作
        7、用户运行Union 或 intersect 或 minus
        8、用户运行Sort-merge joins
        9、用户运行analyze


    对ArcGIS用户来说,进行Oracle逻辑迁移、重建空间索引、空间数据与属性数据的关联等操作都会使用到Oracle的暂时表,特别是假设有数据量比較大的空间数据重建空间索引,会使用PGA内存,假设该内存资源不足就会使用暂时表空间资源,所以暂时表空间的管理对用户来说也是比較重要的。


    普通情况下,创建Oracle库之后默认有一个暂时表空间TEMP,默认大小是30MB,在创建数据库用户时,都会为该用户设置一个暂时表空间,那么该用户所做的以上某些操作自然会在占用暂时表空间的资源。那么假设是OLTP系统,多个用户都在进行不同的操作,势必会带来暂时表空间资源的占用。所以非常多用户能够创建了多个表空间,依据用户业务类型分配对应的暂时表空间大小。对于大型操作频繁(大型查询,大型分类查询,大型统计分析等),应指定单独的比較大容量的暂时表空间,当然我们也能够创建暂时表空间组来让Oracle自己主动合理分配暂时表空间资源。


    暂时表空间组就是创建多个暂时表空间数据文件,然后将这些暂时表空间组成一个暂时表空间组,设置Oracle的默认暂时表空间,那么创建用户设置的暂时表空间也为该暂时表空间组,让Oracle自己主动管理暂时表空间资源。

    下面为oracle官方帮助:

    A tablespace group enables a user to consume temporary space from multiple tablespaces. Using a tablespace group, rather than a single temporary tablespace, can alleviate problems caused where one tablespace is inadequate to hold the results of a sort, particularly on a table that has many partitions. A tablespace group enables parallel execution servers in a single parallel operation to use multiple temporary tablespaces.

    ----------------------------------------------------------------------------------

    版权全部,文章同意转载,但必须以链接方式注明源地址,否则追究法律责任!

    Blog:               http://blog.csdn.net/linghe301

    ----------------------------------------------------------------------------------


    下面就实践一下创建暂时表空间组


    查明默认的暂时表空间信息

    SQL> select tablespace_name from dba_tablespaces;
    
    TABLESPACE_NAME
    ------------------------------
    SYSTEM
    SYSAUX
    UNDOTBS1
    TEMP
    USERS
    EXAMPLE
    SDE
    ESRI
    ESRI2
    TEST
    
    已选择10行。
    创建多个暂时表空间数据文件
    SQL> create temporary tablespace temp2 tempfile 'E:APPADMINISTRATORORADATAORCL	emp02.dbf' size 10M;
    
    表空间已创建。
    
    SQL> create temporary tablespace temp3 tempfile 'E:APPADMINISTRATORORADATAORCL	emp03.dbf' size 10M;
    
    表空间已创建。
    
    SQL> create temporary tablespace temp4 tempfile 'E:APPADMINISTRATORORADATAORCL	emp04.dbf' size 10M;
    
    表空间已创建。
    
    SQL> select name from v$tempfile;
    
    NAME
    --------------------------------------------------------------------------------
    E:APPADMINISTRATORORADATAORCLTEMP01.DBF
    E:APPADMINISTRATORORADATAORCLTEMP02.DBF
    E:APPADMINISTRATORORADATAORCLTEMP03.DBF
    E:APPADMINISTRATORORADATAORCLTEMP04.DBF
    加入暂时表空间组
    SQL> alter tablespace temp tablespace group temp_group;
    
    表空间已更改。
    
    SQL> alter tablespace temp2 tablespace group temp_group;
    
    表空间已更改。
    
    SQL> alter tablespace temp3 tablespace group temp_group;
    
    表空间已更改。
    
    SQL> alter tablespace temp4 tablespace group temp_group;
    
    表空间已更改。
    
    SQL> select * from dba_tablespace_groups;
    
    GROUP_NAME                     TABLESPACE_NAME
    ------------------------------ ------------------------------
    TEMP_GROUP                     TEMP
    TEMP_GROUP                     TEMP2
    TEMP_GROUP                     TEMP3
    TEMP_GROUP                     TEMP4
    设置暂时表空间为暂时表空间组
    SQL> alter database default temporary tablespace temp_group;
    
    数据库已更改。
    
    SQL> select temporary_tablespace from dba_users where username='SDE';
    
    TEMPORARY_TABLESPACE
    ------------------------------
    TEMP_GROUP

    ----------------------------------------------------------------------------------

    版权全部,文章同意转载,但必须以链接方式注明源地址,否则追究法律责任!

    Blog:               http://blog.csdn.net/linghe301

    ----------------------------------------------------------------------------------


    关于暂时表空间的问题:

    非常多用户会发如今使用暂时表空间时,假设操作任务完毕之后,系统不会自己主动清理暂时表空间的资源。


    能够通过Oracle11g新增的DBA_TEMP_FREE_SPACE视图来查看暂时表空间的占用率和空暇率

    SQL> select * from DBA_TEMP_FREE_SPACE;
    
    TABLESPACE_NAME                TABLESPACE_SIZE ALLOCATED_SPACE FREE_SPACE
    ------------------------------ --------------- --------------- ----------
    TEMP                                  32497664         2088960   31457280
    TEMP4                                 10485760         2097152    9437184
    TEMP3                                 10485760         4194304    7340032
    TEMP2                                 10485760         3145728    9437184
    
    
    SQL> select allocated_space*100/tablespace_size as used from DBA_TEMP_FREE_SPACE;
    
          USED
    ----------
    6.42803126
            20
            40
            30


    假设TEMPORARY TABLESPACE的类型是TEMPORARY,TEMPORARY TABLESPACE里的使用过的空间是不会被释放的,除非shutdown。


    假设使用TEMPORARY类型的暂时表空间,数据库刚刚startup后,第一个使用TEMPORARY tablespace进行排序的statement会创一个建sort segment,这个segment不会被释放,除非数据库restart,能够用V$SORT_SEGMENT察看当前的已分配了的sort segments地使用情况。


    假设暂时表空间的类型为PERMANENT,SMON会在process不再使用暂时段之后去做清理。


    假设是用PERMANENT tablespace作排序,由smon负责在statement结束之后删除被创建的temporary segments,这样空间能够被其他对象使用。

    考虑到性能原因,当一个temporary extent被分配的时候,tablespace会做一个标记,操作结束之后这个extent不会被释放或回收,对应的,这个extent被简单的标志为free,对于后面的sort操作是available的,这样就省去了系统分配和回收temporary extent的负载。建议都是用暂时类型。


    当然,在Oracle11g版本号用户也能够使用ALTER TABLESPACE SHRINK 命令对暂时表空间为释放的资源进行Shrink。

    ----------------------------------------------------------------------------------

    版权全部,文章同意转载,但必须以链接方式注明源地址,否则追究法律责任!

    Blog:               http://blog.csdn.net/linghe301

    ----------------------------------------------------------------------------------


    參考Oracle帮助文档:

    Shrinking a Locally Managed Temporary Tablespace

    Large sort operations performed by the database may result in a temporary tablespace growing and occupying a considerable amount of disk space. After the sort operation completes, the extra space is not released; it is just marked as free and available for reuse. Therefore, a single large sort operation might result in a large amount of allocated temporary space that remains unused after the sort operation is complete. For this reason, the database enables you to shrink locally managed temporary tablespaces and release unused space.

    You use the SHRINK SPACE clause of the ALTER TABLESPACE statement to shrink a temporary tablespace, or the SHRINK TEMPFILE clause of the ALTER TABLESPACE statement to shrink a specific temp file of a temporary tablespace. Shrinking frees as much space as possible while maintaining the other attributes of the tablespace or temp file. The optional KEEP clause defines a minimum size for the tablespace or temp file.

    Shrinking is an online operation, which means that user sessions can continue to allocate sort extents if needed, and already-running queries are not affected.

    The following example shrinks the locally managed temporary tablespace lmtmp1 while ensuring a minimum size of 20M.

    ALTER TABLESPACE lmtemp1 SHRINK SPACE KEEP 20M;
    

    The following example shrinks the temp file lmtemp02.dbf of the locally managed temporary tablespace lmtmp2. Because the KEEP clause is omitted, the database attempts to shrink the temp file to the minimum possible size.

    ALTER TABLESPACE lmtemp2 SHRINK TEMPFILE '/u02/oracle/data/lmtemp02.dbf';

    默认能够不带KEEP參数,假设忽略KEEP 子句,则仅仅要满足其他存储属性,数据库就会尽可能尝试收缩表空间/暂时文件(全部当前使用的区的总空间),假设使用KEEP參数建议KEEP大小不能超过所操作暂时表空间的最大值。假设该表空间对象參与了暂时表空间组也适用于该命令。


    注意:暂时表空间过大或者过小都会对数据库性能有直接影响,所以建议在Shrink暂时表空间都是用KEEP參数。


    參考文献:

    http://blog.chinaunix.net/uid-21267700-id-3295645.html

    http://blog.csdn.net/tianlesoftware/article/details/8225395

    ----------------------------------------------------------------------------------

    版权全部,文章同意转载,但必须以链接方式注明源地址,否则追究法律责任!

    Blog:               http://blog.csdn.net/linghe301

    ----------------------------------------------------------------------------------



  • 相关阅读:
    移动端底部fixed固定定位输入框ios下不兼容
    mint-ui Picker设置指定初始值
    vue项目的mode:history模式
    更改checkbox的默认样式
    vue组件通信的几种方式
    Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案
    ActionFilterAttribute之HtmlFilter,压缩HTML代码
    MongoDB C#驱动中Query几个方法
    无需路由端口映射 花生壳6.5工程版发布
    如何让搜索引擎抓取AJAX内容?
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3820992.html
Copyright © 2011-2022 走看看