Skip to Main Content
  • Questions
  • Blocks allocation to tables and segments

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: August 31, 2016 - 7:25 am UTC

Last updated: February 24, 2022 - 4:11 pm UTC

Version: 11g

Viewed 10K+ times! This question is

You Asked

1)
select s.segment_name,sum(s.blocks),sum(s.BYTES),sum(s.extents) from user_segments s where s.segment_name='TBL_1'
group by s.segment_name;

SEGMENT_NAME SUM(S.BLOCKS) SUM(S.BYTES) SUM(S.EXTENTS)
TBL_1 5504 45088768 8

2)
select e.segment_name,sum(e.bytes),sum(e.BLOCKS),count(1) count_extents from user_extents e where e.segment_name='TBL_1'
group by segment_name;


SEGMENT_NAME SUM(E.BYTES) SUM(E.BLOCKS) COUNT_EXTENTS
TBL_1 45088768 5504 8


3)
select t.TABLE_NAME ,sum(t.BLOCKS),sum(t.EMPTY_BLOCKS) from user_tables t where t.TABLE_NAME='TBL_1'
group by table_name;

TABLE_NAME SUM(T.BLOCKS) SUM(T.EMPTY_BLOCKS)
TBL_1 5352 0

Now Blocks of the segments is larger than blocks of the tables
so difference is 152.

where is remaining blocks( means 152 blocks where occupied by oracle)?

and Connor said...

The blocks in an extent is "different" to the blocks used in a table.

Think of it this way (this is a *conceptual* model - in reality, a few things are different for efficiency reasons, but we'll skip that for ease of explanation). And we'll assume defaults for blocksize etc.

- I create a table, it needs no space
- I insert my first row, so I need a block
- We currently have no space, so we create an extent for you.
- That extent is 8 blocks (64KB)
- So now I have 8 blocks *allocated*, ie, they are *mine*, no-one else can have them
- But I've only *used* 1 block for that first row
- As I keep adding rows, eventually I will use up all of the 8 blocks currently allocated to me. At *that* point, everything would appear in alignment, ie, 8 blocks allocated, and 8 blocks used.
- But when I add another row...well, I need more space...so we'll allocate a *new* extent, thus giving you another 8 blocks (16 total allocated, and 9 in use)

Once again - this is *conceptual* - the numbers here are not *exactly* what goes on

Hope this helps.

Rating

  (6 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, August 31, 2016 - 8:25 am UTC

Thanx

Sharing blocks

Aps, February 26, 2018 - 10:02 am UTC

When you say "So now I have 8 blocks *allocated*, ie, they are *mine*, no-one else can have them" is that meaning an extent or segment from another table cannot also live in that block? Or is it possible for segments from different objects to reside in the same block?
Connor McDonald
February 27, 2018 - 2:00 am UTC

In most cases, a block belongs solely to one object (a table or an index).

There does exist a database object called a cluster, where multiple tables can occupy a single block.

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/cncpt/tables-and-table-clusters.html

blocks in an extent is "different" to the blocks used in a table

Sajith Ihsan, February 11, 2022 - 5:47 am UTC

HI,

What do you mean by "blocks in an extent is "different" to the blocks used in a table"
Connor McDonald
February 14, 2022 - 1:49 am UTC

When I get given an extent, it might be (say) 1megabyte hence 128 blocks.

But as I insert data, my table will use them bit by bit, so at any given moment my table could look like:

extent blocks allocated: 128
blocks used: 5

then a little later

extent blocks allocated: 128
blocks used: 30

etc etc

Blocks allocation the Segment directly when an Extent cannot be allocated

Ihsan, February 17, 2022 - 10:06 am UTC

Hi Connor,

One my friend said that "if an extent is not allocated to a specific instance, blocks themselves are allocated to the segment directly". is it true? If yes, can you explain the difference between this and the above concept you have explained.




Connor McDonald
February 24, 2022 - 7:16 am UTC

"if an extent is not allocated to a specific instance, blocks themselves are allocated to the segment directly". is it true?


Nope.

blocks go into extents, extents get given to segments.

Extent Allocation date

Ihsan, February 24, 2022 - 8:45 am UTC

Is there any way to check the date and time of an extent allocated to the segment?
Chris Saxon
February 24, 2022 - 4:11 pm UTC

See below

To Ihsan

J. Laurindo Chiappa, February 24, 2022 - 1:47 pm UTC

Hi - no, exactly as https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:431790400346919587 already says, Oracle RDBMS doesn't track such kind of low-level detais : they are of no use for the RDBMS....
That said, you can find some (loosely) related information from AWR/ASH (DBA_HIST_TBSPC_SPACE_USAGE) , LOGMNER (IF you have the needed redo AND Supplemental Log is activated), DBMS_SPACE and things alike : NONE of these sources will say to you the EXACT date and time of allocation for an extent, BUT maybe you could derive (from logniner, say) some information about the DMLs that demanded more space (and thus resulted in extents allocation), AND/OR you cold extract from DBA_HIST_TBSPC_SPACE_USAGE (column TABLESPACE_USEDSIZE) approximately when the used size gone up due to extent allocation, things like that....
Chris Saxon
February 24, 2022 - 4:10 pm UTC

Good points