您的位置:首页 > 数据库 > Oracle

oracle RAC调整数据文件大小并移动表到指定的表空间

2015-03-28 17:04 477 查看
一、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';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐