Operating System - HP-UX
1752806 Members
5589 Online
108789 Solutions
New Discussion юеВ

Re: schema table storage size

 
Edgar_8
Regular Advisor

schema table storage size

Hi,

We have a DB schema with many daily tables within a specific tablespace, what formula can one use to determine
what the space capacity(in GB/GB) a particular table is consuming within its tablespace.

Thanks in advance!
10 REPLIES 10
Fred Ruffet
Honored Contributor

Re: schema table storage size

select
tablespace_name,
segment_type,
segment_name,
sum(bytes)/(1024*1024) size_gb
from
dba_segments
group by
tablespace_name,
segment_type,
segment_name;

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Indira Aramandla
Honored Contributor

Re: schema table storage size

Hi Edgar,

In addition to what Fred said, to determine Real Space used by a Table ie. are not empty,
you can do by the ROWID.

Each row in the table has pseudocolumn called ROWID. This pseudo contains information about physical location of the row in format block_number.row.file

If the table is stored in a tablespace which has one datafile, all we have to do is to get DISTINCT number of block_number from ROWID column of this table.

But if the table is stored in a tablespace with more than one datafile then you can have the same block_number but in different datafiles so we have to get DISTINCT number of block_number+file from ROWID.

The SELECT statements which give us the number of "really used" blocks is below. They are different for ORACLE 7 and ORACLE 8 because of different structure of ROWID column in these versions.
For ORACLE 7:

SELECT COUNT(DISTINCT SUBSTR(rowid,15,4)||
SUBSTR(rowid,1,8)) "Used"
FROM schema.table;


For ORACLE 8+:

SELECT COUNT (DISTINCT
DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid)||
DBMS_ROWID.ROWID_RELATIVE_FNO(rowid)) "Used"
FROM schema.table;
or

SELECT COUNT (DISTINCT SUBSTR(rowid,1,15)) "Used"
FROM schema.table;

You could ask why the above information could not be determined by using the ANALYZE TABLE command. The ANALYZE TABLE command only identifies the number of 'ever' used blocks or the high water mark for the table.

I hipe this helps.

Indira A
Never give up, Keep Trying
Edgar_8
Regular Advisor

Re: schema table storage size

Hi Indira,

Thanks for the info. The value returned is it the no. of bytes/kb/Mb/Gb? Or does one have to do a conversion?

Thanks in advance!
Yogeeraj_1
Honored Contributor

Re: schema table storage size

hi,

some more clarifications and summary.

consider the attached script free.sql

it will generate a report like:
Tablespace Name KBytes Used Free Used Largest
________________ ____________ ____________ ____________ ______ ____________
DRSYS 86,016 4,232 81,784 4.9 81,784
OEM_REPOSITORY 30,728 27,912 2,816 90.8 2,816
...
------------ ------------ ------------
sum 25,699,592 19,860,136 5,839,456

which shows us:

Kbytes = space allocated to the tablespace currently.
Used = space allocated within the tablespace to specific objects
Free = space NOT yet allocated to any objects
Used = % of space allocated to objects in tablespace
Largest= Largest free contigous extent available (NEXT_EXTENTS larger then this will FAIL)

and now, to find the amount of free space within the allocated space, we have 2 choices:

a. analyze tables frequently. Then the "EMPTY_BLOCKS" column in user_tables will be populated

b. use the dbms_space package to find the free space available.

hope this helps!
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: schema table storage size

free.sql
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Edgar_8
Regular Advisor

Re: schema table storage size

Hi Yogee,

We need to find out the storage space of a table, not the tablespace size.

Thanks in advance!
Fred Ruffet
Honored Contributor

Re: schema table storage size

Edgar,

About Indira's answer : Result is given in blocks. So you will need to convert. Bock size is given in bytes by the oracle parameter db_block_size :
show parameter db_block_size

Note, that it may be a little more complex if you have different block size on your tablespaces.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Edgar_8
Regular Advisor

Re: schema table storage size

Hi,

The db_block_size is 8192.Any idea of what the conversion formula would be?

Thanks in advance!
Fred Ruffet
Honored Contributor

Re: schema table storage size

to take one example from Indira's answer :

SELECT 8192*(COUNT (DISTINCT DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid)||DBMS_ROWID.ROWID_RELATIVE_FNO(rowid))) "bytes" FROM table_name;

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)