美文网首页
oracle 表 迁移到其它表空间

oracle 表 迁移到其它表空间

作者: 数据老菜鸟 | 来源:发表于2023-01-20 04:20 被阅读0次

        默认用户是使用Users表空间的,我们如果没有指定用户默认表空间,会导致USERs很快爆满,

    这个时候就需要对用户已经创建的表进行迁移

    1.创建表空间

    create tablespace TS_PBDATARMS

    datafile '/opt/data/oracle/app/oracle/oradata/TS_PBDATARMS.dbf'

    size 1280m

    autoextend on next 256m maxsize UNLIMITED

    permanent

    extent management local;

    2.指定用户的默认表空间

    alter user APP_PBDATARMS default tablespace TS_PBDATARMS;

    3. 将现有表迁移到新的表空间中去

    --第1类:移动【表】所在表空间:如将表table_name 移动到新的new_tbsp表空间

    alter table  table_name move tablespace new_tbsp;

    --生成指定tbsp_name表空间下的【所有表】生成移动new_tbsp表空间SQL语句

    select 'alter table '|| table_name|| ' move tablespace new_tbsp;' from user_tables where tablespace_name = 'tbsp_name'

    --第2类:移动【索引】所在表空间:如将索引index_name 移动到新的new_tbsp表空间(LOB数据类型的字段需按如下第3类处理)

    alter index index_name rebuild tablespace new_tbsp;

    --生成指定user_name用户下的【所有索引】生成移动new_tbsp表空间SQL语句

    select 'alter index '||index_name||' rebuild tablespace new_tbsp;' from user_indexes where table_owner = 'user_name'

    --第3类:移动【二进制流字段】数据存储表空间,如将表table_name中的二进制流字段col_name移动到new_tbsp表空间

    alter table table_name move tablespace new_tbsp  lob (col_name) store as  (tablespace new_tbsp);

    --生成指定表table_name中为CLOB类型的字段的移动到new_tbsp 表空间SQL语句

    select 'alter table '|| table_name||' move tablespace new_tbsp lob ('|| column_name||' ) store as  (tablespace new_tbsp);'  from user_tab_columns

    where  data_type='CLOB' and table_name='table_name'

    相关文章

      网友评论

          本文标题:oracle 表 迁移到其它表空间

          本文链接:https://www.haomeiwen.com/subject/uaracdtx.html