oracle 分区表(子分区)收缩笔记
思路
1.首先移动子分区到别的表空间。
2.收缩数据文件。
3.再把子分区移回原表空间。
---------------------------------------------生成发送报告移动子分区语句---------------------------------------------
select 'alter table '||TABLE_NAME||' move subpartition '||SUBPARTITION_NAME||' tablespace SMART_NRRPSTA01;' from dba_tab_subpartitions
where table_name = 'S_T_RTNRP_STATUS'
AND PARTITION_NAME LIKE 'ST_RRPS_12%'
ORDER BY SUBPARTITION_NAME
select 'alter table '||TABLE_NAME||' move subpartition '||SUBPARTITION_NAME||' tablespace SMART_NSNRP01;' from dba_tab_subpartitions
where table_name = 'S_T_SEND_REPORT'
AND PARTITION_NAME LIKE 'ST_SNDRP_12%'
ORDER BY SUBPARTITION_NAME
--------------------------------------------生成返回报告移动子分区语句---------------------------------------------
select 'alter table '||TABLE_NAME||' move subpartition '||SUBPARTITION_NAME||' tablespace SMART;' from dba_tab_subpartitions
where table_name = 'S_T_RTNRP_STATUS'
AND PARTITION_NAME LIKE 'ST_RRPS_01%'
ORDER BY SUBPARTITION_NAME
select 'alter table '||TABLE_NAME||' move subpartition '||SUBPARTITION_NAME||' tablespace SMART_NRRPSTA01;' from dba_tab_subpartitions
where table_name = 'S_T_RTNRP_STATUS'
AND PARTITION_NAME LIKE 'ST_RRPS_01%'
ORDER BY SUBPARTITION_NAME
--------------------------------查看数据文件号---------------------------------------
select TABLESPACE_NAME,FILE_ID,FILE_NAME FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME = 'SMART_NSNRP01'
select TABLESPACE_NAME,FILE_ID,FILE_NAME FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME = 'SMART_NRRPSTA01'
--------------------------------查看数据块最大id值---------------------------------
show parameter db_block_size 查看db_block_size的值
select TABLESPACE_NAME,file_id,max(block_id),max(block_id)*16/1024 from dba_extents where file_id in(99,100,101)
group by TABLESPACE_NAME,file_id
--------------------------------回收发送报告数据文件空间----------------------------------------
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_01.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_02.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_03.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_04.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_05.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_06.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/db75/datafile/smart_nsnrp02_07.dbf' RESIZE 2000M;
--------------------------------回收返回报告数据文件空间----------------------------------------
ALTER DATABASE DATAFILE '+DATA/oracledata3/returnreport/smart_nrrpsta02_01.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/oracledata3/returnreport/smart_nrrpsta02_02.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/oracledata3/returnreport/smart_nrrpsta02_03.dbf' RESIZE 2000M;
ALTER DATABASE DATAFILE '+DATA/oracledata3/returnreport/smart_nrrpsta02_04.dbf' RESIZE 2000M;
--------------------------------查看磁盘组空间使用情况命令--------------------------------------
grid用户执行
sqlplus / as sysasm
select group_number,name,total_mb,free_mb from v$asm_diskgroup;
select 'alter table '||TABLE_NAME||' drop partition '||PARTITION_NAME||';' from dba_tab_partitions
where table_name = 'S_OPERATELOG'
AND PARTITION_NAME LIKE 'OPLOG_1701%'
ORDER BY PARTITION_NAME
select 'alter table '||TABLE_NAME||' drop partition '||PARTITION_NAME||'tablespace SMART;' from dba_tab_partitions
where table_name = 'S_SENDBACKUPQUEUE'
AND PARTITION_NAME LIKE 'SENDBAK_1701%'
ORDER BY PARTITION_NAME
------------------------------------------------扣费日志------------------------------------
alter database datafile '+DATA/oracledata1/smart_oplog01_01.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_02.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_03.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_04.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_05.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_06.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_07.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_oplog01_08.dbf' resize 1024M;
-----------------------------------------------发送记录-------------------------------------
alter database datafile '+DATA/oracledata1/smart_osendbak1_01.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_osendbak1_02.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_osendbak1_03.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_osendbak1_04.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_osendbak1_05.dbf' resize 1024M;
alter database datafile '+DATA/oracledata1/smart_osendbak1_06.dbf' resize 1024M;