Reduce the Oracle system table space (SYSTEM, TEMP, UNDOTBS1, SYSAUX)

Reduce the Oracle system table space (SYSTEM, TEMP, UNDOTBS1, SYSAUX)

Technical label:  the Oracle   system table space   narrowing

 

First, the basic environment

      Operating System: Windows or Linux

      Database version: Oracle Database 11.2.0.1.0 and above

Second, to solve the problem

      With the growth in use of time, Oracle system table space (SYSTEM, TEMP, UNDOTBS1, SYSAUX) will become increasingly large, will lead to lack of system disk space. We need regular maintenance to ensure the security and stability of the database to run the database and improve database efficiency.

Three steps

       Note: The following steps apply only to Windows or Linux need to be modified for different operating systems file path format

       1, reduce the temporary table space (that contains the system TEMP temporary table space and user-created temporary table space) size

       a) Log on to the DBA SQL plus;

sqlplus / as sysdba;
 

      b) Execute the following SQL statement: 100M If you feel too small which can be re-set themselves. Temporary table space is generally automatic extension.

SELECT 'ALTER TABLESPACE '||TABLESPACE_NAME ||' SHRINK SPACE KEEP 100M;' FROM DBA_TEMP_FILES;
 

      c) Copy the query results to SQL plus there can be executed.

      d) completion. The method tested in a production environment without problems.

      2, table space reduction system (SYSTEM means tablespace)

      a) Log on to the DBA SQL Plus;

sqlplus / as sysdba;
 

     b) reduce the need to query the table space FILE_ID corresponding data file. According FILE_ID FILE_NAME determine the need to narrow the data file

  1.  
    SELECT FILE_ID, FILE_NAME
  2.  
    FROM DBA_DATA_FILES
  3.  
    WHERE TABLESPACE_NAME = 'SYSTEM';

     c) the maximum position query data block in the data file where the data

 SELECT MAX(BLOCK_ID)*8/1024 FROM DBA_EXTENTS WHERE FILE_ID=1;
 

     d) 查询结果为:721.4375 即:该数据文件中数据所在的数据块的最大位置为 721.4375MB 处。

     e) 修改该数据文件的尺寸。根据需要调整数据文件的大小,但是不能低于上一步骤的查询值。数据文件的路径为步骤 b) 的FILE_NAME 值。

ALTER DATABASE DATAFILE 'D:\PROGRAMFILES\ORACLE\ORADATA\ORCL\SYSTEM01.DBF' RESIZE 750M;
 

      f)  完成。该方法为通用方法,即适用于其他表空间。

      3、缩小UNDOTBS 表空间 

      a) UNDOTBS 表空间的作用为:(1)、 Read Consistent(一致性读)(2)、Transaction Rollback(事务回滚)(3)、Transaction Recovery(事务恢复)时间越长,该表空间可能越大,但表空间只用于临时存储所以可以清理。可以通过创建新的UNDO 表空间替换旧的 UNDO 表空间。

     b) 以 DBA 的身份登陆SQL Plus ;

sqlplus / as sysdba;
 

    c) 创建一个新的 UNDO 表空间

  1.  
    CREATE UNDO TABLESPACE UNDOTBS2
  2.  
    DATAFILE 'D:\PROGRAMFILES\ORACLE\ORADATA\ORCL\UNDOTBS2.DBF'
  3.  
    SIZE 100M
  4.  
    REUSE AUTOEXTEND ON;

   d) 设置新的 UNDO 表空间为系统的 UNDO 表空间

ALTER SYSTEM SET UNDO_TABLESPACE=UNDOTBS2;
 

  e)重启数据库,以下命令相当于 shutdown abort + startup

STARTUP FORCE
 

   f) 删除旧的 UNDO 表空间及数据文件

DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
 

  g) 至此,UNDOTBS01 表空间缩减完毕。如果想要还原原来的表空间名称,重新执行该方法即可。

参考资料:

1、https://yq.aliyun.com/articles/518452

2、https://www.cnblogs.com/tyler2000/archive/2011/01/21/1940904.html

3、https://www.jianshu.com/p/29651bace851

Guess you like

Origin www.cnblogs.com/yaoyangding/p/12595637.html