Welcome 微信登录

首页 / 数据库 / MySQL / 关于move table和rebuild index批量操作的记录

批量move oldtablespace表空间下的table到newtablespace,查询并执行查询结果即可select "alter table "||table_name||" move tablespace newtablespace"from user_all_tables where table_space="oldtablespace";批量rebuild oldtablespace表空间下的index到newtablespace,查询并执行查询结果即可select "alter index "|| index_name || " rebuild  tablespace newtablespace;"
 from user_indexes
 where  tablespace_name="oldtablespace" ;带有lob字段的表做move时lob字段需要单独moveALTER TABLE AUDIT_RECORD MOVE LOB(lobrow1) STORE AS (TABLESPACE newtablespace);ALTER TABLE AUDIT_RECORD MOVE LOB(lobrow2) STORE AS (TABLESPACE newtablespace);
 ALTER TABLE AUDIT_RECORD MOVE TABLESPACE newtablespace; 或者
ALTER TABLE test2 MOVE              TABLESPACE users                  LOB (lobrow1) STORE AS lobsegment              (TABLESPACE newtablespace);另外exp/imp迁移带有lob字段的  在执行IMP时需要将原lob字段所在的tablespace建好再导入,导入后再考虑move到其他tablespaceexped/imped可以用remap_tablespace参数指定将数据导入到指定的表空间,无需考虑该项本文永久更新链接地址