Skip to Main Content
  • Questions
  • Locally Managed Tablespace and DBA_FREE_SPACE view

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, William.

Asked: December 11, 2000 - 2:12 am UTC

Last updated: September 07, 2005 - 8:04 am UTC

Version: Oracle 8.1.7

Viewed 1000+ times

You Asked

Hi Tom,

I am using locally managed tablespaces in my database. Running the query:

select fs.tablespace_name tsname,
df.tot_blks tot,
fs.free_blks free,
df.tot_blks - fs.free_blks used,
nvl(seg.seg_blks, 0) alloc,
(df.tot_blks - fs.free_blks) - nvl(seg.seg_blks, 0) lost
from ( select tablespace_name,
sum(blocks) tot_blks
from dba_data_files
group by tablespace_name ) df,
( select tablespace_name,
sum(blocks) free_blks
from dba_free_space
group by tablespace_name ) fs,
( select tablespace_name,
sum(blocks) seg_blks
from dba_segments
group by tablespace_name ) seg,
dba_tablespaces ts
where df.tablespace_name = fs.tablespace_name
and df.tablespace_name = seg.tablespace_name (+)
and df.tablespace_name = ts.tablespace_name
and ts.extent_management = 'LOCAL'
/

I get the following results:

Total Free Used Alloc Lost
Tablespace Blocks Blocks Blocks Blocks Blocks
---------------- ------------ ------------ ------------ ------------ ------------
DYNDATA 192,000 163,840 28,160 24,576 3,584
STDATA 38,400 37,104 1,296 1,280 16
TOOLS 2,560 2,528 32 16 16
USERS 1,280 1,248 32 16 16
STIDX 12,800 12,784 16 0 16
DYNIDX 12,800 12,288 512 0 512


The tablespaces have had objects created and deleted. My
question is why are there "lost blocks". I know that each datafile uses 64K to maintain a bitmap of free blocks. I am using 8K blocks.

Cheers

and Tom said...

Sounds like you are using uniform extent management and your datafiles are not an even multiple + 64k of the extent size. Consider for example (using your query):


tkyte@TKYTE816> create tablespace lm
2 datafile 'c:\temp\lm.dbf'
3 size 500k
4 extent management local
5 uniform size 400k;

Tablespace created.


So, in this tablespace, we allocate 400k extents. Looking at your query:

tkyte@TKYTE816> @a

TSNAME TOT FREE USED ALLOC LOST
------ ---- ---- ---- ----- ----
LM 63 50 13 0 13

we've lost 13 blocks due to overhead. Now, I have a 8k block size so that is 8k*13 = 104k. 64k is bitmap overhead so that is 40k unaccounted for. Well, that makes sense since 504k (the real size of the datafile -- it has 63 blocks) MINUS 400k for an extent is 104k MINUS 64k for the overhead is 40k. We have 40k we can never allocate to an extent.

Let's resize the file to be better suited to this tablespace:


tkyte@TKYTE816> alter database datafile 'c:\temp\lm.dbf' resize 864k;

Database altered.

tkyte@TKYTE816> @a

TSNAME TOT FREE USED ALLOC LOST
------ ---- ---- ---- ----- ----
LM 108 100 8 0 8

There we go -- we have room for exactly 2 400k extents plus 64k for the bitmap -- minimal lossage

tkyte@TKYTE816> alter database datafile 'c:\temp\lm.dbf' resize 464k;

Database altered.

tkyte@TKYTE816> @a

TSNAME TOT FREE USED ALLOC LOST
------ ---- ---- ---- ----- ----
LM 58 50 8 0 8

tkyte@TKYTE816> alter database datafile 'c:\temp\lm.dbf' resize 460k;

Database altered.

Same story here -- we have room for exactly 1 400k extent and the 64k overhead. If we try to go too small:

tkyte@TKYTE816> alter database datafile 'c:\temp\lm.dbf' resize 432k;
alter database datafile 'c:\temp\lm.dbf' resize 432k
*
ERROR at line 1:
ORA-03214: File Size specified is smaller than minimum required



Rating

  (7 ratings)

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

Comments

WHAT IF ?

A reader, September 11, 2001 - 6:58 am UTC

WHAT IF THE TABLESPACE IS TEMPORARY AND MANAGED LOCALLY. THE FREE SPACE DOESN'T SHOW UP IN DBA_FREE_SPACE. IS THERE AN EQUIVALENT VIEW FOR TEMPORARY TS ?.

Tom Kyte
September 11, 2001 - 9:37 am UTC

You don't need a dba_free_space for temporary files. Consider them to always be "all used". You use the dynamic performance view v$sort_segment and v$sort_usage to see how the system is using them.

Space in temporary tablespaces is allocated and managed by the system itself in memory -- not in the normal fashion. It doesn't make sense to look at the physically unallocated space in "temp" and say that is how much is free. You rather look at how much is allocated and in use in the v$sort_segment/usage views and assume the rest is in fact "free"

Scripts for freespace in locally managed temporary tables

Dik Pater, July 26, 2002 - 6:50 am UTC

Hi Tom,
thanks for the lots of info on this site.
I use this query for getting the information concerning freespace in LM TEMP :

-- START
col size_temp_files format 99999 Heading "Size|Temp|Files"
col free_space_in_temp_files format 99999 Heading "Free|Space|In|Temp|Files"
col free_space_in_sort_segment format 99999 Heading "Free|Space|In|Sort|Segment"
col used_space_in_sort_segment format 99999 Heading "Used|Space|In|Sort|Segment"
col total_free format 99999 Heading "Total|Free"
select tsh.tablespace_name
, dtf.omvang size_temp_files
, tsh.free_space_space_header free_space_in_temp_files
, nvl(ss.free_space_sort_segment,tsh.used_space_space_header) free_space_in_sort_segment -- could be empty
, nvl(ss.used_space_sort_segment,0) used_space_in_sort_segment
, tsh.free_space_space_header+nvl(ss.free_space_sort_segment,tsh.used_space_space_header) TOTAL_FREE
from
( select tablespace_name, sum(bytes)/1024/1024 omvang from dba_temp_files
group by tablespace_name ) dtf
,(
select tablespace_name
,sum(BYTES_USED)/1024/1024 USED_SPACE_SPACE_HEADER
,sum(BYTES_FREE)/1024/1024 FREE_SPACE_SPACE_HEADER
from v$temp_space_header
group by tablespace_name
) tsh,
( select tablespace_name
,sum(USED_BLOCKS)/1024/1024 USED_SPACE_SORT_SEGMENT
,sum(FREE_BLOCKS)*par.value/1024/1024 FREE_SPACE_SORT_SEGMENT
from v$sort_segment ss
, v$parameter par
where par.name = 'db_block_size'
group by tablespace_name, value
) ss
where dtf.tablespace_name = tsh.tablespace_name
and ss.tablespace_name (+) = dtf.tablespace_name
/
-- END


Excellent script

MZ, September 17, 2003 - 11:56 am UTC

The script from Dik Pater is excellent!!!

trying Dik Pater's script

Fernando Sanchez, November 10, 2003 - 11:30 am UTC

I've tried Dik Pater's script, having a temporary tablespace called TEMP with 2 tempfiles (one 600 Mb size and the other 400 Mb size) and I get:

TABLESPACE_NAME SIZE_TEMP_FILES FREE_SPACE_IN_TEMP_FILES FREE_SPACE_IN_SORT_SEGMENT USED_SPACE_IN_SORT_SEGMENT TOTAL_FREE
------------------------------ --------------- ------------------------ -------------------------- -------------------------- ----------
TEMP 1000 0 599,75 0 599,75


I don't understand what I get, I guess SIZE_TEMP_FILES=1000 is OK, but what about the others columns?

Can someone help me?


update of code

Dik Pater, December 06, 2004 - 9:41 am UTC

You're right : I updated the code.

select tsh.tablespace_name
, dtf.omvang size_temp_files
, tsh.free_space_space_header free_space_in_temp_files
, nvl(ss.free_space_sort_segment,tsh.used_space_space_header) free_space_in_sort_segment -- could be empty
, nvl(ss.used_space_sort_segment,0) used_space_in_sort_segment
, tsh.free_space_space_header+nvl(ss.free_space_sort_segment,tsh.used_space_space_header) TOTAL_FREE
from
( select tablespace_name, sum(bytes)/1024/1024 omvang from dba_temp_files
group by tablespace_name ) dtf
,(
select tablespace_name
,sum(BYTES_USED)/1024/1024 USED_SPACE_SPACE_HEADER
,sum(BYTES_FREE)/1024/1024 FREE_SPACE_SPACE_HEADER
from v$temp_space_header
group by tablespace_name
) tsh,
( select tablespace_name
,sum(USED_BLOCKS)*par.value/1024/1024 USED_SPACE_SORT_SEGMENT
,sum(FREE_BLOCKS)*par.value/1024/1024 FREE_SPACE_SORT_SEGMENT
from v$sort_segment ss
, v$parameter par
where par.name = 'db_block_size'
group by tablespace_name, value
) ss
where dtf.tablespace_name = tsh.tablespace_name
and ss.tablespace_name (+) = dtf.tablespace_name
/


Tablespace - Alter User

VIKAS, September 07, 2005 - 4:18 am UTC

Dear Mr. Kyte

How r u? Hope u r doing well.
I have a few questions related to the below given situation for you.

I have few users say u1, u2, u3 and they all have been assigned their default tablespace as T1 and temporary tablespace as Tmp. The above default tablespace T1 is a free list Tablespace that was creted by me without using
"Segement Space Management Auto" clause.

Now the thing is, as we all know that the Tablespaces created with their "Segement Space Management Auto", are considered good and hassle free from the performance and maintainance point of view. I want to assign the above users u1, u2, u3 a new tablespace which has its segement space management auto. For achieving this, I created a new tablespace T2 with its "Segment Space Management Auto".

-->Now can you pls suggest me, how should i migrate the users which are working on free list tablespace T1 to a tablespace T2 which has "Segment Space Management Auto", along with all of their objects (Tables, Views, Procedures, etc).

-->Will issuing the "ALTER USER... DEFAULT TABLESPACE T2;" serve the purpose? if not, what should I do to achieve the above task?

-->Suppose that I have already issued the "ALTER USER... DEFAULT TABLESPACE T2;" command and users are working on the database, what effect will it have on their objects and database(Incase i have not dropped T1, and assigned T2 to u1, u2, u3)?

-->Does altering a default tablespace of any user, migrates the user along with his objects to the new tablespace or would his objects become invalid and useless or even may get dropped?

--> what will happen to user/user objects if I isuue the "ALTER USER...DEFAULT TABLESPACE T2;" and drop the tablespace T1?

Sorry i know these are lot many questions, and some may even be Kiddish, but i cant help putting them up to you for thier answers and clarification.

Take car. Regards...
Vikas.






Tom Kyte
September 07, 2005 - 8:04 am UTC


...along with all of their objects (Tables, Views, Procedures,
etc).....


only segments are in tablespaces -- views, no tablespaces. procedures, no tablespaces (well, their code is always stored in SYSTEM)....

You can use alter table TabName MOVE tablespace T2; for each table owned by a given user and then alter index IdxName rebuild tablespace t2; for each index...


altering a users default tablespace only affects segments created in the future (that don't have some other tablespace name associated with them)



If you drop tablespace t1 with segments still in it, it'll fail (it won't drop) unless you add including contents - and then it will wipe out their stuff.



Tablespace - Alter User

Vikas, September 26, 2005 - 6:49 am UTC

Thanx for the information.
Regards...