zoukankan      html  css  js  c++  java
  • oracle RAC调整数据文件大小并移动表到指定的表空间

    一、Oracle RAC 调整表空间数据文件大小

      1、先查找出表空间对应的数据文件路径:

      select file_name,tablespace_name from dba_data_files ;

      2、确认目前数据文件的大小即表空间的大小

      select tablespace_name ,sum(bytes)/1024/1024 total from dba_data_files group by tablespace_name;

      3、查看表空间的目前使用情况

        select a.tablespace_name,total,free,total-free used from
        ( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files
          group by tablespace_name) a,
        ( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space
          group by tablespace_name) b
        where a.tablespace_name=b.tablespace_name

      4、通过默认参数pctfree=10%,pctused确定表空间的大小是否满足后续的使用

      5、通过调整数据文件的大小来增加表空间

      alter database datafile '+DATA1/ora11g/datafile/system.262.760023469' resize 3G;

      6、确认表空间大小是否更改成功

    二、移动表到指定的表空间

      1、首先,使用下面的命令移动:

      alter table table_name move tablespace tablespace_name;

      2、然后,如果有索引的话必须重建索引:

      alter index index_name rebuild tablespace tablespace_name;

      注:当然,可以使用spool来帮助实现多个表的操作.
        set header off;
        spool /export/home/oracle/alter_tables.sql;
        select 'alter table   ' || object_name || '  move tablespace users'
        from dba_object
        where owner = 'XXX' and object_type = 'TABLE';
        spool off;
      之后执行此sql脚本即可.
      同样对于index也做同样的操作.

      如果要使用sql脚本批量执行的话可能会丢失一下索引信息,使得原来建立在别的表空间上的 索引失效

    三、批量处理的方法步骤:

      首先考虑使用shell执行sql脚本,生成对应的批量执行sql脚本,然后再执行sq脚本。

      1、changeSpace.sql脚本:这个主要是生成对应的Alter语句

        set echo off
        set feedback off
        set newpage none
        set verify off
        set term off
        set trims on
        set heading  off
        set timing off
        set verify off
        spool AlterchangeSpace.sql
      
        
        select 'alter table  '||owner||'.'||table_name||'  move '||' tablespace '||' FAB '||';' from (
          select * from dba_tables where owner='FAB' and tablespace_name not in ('FAB')
        ); 
        spool off
        
        2、执行changeSpace.sql的脚本changeSpaceFirst.sh:
        
          echo "begin `date '+%Y%m%d %H:%M:%S'`"
          . ${HOME}/yz/env.sh
          . ${MIGRATE_PATH}/cfg/par_set.sh
          if [ $? -eq 1 ]
          then
          echo "初始化环境ERROR!"
          return 1
          fi
     
          sqlplus $dbusr/$dbpwd@$dbsid << !
     
          @changeSpace.sql;
     
          exit
          !
          echo "end `date '+%Y%m%d %H:%M:%S'`"
        此时生成了对应的AlterChangeSpace.sql脚本:
      3、利用changeSpaceSecond.sh执行AlterChangeSpace.sql脚本:
        
          echo "begin `date '+%Y%m%d %H:%M:%S'`"
          . ${HOME}/yz/env.sh
          . ${MIGRATE_PATH}/cfg/par_set.sh
          if [ $? -eq 1 ]
          then
          echo "初始化环境ERROR!"
          return 1
          fi
     
          sqlplus $dbusr/$dbpwd@$dbsid << !
     
          @AlterchangeSpace.sql;
     
          exit
          !
          echo "end `date '+%Y%m%d %H:%M:%S'`"
      注:基于原来表空间的建立在移动表上的索引必须重建
        alter index index_name rebuild tablespace tablespace_name;
        批量执行索引的重建方法类似于批量移动表
        生成alter的select语句如下;
     
        select 'alter index '|| t.object_name ||' rebuild tablespace FAB;' from dba_objects t,dba_indexes q
          where t.owner='FAB'
            and t.object_type='INDEX'  
            and q.index_name=t.object_name
            and q.index_type!='LOB';
     

     

  • 相关阅读:
    VUE笔记-如何处理vue create demo时候,不能使用上下按键选择?
    帝国CMS之PC端上新栏目后,移动端无法同步,添加内容编辑页打开空白的处理方法
    帝国cms:迁移站点后,配置多端访问显示“访问端目录不存在”
    如何批量删除帝国CMS中同一前缀的数据表?
    宝塔插件"网站监控报表"错误日志显示大量不存在的链接,处理方法及流程
    mysql删除重复数据只保留一条
    VirtualBox 中 discuzq不能添加软链接的处理方法
    mysql8 source 导入大文件时 经常意外中断 且无法再链接断续 解决方法先设置 set names utf8;
    discuzq Virtualbox 虚拟机 在共享文件夹设置软链接 in 报错 Protocol error问题
    是的,奈学教育一周年了!
  • 原文地址:https://www.cnblogs.com/moonfans/p/4374466.html
Copyright © 2011-2022 走看看