Oracle 11g 修改表的所属表空间

应领导要求,需要将部分表的所属表空间进行更改,目的为了整理用户。

查询owner下 对于表级别的表空间分类

select tablespace_name,count(*) from dba_tables where owner = 'XXX' group by tablespace_name order by 2;

核对上面的数量情况

select * from dba_tables where owner = 'XXX' and tablespace_name = 'USERS';

查看每张表的基本信息

select table_name,num_rows from dba_tables where owner = 'XXX' and tablespace_name = 'USERS' order by 2 desc;

查询需要move表的详细信息

select t.table_name as "表名",

t.num_rows as "表行数",

nvl(s.partition_name, 0) as "分区名",

s.segment_type "段类型",

s.bytes / 1024 / 1024 as "段大小(MB)"

FROM dba_tables t, dba_segments s

where t.table_name = s.segment_name(+)

and t.owner = 'XXX'

and t.tablespace_name = 'USERS'

order by s.bytes

desc;

select count(*) from(

select table_name

from dba_tables

where owner = 'XXX'

and table_name not like 'T\_%' escape '\'

and table_name not like 'JF\_%' escape '\'

and table_name not like 'PAYMENT\_%' escape '\'

and table_name not like 'PROM%'

and table_name <> 'CUSTOMER_BUY_HIS');

查询需要move表的索引情况,11g中要考虑move后的索引重建,12c版本中可以支持online move

select index_name,index_type,table_name,table_owner,table_type,uniqueness,status from dba_indexes where owner = 'XXX' and tablespace_name = 'USERS';

拼接move的sql语句

SELECT 'alter table '||TABLE_NAME||' move tablespace YLPW;' FROM DBA_TABLES WHERE TABLESPACE_NAME = 'USERS' and OWNER = 'XXX';

拼接重建索引的sql语句(rebuild 跟 rebuid online的区分要注意,online不会阻塞dml语句)

select 'alter index ' ||index_name||' rebuild online;' from dba_indexes where table_owner = 'YL2012' and status <> 'VALID';

1、要考虑move后的索引重建问题

2、尽量放在业务低峰期或者夜间进行

3、对于大表考虑重建索引时占用的cpu跟临时表空间的问题

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐