Oracle extent、segment、datafile、tablespace及存储关系

1、创建测试表空间

create tablespace efmis datafile '/u01/app/oracle/oradata/orcl/efmis_01.dbf' size 80m;

alter tablespace efmis add datafile '/u01/app/oracle/oradata/orcl/efmis_02.dbf' size 80m;

alter tablespace efmis add datafile '/u01/app/oracle/oradata/orcl/efmis_03.dbf' size 80m;

SQL> select t.tablespace_name,t.file_id,t.file_name,t.bytes/1024/1024/1024||'G' from dba_data_files t where t.tablespace_name='EFMIS';

TABLESPACE_NAME FILE_ID FILE_NAME T.BYTES/1024/1024/1024||'G'


EFMIS 5 /u01/app/oracle/oradata/orcl/efmis_01.dbf .078125G

EFMIS 6 /u01/app/oracle/oradata/orcl/efmis_02.dbf .078125G

EFMIS 7 /u01/app/oracle/oradata/orcl/efmis_03.dbf .078125G

2、创建测试用户

create user fasp identified by 1 default tablespace efmis;

grant connect,resource to fasp;

3、创建测试表并插入数据

create table fasp.tab1 as select * from dba_objects;

4、查看dba_extents及dba_segments数据相关操作

SQL> select t.tablespace_name,t.segment_name,t.bytes/1024/1024 from dba_segments t where t.owner='FASP';

TABLESPACE_NAME SEGMENT_NAME T.BYTES/1024/1024


EFMIS TAB1 10

SQL> select file_id,sum(bytes)/1024/1024 from dba_extents t where t.owner='FASP' group by file_id;

FILE_ID SUM(BYTES)/1024/1024


6 4

5 3

7 3

SQL> select count(*) from fasp.tab1;

COUNT(*)


86268

SQL> insert into fasp.tab1 select * from fasp.tab1;

86268 rows inserted

SQL> insert into fasp.tab1 select * from fasp.tab1;

172536 rows inserted

SQL> select t.tablespace_name,t.segment_name,t.bytes/1024/1024 from dba_segments t where t.owner='FASP';

TABLESPACE_NAME SEGMENT_NAME T.BYTES/1024/1024


EFMIS TAB1 40

SQL> select file_id,sum(bytes)/1024/1024 from dba_extents t where t.owner='FASP' group by file_id;

FILE_ID SUM(BYTES)/1024/1024


6 14

5 13

7 13

SQL> delete from fasp.tab1;

345072 rows deleted

SQL> commit;

Commit complete

SQL> select count(*) from fasp.tab1;

COUNT(*)


0

SQL> select t.tablespace_name,t.segment_name,t.bytes/1024/1024 from dba_segments t where t.owner='FASP';

TABLESPACE_NAME SEGMENT_NAME T.BYTES/1024/1024


EFMIS TAB1 40

SQL> select file_id,sum(bytes)/1024/1024 from dba_extents t where t.owner='FASP' group by file_id;

FILE_ID SUM(BYTES)/1024/1024


6 14

5 13

7 13

5、结论:

1)tab1表在dba_segments中共1个段,占据10m存储空间。

2)tab1表在dba_extents中分成多个区,总共占10m存储空间。

3)oracle数据库中segment由extent逻辑构成。

4)tab1插入的数据按照hash算法均为分布在所属表空间数据文件下,数据文件创建后不可随意删除,否则将导致部分数据丢失。

5)段相关数据字典:dba_segments,user_segments

区相关数据字典:dba_extents,user_extents

6)dba_segments及dba_extents存储至高水位线空间大小,delete删除数据并不会降低高水位线值。

7)可以通过dba_segments视图查看table及index等数据库对象占用存储空间大小,此时值为起点至高水位线值大小。

6、查看表空间使用率

select a.tablespace_name,

round((a.maxbytes / 1024 / 1024 / 1024), 2) "sum G",

round((a.bytes / 1024 / 1024 / 1024), 2) "datafile G",

round(((a.bytes - b.bytes) / 1024 / 1024 / 1024), 2) "used G",

round(((a.maxbytes - a.bytes + b.bytes) / 1024 / 1024 / 1024), 2) "free G",

round(((a.bytes - b.bytes) / a.maxbytes) * 100, 2) "percent_used(%)"

from (select tablespace_name, sum(sumnow) bytes, sum(summax) maxbytes

from (select t1.tablespace_name,

sum(t1.bytes) sumnow,

sum(t1.maxbytes) summax

from dba_data_files t1

where t1.maxbytes <> 0

group by t1.tablespace_name

union all

select t2.tablespace_name,

sum(t2.bytes) sumnow,

sum(t2.bytes) summax

from dba_data_files t2

where t2.maxbytes = 0

group by t2.tablespace_name)

group by tablespace_name) a,

(select tablespace_name, sum(bytes) bytes

from dba_free_space

group by tablespace_name) b

where a.tablespace_name = b.tablespace_name

order by ((a.bytes - b.bytes) / a.maxbytes) desc;

TABLESPACE_NAME sum G datafile G used G free G percent_used(%)


EFMIS 0.23 0.23 0.04 0.19 17.92

SYSTEM 32 0.82 0.81 31.19 2.52

SYSAUX 32 0.54 0.51 31.49 1.59

UNDOTBS1 32 0.35 0.13 31.87 0.41

USERS 32 0 0 32 0

SQL> select t.tablespace_name,t.file_name,t.file_id,t.bytes/1024/1024,t.autoextensible,t.maxbytes from dba_data_files t where t.tablespace_name='EFMIS';

TABLESPACE_NAME FILE_NAME FILE_ID T.BYTES/1024/1024 AUTOEXTENSIBLE MAXBYTES


EFMIS /u01/app/oracle/oradata/orcl/efmis_01.dbf 5 80 NO 0

EFMIS /u01/app/oracle/oradata/orcl/efmis_02.dbf 6 80 NO 0

EFMIS /u01/app/oracle/oradata/orcl/efmis_03.dbf 7 80 NO 0

7、结论

1)表空间数据文件未设置自动增长,则数据文件最大值(maxbytes)为0,此时数据文件最大值为bytes值大小。

2)表空间由数据文件物理构成。

相关推荐
酷酷的崽79820 分钟前
Redis 键(Key)的命令
数据库·redis·缓存
1892280486134 分钟前
NW622NW623美光固态闪存NW624NW635
大数据·网络·数据库·人工智能·microsoft·性能优化
云飞云共享云桌面44 分钟前
1台电脑10个画图设计用怎么实现
linux·运维·服务器·网络·数据库·自动化·电脑
TTBIGDATA1 小时前
【Ambari监控】Ambari-Metrics 的分支研究
大数据·数据库·hadoop·ambari·bigtop·edp·hidataplus
Z_z在努力1 小时前
【杂类】应对 MySQL 处理短时间高并发的请求:缓存预热
数据库·mysql·缓存
望获linux2 小时前
【实时Linux实战系列】规避缺页中断:mlock/hugetlb 与页面预热
java·linux·服务器·数据库·chrome·算法
longerxin20203 小时前
MongoDB 在线安装-一键安装脚本(CentOS 7.9)
数据库·mongodb·centos
水无痕simon3 小时前
3 水平分表
java·数据库
恣艺3 小时前
探索数据库世界:从基础类型到实际应用
数据库
小钻风33663 小时前
IDEA连接redis数据库时出现Failed to connect to any host resolved for DNS name.
数据库