--create tablespace CREATE BIGFILE TABLESPACE "TBS_ADTDATA1" DATAFILE '+DG_DATA/tbs_adtdata1_n.dbf' SIZE 2621440m AUTOEXTEND ON NEXT 32212254720 MAXSIZE 134217727M LOGGING ONLINE PERMANENT BLOCKSIZE 32768 EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT NOCOMPRESS SEGMENT SPACE MANAGEMENT AUTO; CREATE BIGFILE TABLESPACE "TBS_ADTDATA1" DATAFILE '+DG_DATA/tbs_adtdata_n.dbf' SIZE 1677721m AUTOEXTEND ON NEXT 32212254720 MAXSIZE 134217727M LOGGING ONLINE PERMANENT BLOCKSIZE 32768 EXTENT MANAGEMENT LOCAL AUTOALLOCATE DEFAULT NOCOMPRESS SEGMENT SPACE MANAGEMENT AUTO; --1.enable row movement,data tablespace define OLD_TS_NAME='TS_BLOCK' set serveroutput on; declare cursor c is select distinct se.owner,se.segment_name from dba_segments se where se.tablespace_name='&OLD_TS_NAME' and se.segment_type in('TABLE','TABLE PARTITION') order by se.owner; begin for v in c loop execute immediate 'alter table '||v.owner||'.'||v.segment_name ||' enable row movement'; dbms_output.put_line('-->Enable row movement OK : '||v.owner||'.'||v.segment_name); end loop; end; / --2.move table define OLD_TS_NAME='TS_BLOCK' define NEW_TS_NAME='USERS' set serveroutput on; declare cursor c is select se.owner,se.segment_name from dba_segments se where se.tablespace_name='&OLD_TS_NAME' and se.segment_type='TABLE'; sql_stmt varchar2(200); sql_enable varchar2(200); sql_disable varchar2(200); begin execute immediate 'alter session enable parallel ddl'; for v in c loop sql_stmt:= 'alter table '||v.owner||'.'||v.segment_name ||' move tablespace '|| '&NEW_TS_NAME'||' parallel 16'; --excute sqls execute immediate sql_stmt; dbms_output.put_line('-->Move table OK : '|| v.segment_name); end loop; end; / --3.move table partitions define OLD_TS_NAME='TS_BLOCK' define NEW_TS_NAME='USERS' set serveroutput on; declare cursor c is select se.owner,se.segment_name,se.partition_name from dba_segments se where se.tablespace_name='&OLD_TS_NAME' and se.segment_type='TABLE PARTITION' order by se.owner; sql_stmt varchar2(200); begin execute immediate 'alter session enable parallel ddl'; for v in c loop --move table partition sql_stmt:= 'alter table '||v.owner||'.'||v.segment_name ||' move partition '||v.partition_name || ' tablespace &NEW_TS_NAME parallel 16'; --dbms_output.put_line(sql_stmt); --excute sqls execute immediate sql_stmt; dbms_output.put_line('-->Move table partition OK: '|| v.owner||'.'||v.partition_name); end loop; end; / --4.disable row movment,data tablespace define NEW_TS_NAME='USERS' set serveroutput on; declare cursor c is select distinct se.owner,se.segment_name from dba_segments se where se.tablespace_name='&NEW_TS_NAME' and se.segment_type in('TABLE','TABLE PARTITION') order by se.owner; begin for v in c loop execute immediate 'alter table '||v.owner||'.'||v.segment_name ||' disable row movement'; dbms_output.put_line('-->Disable row movement OK : '||v.owner||'.'||v.segment_name); end loop; end; / --5.check all tables to new tablespace,not in old tablespace,on table/table partitoon is OK define TS_BLOCK='TS_BLOCK' select * from dba_segments se where se.tablespace_name='&OLD_TS_NAME'; --6..rebuild indexes define OLD_TS_IDX_NAME='TS_BLOCK' define NEW_TS_IDX_NAME='USERS' set serveroutput on; declare cursor c is select distinct se.owner,se.segment_name from dba_segments se where se.tablespace_name='&OLD_TS_IDX_NAME' and se.segment_type='INDEX' order by se.owner; sql_stmt varchar2(200); begin execute immediate 'alter session enable parallel ddl'; for v in c loop --move table partition sql_stmt:= 'alter index '||v.owner||'.'||v.segment_name ||' rebuild tablespace &NEW_TS_IDX_NAME parallel 16 nologging'; --dbms_output.put_line(sql_stmt); --excute sqls execute immediate sql_stmt; dbms_output.put_line('-->Rebuild index OK: '|| v.owner||'.'||v.segment_name); end loop; end; / --7.rebuild partiton indexes define OLD_TS_IDX_NAME='TS_BLOCK' define NEW_TS_IDX_NAME='USERS' set serveroutput on; declare cursor c is select distinct se.owner,se.segment_name,se.partition_name from dba_segments se where se.tablespace_name='&OLD_TS_IDX_NAME' and se.segment_type='INDEX PARTITION' order by se.owner; sql_stmt varchar2(200); begin execute immediate 'alter session enable parallel ddl'; for v in c loop --move table partition sql_stmt:= 'alter index '||v.owner||'.'||v.segment_name ||' rebuild partition '||v.partition_name||' tablespace &NEW_TS_IDX_NAME parallel 16 nologging'; --dbms_output.put_line(sql_stmt); --excute sqls execute immediate sql_stmt; dbms_output.put_line('-->Rebuild index OK: '||v.owner||'.'|| v.segment_name); end loop; end; / --8.check all indexes to new tablespace ,not in old tablespace ,no index index partition is OK define OLD_TS_IDX_NAME='TS_BLOCK' select * from dba_segments se where se.tablespace_name='&OLD_TS_IDX_NAME'; --9.gather table/index stats for new tables for update in new tablespace define NEW_TS_NAME='USERS' set serveroutput on; declare cursor c is select distinct se.owner,se.segment_name from dba_segments se where se.tablespace_name='&NEW_TS_NAME' and se.segment_type in('TABLE','TABLE PARTITION'); begin for v in c loop if c%NOTFOUND then dbms_output.put_line('No data found!'); else --dbms_output.put_line(v.owner||v.segment_name); dbms_stats.gather_table_stats(ownname => v.owner,tabname => v.segment_name,estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,method_opt => 'FOR ALL COLUMNS SIZE 1',degree => dbms_stats.AUTO_DEGREE,cascade => true); dbms_output.put_line('Gather stats OK : ' || v.owner||'.'||v.segment_name); end if; end loop; end; / --10.check statst on all objects,no data os OK define NEW_TS_NAME='TS_BLOCK'; define NEW_TS_IDX_NAME='TS_BLOCK' select se.owner,se.TABLE_NAME,se.ROW_MOVEMENT,se.degree,se.LAST_ANALYZED from dba_tables se where se.TABLESPACE_NAME='NEW_TS_NAME' and se.LAST_ANALYZED is null; select es.owner,es.index_name,es.degree,es.LAST_ANALYZED from dba_indexes es where es.TABLESPACE_NAME='NEW_TS_NAME' and es.LAST_ANALYZED is null; --11.drop old tablespaces; drop tablespace xx_idx including contents and datafiles; drop tablespace xx_data including contents and datafile;
Oracle Shrink Datafile
来源:这里教程网
时间:2026-03-03 21:01:53
作者:
编辑推荐:
- Oracle Shrink Datafile03-03
- 糖尿病患者每天最多喝多少乌龙茶?03-03
- securecrt 录制脚本,securecrt 录制脚本一般操作03-03
- 普洱茶和滇红茶的口感有什么区别?03-03
- 滇红茶适合哪些人群饮用?03-03
- 普通表转分区表-在线重定义03-03
- 长沙买家具,一定不要错过这家宝藏店03-03
- [20241216]Oracle wrong result一则(优化器问题)2.txt03-03
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- securecrt 录制脚本,securecrt 录制脚本一般操作
securecrt 录制脚本,securecrt 录制脚本一般操作
26-03-03 - 普洱茶和滇红茶的口感有什么区别?
普洱茶和滇红茶的口感有什么区别?
26-03-03 - 滇红茶适合哪些人群饮用?
滇红茶适合哪些人群饮用?
26-03-03 - xshell备份数据库,如何实现xshell备份数据库
xshell备份数据库,如何实现xshell备份数据库
26-03-03 - ora-04036处理
ora-04036处理
26-03-03 - 柔性振动盘智能分拣
柔性振动盘智能分拣
26-03-03 - 紫砂壶的泥料种类有哪些特点?
紫砂壶的泥料种类有哪些特点?
26-03-03 - 《大连公益讲师团》在美丽的滨海城市-大连成立了啦
《大连公益讲师团》在美丽的滨海城市-大连成立了啦
26-03-03 - 紫砂壶泡养的色泽变化是怎样的?
紫砂壶泡养的色泽变化是怎样的?
26-03-03 - 泡养紫砂壶时,茶叶种类对色泽有何影响?
泡养紫砂壶时,茶叶种类对色泽有何影响?
26-03-03
