Oracle 表空间管理和优化(二)

2014-11-24 17:44:16 · 作者: · 浏览: 4
.
DBMS_SPACE.UNUSED_SPACE(SEGMENT_OWNER => P_OWNER,
SEGMENT_NAME => P_SEGNAME,
SEGMENT_TYPE => P_TYPE,
PARTITION_NAME => P_PARTITION,
TOTAL_BLOCKS => L_TOTAL_BLOCKS,
TOTAL_BYTES => L_TOTAL_BYTES,
UNUSED_BLOCKS => L_UNUSED_BLOCKS,
UNUSED_BYTES => L_UNUSED_BYTES,
LAST_USED_EXTENT_FILE_ID => L_LASTUSEDEXTFILEID,
LAST_USED_EXTENT_BLOCK_ID => L_LASTUSEDEXTBLOCKID,
LAST_USED_BLOCK => L_LAST_USED_BLOCK);
P('TOTAL BLOCKS', L_TOTAL_BLOCKS);
P('TOTAL BYTES', L_TOTAL_BYTES);
P('TOTAL MBYTES', TRUNC(L_TOTAL_BYTES / 1024 / 1024));
P('UNUSED BLOCKS', L_UNUSED_BLOCKS);
P('UNUSED BYTES', L_UNUSED_BYTES);
P('LAST USED EXT FILEID', L_LASTUSEDEXTFILEID);
P('LAST USED EXT BLOCKID', L_LASTUSEDEXTBLOCKID);
P('LAST USED BLOCK', L_LAST_USED_BLOCK);
END;
让普通用户能执行SYS.SHOW_SPACE
SYS@zcs11G> drop user zcs1 CASCADE;
create user zcs identified by zcs;
grant connect,resource,dba to zcs;
grant execute on SYS.SHOW_SPACE TO zcs;
connect zcs/zcs
drop table t1 purge;
create table t1 (id int,name varchar2(19)) segment creation IMMEDIATE tablespace users;
set serverout on;
exec sys.show_space('T1');


2.Shrink收缩高水位实操:
ALTER TABLE MOVE 步骤:
1. desc username.table_name ----检查表中是否有LOB
2. 如果表没有LOB字段
直接 alter table move; 然后 rebuild index
--如果表中包含了LOB字段
alter table owner.table_name move tablespace tablespace_name lob (lob_column) store as lobsegment tablespace tablespace_name;

--也可以单独move lob,但是表上面的index 同样会失效,这是不推荐的
alter table owner.table_name move lob(lob_column) store as lobsegment tablespace tablespace_name ;
3. rebuild index
首先用下面的SQL查看表上面有哪类索引:
select a.owner,a.index_name,a.index_type,a.partitioned,a.status,b.status p_status,b.composite from dba_indexes
a left join dba_ind_partitions b on a.owner=b.index_owner and a.index_name=b.index_name where a.owner='&owner' and a.table_name='&table_name';

对于普通索引直接rebuild index index_name online nologging parallel,对于分区索引,必须单独rebuild 每个分区,对于组合分区索引,必须单独rebuild 每个子分区。
4.对表收集统计信息
限制:
虽然在10g中可以用shrink ,但也有些限制:
1). 对cluster,cluster table,或具有Long,lob类型列的对象 不起作用。
2). 不支持具有function-based indexes 或 bitmap join indexes的表
3). 不支持mapping 表或index-organized表。
4). 不支持compressed 表


3.MOVE收缩高水位
一、shrink操作
1.行的rowid会改变所以表必须启用row movement
SYS@zcs11G> alter table t4 enable row movement;
2.shrink space cascade(cascade可省略)
SYS@zcs11G> alter table t4 shrink space cascade;
4.shrink space可分成两步单步执行
1、shrink space compact 忙时:仅重整表记录行,HWM及索引不变
2、shrink space cascade 闲时:其余全部动作


相关阅读: