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)表空间由数据文件物理构成。

相关推荐
钝挫力PROGRAMER5 分钟前
开发踩坑记:MyBatis selectKey、空 SQL
数据库·sql·mybatis
JosieBook12 分钟前
【数据库】MySQL 实战精通系列 · 第6篇:InnoDB 存储引擎、日志与崩溃恢复
数据库·mysql
杨云龙UP1 小时前
TDengine 3.4.2.8 Community 三节点三副本生产集群部署实战(DNode/MNode/taosAdapter/Explorer)
大数据·linux·运维·数据库·tdengine·时序库
梦帮科技1 小时前
领域认知知识库图谱注入:从双式记账图网络到高质量问答对自动化合成流水线
运维·网络·数据库·人工智能·矩阵·架构·自动化
Long long ago.1 小时前
vastbase数据库运行sql宕机重启解决
数据库·sql
SelectDB技术团队2 小时前
一条日志两套引擎的账:把 Elasticsearch 检索与分析合并到同一份数据的落地写法
大数据·数据库·elasticsearch·搜索引擎·全文检索·日志·apache doris
数据库百宝箱2 小时前
rum&gin索引对比
java·数据库·gin
wefg13 小时前
【Redis】初识 Redis
数据库·redis·缓存
hacker_LeeFei5 小时前
Windows 下配置 Redis 8.10.2 开机自启:一次踩坑全记录
数据库·windows·redis
这个DBA有点耶5 小时前
MySQL字符集与排序规则深入:索引失效的隐蔽场景与排查方法
数据库·mysql·代码规范