Two meanings of table size in Oracle
One is the number of physical spaces allocated to a table, regardless of whether the space is used or not. You can query the number of bytes as follows:
Select segment_name, bytes
From user_segments
Where segment_type = TABLE;
The effect is as follows:
Or
Select Segment_Name, Sum (bytes)/1024/1024 from User_Extents Group By Segment_Name;
The result is as follows: [this query is slow]
As shown in the results of the above two figures, the query is the size allocated to the table by 10896M.
Query the actual space occupied by the table.
Space actually used by another table. Query as follows:
Analyze table emp compute statistics;
Select num_rows * avg_row_len
From user_tables
Where table_name = EMP; -- EMP is the table name (table name Big write query)
The effect is as follows:
The actual space occupied by the table is about 9506M.
Appendix:
View the size of each tablespace
Select Tablespace_Name, Sum (bytes)/1024/1024 from Dba_Segments Group By Tablespace_Name
1. view the remaining tablespace size
SELECT tablespace_name tablespace, sum (blocks * 8192/1000000) residual space M from dba_free_space group by tablespace_name;
2. Check the total space of all tablespaces in the system.
Select B. name, sum (. bytes/1000000) total space from v $ datafile a, v $ tablespace B where. ts # = B. ts # group by B. name;
3. query the remaining and used table space usage of the entire database:
Select df. tablespace_name "tablespace name", totalspace "total space M", freespace "remaining space M", round (1-freespace/totalspace) *, 2) "usage %"
From
(Select tablespace_name, round (sum (bytes)/1024/1024) totalspace
From dba_data_files
Group by tablespace_name) df,
(Select tablespace_name, round (sum (bytes)/1024/1024) freespace
From dba_free_space
Group by tablespace_name) fs
Where df. tablespace_name = fs. tablespace_name;
The effect is as follows: