首页
登录 | 注册

oracle shrink file partition table,resize datafile

1、确保表所在表空间segment状态为自动:
   select tablespace_name,segment_space_management from dba_tablespaces;
    TABLESPACE_NAME                SEGMEN                                          
     ------------------------------ ------                                          
      SYSTEM                         MANUAL                                          
      UNDOTBS1                       MANUAL                                          
      SYSAUX                         AUTO                                            
2、确保表enable了row movement;
    select a.row_movement,a.* from all_tables a
         where  a.TABLE_NAME=tb_name '
 
   alter table tb_name enable row movement;
 
3、shrink table
  

Examples

Shrink a table and all of its dependent segments (including LOB segments):

ALTER TABLE employees SHRINK SPACE CASCADE;

Shrink a LOB segment only:

ALTER TABLE employees MODIFY LOB (perf_review) (SHRINK SPACE);
Shrink a single partition of a partitioned table:
ALTER TABLE customers MODIFY PARTITION cust_P1 SHRINK SPACE;

Shrink an IOT index segment and the overflow segment:

ALTER TABLE cities SHRINK SPACE CASCADE;

Shrink an IOT overflow segment only:

ALTER TABLE cities OVERFLOW SHRINK SPACE;
4、resize datafile
 
计算datafile可以resize收缩的空间.
col name for a40
col resizecmd for a80
select a.file#,a.name,a.bytes/1024/1024 CurrentMB,
       ceil(HWM * a.block_size)/1024/1024 ResizeTo,
       (a.bytes - HWM * a.block_size)/1024/1024 ReleaseMB,
       'alter database datafile '''||a.name||''' resize '||
       ceil(HWM * a.block_size/1024/1024) || 'M;' ResizeCMD
from v$datafile a,
     (select file_id,max(block_id+blocks-1) HWM
       from dba_extents
       group by file_id) b
where a.file# = b.file_id(+)
and (a.bytes - HWM *block_size)>0
order by 5
如果只是想对某个表个间的datafile resize,可采用:
select a.file#,a.name,a.bytes/1024/1024 CurrentMB,
       ceil(HWM * a.block_size)/1024/1024 ResizeTo,
       (a.bytes - HWM * a.block_size)/1024/1024 ReleaseMB,
       'alter database datafile '''||a.name||''' resize '||
       ceil(HWM * a.block_size/1024/1024) || 'M;' ResizeCMD
from v$datafile a,
     (select file_id,max(block_id+blocks-1) HWM
       from dba_extents where file_id in
              (select b.file#  From v$tablespace a ,v$datafile b
                where a.ts#=b.ts# and a.name='MP2000')
       group by file_id) b
where a.file# = b.file_id(+)
and (a.bytes - HWM *block_size)>0
order by 5

计划tempfile可以resize的空间.on apply that have only one tempfile
select 'alter database tempfile '''||a.name ||''' reize '||b.siz||'M;' from v$tempfile a,
     (select tmsize.maxblk*bk.value/1024/1024 siz from
         (select nvl(max(segblk#),128) maxblk  from v$sort_usage) tmsize,
         (select value From v$parameter where name = 'db_block_size') bk) b
  
----------------
参考:
---MOVE LOGSEGMENT TO NEW TABLESPACE,根据实际检验LOBINDEX会随着相应的LOBSEGMENT自动移动
ALTER TABLE USERNAME.TABLE_NAME MOVE LOB(LOB_COLUMN) STORE AS (TABLESPACE NEW_TABLESPACE)

相关文章

  • 一篇关于oracle net log file的学习笔记.学习资料为oracle10g版本的官方文档<Troubleshooting Oracle Net Services>,链接如下: http://download.orac ...
  • 1. full chekcpoint的一些基础知识 我们汉子道检查点其实是一个数据库事件,它存在的目的其实有2个: 1)建立数据的一致性 2)保证数据库尽可能快的恢复 full chekcpoint检查点的分类以及检查点的触发机制: 主要有 ...
  • Ubuntu linux下安装sqlite3 1.介绍:sqlite3是linux上的小巧的数据库,一个文件就是一个数据库. 2.安装: 要安装sqlite3,可以在终端提示符后运行下列命令: sudo apt-get install sq ...
  • Ubuntu linux下安装sqlite3 1.介绍:sqlite3是linux上的小巧的数据库,一个文件就是一个数据库. 2.安装: 要安装sqlite3,可以在终端提示符后运行下列命令: sudo apt-get install sq ...
  • 一.制作U盘启动 1.将FreeBSD-11.0-RELEASE-amd64-memstick.img拷贝到FreeBSD主机上. 2.Smiles#dd if=FreeBSD-11.0-RELEASE-amd64-memstick.img ...
  • Oracle 12C Sharding部署和测试
    Oracle 12C Sharding部署和测试 日期:2019-02-26 作者:陈举超   一:环境说明 OS:CentOS Linux release 7.5 DB:Oracle 12.2.0.1.0 GSMOCI:2.2.1 本次使 ...

2019 unjeep.com webmaster#unjeep.com
12 q. 0.013 s.
京ICP备10005923号