Oracle database 表空间/段/区/块

表空间

(一个或多个数据文件组成的 用来存储对象)
根据表名查表空间
select table_name ,tablespace_name from user_tables where table_name=’DEPT’;
查询表空间剩余大小
select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;
根据表空间查数据文件
select file_name ,tablespace_name from dba_data_files where tablespace_name=’USERS’;
查管理方式
select tablespace_name,contents,extent_management,segment_space_management from dba_tablespaces;
删除表空间
drop tablespace 表空间名 including contents and datafiles;
级联删除
drop tablespace 表空间名 including contents cascade constraints;
设置自增长
alter database datafile 7 auntoextend on;


增量检查点
show parameter fast_start_mttr_target; 多长时间恢复实例


临时表空间

临时表空间
select username,temporary_tablespace from dba_users where username =’SCOTT’;
临时表空间用的数据文件
select file_name,tablespace_name from dba_temp_files;
创建临时表空间
create temporary tablespace temp2 tempfile ‘/u01/data/orcl/temp02.dbf’ size 10m;
创建临时表空间组
alter tablespace temp tablespace group tempgrp;
查看临时表空间组
select * from dba_tablespace_groups;
修改用户的临时表空间为临时表空间组
alter user scott temporary tablespace tempgrp;
创建一个默认表空间名字为a
create tablespace a datafile ‘/u01/data/orcl/a01.dbf’ size 10m;
切换表logging状态 nologging 不写redo
alter table 表名 nologging(logging);
查询表的logging状态
select table_name,logging from user_tables where table_name=’T1’;
设置数据文件自增长
alter database datafile ‘/u01/data/orcl/a01.dbf’ autoextend on next 1m maxsize 500m;
在表空间a添加数据文件
alter tablespace a add datafile ‘/u01/data/orcl/a02.dbf’ size 10m;
表空间不足时等待插入 默认时间2小时
alter session enable|disable resumable;

块 (block) 最小读写单位 8K
区 (extent) 最小分配单位 初始区(8块 64K)和后续区
段 (segment) 表空间按段管理对象 视图没有段

段(segment)

自动管理(ASSM) AUTO 5个位图 (100% 75% 50% 25% 0%)
手动管理(MSSM) freelist 空闲列表可用块 pctfree 保留百分比 pctused 使用百分比
建表时指定表空间后设置
pctfree pctused
查看表的段管理方式
select table_name,pct_free,pct_used from user_tables;

区(extent)

查看区
select segment_name,file_id,extent_id,bytes from dba_extents;
手动添加t1表的区
alter table t1 allocate extent (datafile’/u01/data/orcl/a01.dbf’ size 5m);
回收未使用的区
alter table t1 deallocate unused;

块(block)

show parameter 16k;
创建表空间时指定块大小 blocksize 16k 为16k
alter system set db_16k_cache_size =4m;


行迁移与行链接

分析表
analyze table t1 compute statistics for table;

select table_name,pct_free,pct_used,avg_row_len,chain_cnt from user_tables where table_name=’T1’;
可以解决行迁移 相当于重新插入
alter table t1 move;

当chain_cnt有值时 看avg_row_len 表示行的平均长度 如果avg_row_len>块大小发生行链接 avg_row_len<块大小 发生行迁移、调整块大小可以解决行链接 重新插入数据可以解决行迁移

查看高水位线;
select num_rows,chain_cnt from user_tab_statistics where table_name=’T1’;
启用行移动
alter table t6 enable row movement;
先压缩 没有锁、
alter table t6 shrink space compact;
移动 有锁
alter table t6 shrink space;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为什么不问问神奇的海螺呢丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值