table of Contents
The size of an oracle table has two meanings, namely, the size of the space allocated by the table and the size of the physical space actually occupied. The size of the allocated physical space may not be all used, and the actual size is the size of the space actually used.
Oracle metadata database related table field interpretation
View the size of the physical space allocated by the table
select segment_name --表名
,bytes --分配空间大小(字节)
,bytes/1024/1024 --分配空间大小(M)
from user_segments
where segment_type = 'TABLE';
Field explanation:
user_segments field explanation
or
select segment_name --表名
,sum(bytes) size_b --分配空间大小(字节)
,sum(bytes)/1024/1024 size_m --分配空间大小(M)
from user_extents
where segment_type = 'TABLE'
group by segment_name
;
Field explanation:
DBA_EXTENTS field explanation
View the actual storage space size of the table
select table_name --表名
,num_rows * avg_row_len size --实际存储空间大小
from user_tables
;
ALL_TABLES table field explanation
View the size of each table space
select tablespace_name --表空间名称
,sum(bytes)/1024/1024 size --表空间大小
from dba_segments
group by tablespace_name
;
View table space size and usage
select a.a1 表空间名称
,c.c2 类型
,c.c3 区管理
,b.b2/1024/1024 表空间大小M
,(b.b2-a.a2)/1024/1024 已使用M
,substr((b.b2-a.a2)/b.b2*100,1,5) 利用率
from (select tablespace_name a1, sum(nvl(bytes,0)) a2 from dba_free_space group by tablespace_name) a,
(select tablespace_name b1,sum(bytes) b2 from dba_data_files group by tablespace_name) b,
(select tablespace_name c1,contents c2,extent_management c3 from dba_tablespaces) c
where a.a1=b.b1 and c.c1=b.b1
;
View data file information in the database
select b.file_name 物理文件名
,b.tablespace_name 表空间
,b.bytes/1024/1024 大小M
,(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M
,substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
from dba_free_space a, dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
;
View temporary table space information
In the oracle database, the temporary table space is mainly used for the temporary working space required by the user when using the order by and group by statements to sort and summarize. To query the name, size and data file of the temporary tablespace in the database, you can query the data dictionary dba_tablespaces and dba_data_files. The command is as follows:
select a.tablespace_name 表空间名称
,b.bytes 大小bytes
,b.file_name 数据文件名
from dba_tablespaces a, dba_data_files b
Where a.tablespace_name = b.tablespace_name
and a.contents = 'TEMPORARY'
;
Starting from Oracle 9i, you can create a Temporary tablespace class table space, that is, a "temporary" table space. This type of table space uses temporary files. The information of the temporary file is stored in the data dictionary V$tempfile. The command is as follows:
select file#,status,name from V$tempfile;
In the daily work of the database administrator, the utilization rate of the table space should be frequently inquired, and the growth of the table space should be estimated according to the specific situation of the database system. When the utilization rate of the table space exceeds 90%, timely measures should be taken, such as cleaning up the history. Tables, historical data to release space, add new data files to the table space, expand the size of existing data files and other methods to reduce the utilization of the table space, and avoid the error of insufficient space when the utilization of the table space approaches 100% .