How to calculate the percentage of free space for a table in Oracle
okay, I am a little confused here. I have been searching the web and looking at a lot of documents. What I basically want to find out is this, how do I calculate the difference between the number of bytes a table is using and the total bytes allocated to a table space (going that way to get percent free for a particular table). So I need a byte count of a table and total table space and the percentage difference. I have been looking at the DBA_TABLES DBA_TABLESPACES and DBA_SEGMENTS views. I have tried to calculated the space as num_rows * avg_row_len (if I am wrong, let me know). I have been trying to compare that calculation to the number in DBA_TABLESPACES and DBA_SEGMENTS. I am just looking for the total space allocated to the table space that the table sits in (seem logical right now) to make the percentage value work. Thus I want to be able to track the table as it grows as compated to the table space it sits in to see a value as it changes over time (days, weeks, etc.) each time I run this script I am working on.
Can someone get me straight and help me to find out if I am looking in the right places. Any advice would help.
Edward
You can use a little modified version of dbms_space from Tom, show_space. Have a look,
SQL> create table test222 as select * from all_objects;
Table created.
SQL> delete from test22 where rownum<=100;
delete from test22 where rownum<=100
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> delete from test222 where rownum<=100;
100 rows deleted.
SQL> analyze table test222 compute statistics;
Table analyzed.
SQL> create or replace procedure show_space
2 ( p_segname in varchar2,
3 p_owner in varchar2 default user,
4 p_type in varchar2 default 'TABLE',
5 p_partition in varchar2 default NULL )
6 -- this procedure uses authid current user so it can query DBA_*
7 -- views using privileges from a ROLE and so it can be installed
8 -- once per database, instead of once per user that wanted to use it
9 authid current_user
10 as
11 l_free_blks number;
12 l_total_blocks number;
13 l_total_bytes number;
14 l_unused_blocks number;
15 l_unused_bytes number;
16 l_LastUsedExtFileId number;
17 l_LastUsedExtBlockId number;
18 l_LAST_USED_BLOCK number;
19 l_segment_space_mgmt varchar2(255);
20 l_unformatted_blocks number;
21 l_unformatted_bytes number;
22 l_fs1_blocks number; l_fs1_bytes number;
23 l_fs2_blocks number; l_fs2_bytes number;
24 l_fs3_blocks number; l_fs3_bytes number;
25 l_fs4_blocks number; l_fs4_bytes number;
26 l_full_blocks number; l_full_bytes number;
27
28 -- inline procedure to print out numbers nicely formatted
29 -- with a simple label
30 procedure p( p_label in varchar2, p_num in number )
31 is
32 begin
33 dbms_output.put_line( rpad(p_label,40,'.') ||
34 to_char(p_num,'999,999,999,999') );
35 end;
36 begin
37 -- this query is executed dynamically in order to allow this procedure
38 -- to be created by a user who has access to DBA_SEGMENTS/TABLESPACES
39 -- via a role as is customary.
40 -- NOTE: at runtime, the invoker MUST have access to these two
41 -- views!
42 -- this query determines if the object is a ASSM object or not
43 begin
44 execute immediate
45 'select ts.segment_space_management
46 from dba_segments seg, dba_tablespaces ts
47 where seg.segment_name = :p_segname
48 and (:p_partition is null or
49 seg.partition_name = :p_partition)
50 and seg.owner = :p_owner
51 and seg.tablespace_name = ts.tablespace_name'
52 into l_segment_space_mgmt
53 using p_segname, p_partition, p_partition, p_owner;
54 exception
55 when too_many_rows then
56 dbms_output.put_line
57 ( 'This must be a partitioned table, use p_partition => ');
58 return;
59 end;
60
61
62 -- if the object is in an ASSM tablespace, we must use this API
63 -- call to get space information, else we use the FREE_BLOCKS
64 -- API for the user managed segments
65 if l_segment_space_mgmt = 'AUTO'
66 then
67 dbms_space.space_usage
68 ( p_owner, p_segname, p_type, l_unformatted_blocks,
69 l_unformatted_bytes, l_fs1_blocks, l_fs1_bytes,
70 l_fs2_blocks, l_fs2_bytes, l_fs3_blocks, l_fs3_bytes,
71 l_fs4_blocks, l_fs4_bytes, l_full_blocks, l_full_bytes, p_partition);
72
73 p( 'Unformatted Blocks ', l_unformatted_blocks );
74 p( 'FS1 Blocks (0-25) ', l_fs1_blocks );
75 p( 'FS2 Blocks (25-50) ', l_fs2_blocks );
76 p( 'FS3 Blocks (50-75) ', l_fs3_blocks );
77 p( 'FS4 Blocks (75-100)', l_fs4_blocks );
78 p( 'Full Blocks ', l_full_blocks );
79 else
80 dbms_space.free_blocks(
81 segment_owner => p_owner,
82 segment_name => p_segname,
83 segment_type => p_type,
84 freelist_group_id => 0,
85 free_blks => l_free_blks);
86
87 p( 'Free Blocks', l_free_blks );
88 end if;
89
90 -- and then the unused space API call to get the rest of the
91 -- information
92 dbms_space.unused_space
93 ( segment_owner => p_owner,
94 segment_name => p_segname,
95 segment_type => p_type,
96 partition_name => p_partition,
97 total_blocks => l_total_blocks,
98 total_bytes => l_total_bytes,
99 unused_blocks => l_unused_blocks,
100 unused_bytes => l_unused_bytes,
101 LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
102 LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
103 LAST_USED_BLOCK => l_LAST_USED_BLOCK );
104
105 p( 'Total Blocks', l_total_blocks );
106 p( 'Total Bytes', l_total_bytes );
107 p( 'Total MBytes', trunc(l_total_bytes/1024/1024) );
108 p( 'Unused Blocks', l_unused_blocks );
109 p( 'Unused Bytes', l_unused_bytes );
110 p( 'Last Used Ext FileId', l_LastUsedExtFileId );
111 p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
112 p( 'Last Used Block', l_LAST_USED_BLOCK );
113 end;
114
115 /
Procedure created.
SQL> desc show_space
PROCEDURE show_space
Argument Name Type In/Out Default?
P_SEGNAME VARCHAR2 IN
P_OWNER VARCHAR2 IN DEFAULT
P_TYPE VARCHAR2 IN DEFAULT
P_PARTITION VARCHAR2 IN DEFAULT
SQL> set serveroutput on
SQL> exec show_space('TEST222','SCOTT');
BEGIN show_space('TEST222','SCOTT'); END;
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "SCOTT.SHOW_SPACE", line 44
ORA-06512: at line 1
SQL> conn / as sysdba
Connected.
SQL> grant sysdba to scott;
Grant succeeded.
SQL> conn scott/tiger as sysdba
Connected.
SQL> exec show_space('TEST222','SCOTT');
BEGIN show_space('TEST222','SCOTT'); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'SHOW_SPACE' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
SQL> exec scott.show_space('TEST222','SCOTT');
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> exec scott.show_space('TEST222','SCOTT');
Unformatted Blocks ..................... 0
FS1 Blocks (0-25) ..................... 0
FS2 Blocks (25-50) ..................... 1
FS3 Blocks (50-75) ..................... 0
FS4 Blocks (75-100)..................... 1
Full Blocks ..................... 807
Total Blocks............................ 896
Total Bytes............................. 7,340,032
Total MBytes............................ 7
Unused Blocks........................... 65
Unused Bytes............................ 532,480
Last Used Ext FileId.................... 4
Last Used Ext BlockId................... 1,289
Last Used Block......................... 63
PL/SQL procedure successfully completed.
SQL>http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5350053031470
I use this to find the space allocations.
Just read your post again,this is not going to show you the percentage of the free/used space. This is going to be the number of blocks which are free/used. For the growth trend, you can look at (in 10g) Oracle EM. It has added now,Segment Growth Trend report which can show you for each object,comparing to the allocated space to the object,how much space is being used by it.
HTH
Aman....
Similar Messages
-
How do I set aside 1G free space for a game?
Trying to install civ4- how do I set aside 1G free space for a game?
if your son is set as a child under your Family Share settings you should be able to turn on "Ask permission" for purchases. If you do have that on I don't know why it's not prompting him to ask.
Another way to stop in-app-purchases is to set restriction on his iOS device. (Turn off in-app-purchases under General/Restrictions) -
How to get the data from pcl2 cluster for TCRT table.
Hi frndz,
How to get the data from pcl2 cluster for tcrt table for us payroll.
Thanks in advance.
Harisumanth.ChPL take a look at the sample Program EXAMPLE_PNP_GET_PAYROLL in your system. There are numerous other ways to read payroll results.. Pl use the search forum option & you sure will get a lot of hits..
~Suresh -
How to retrieve the number of "free" rows in a table?
Hi,
if in a client only environment (no sync to mobile server) rows are inserted and deleted into a table,
is there a way to retrieve the number of "free" rows in a table? Number of "Free" rows stands for
number of rows that can be inserted again, before the table extents in size.
Is there a way in OLite 10.3.0.2.0 to retrieve the size of tables and indexes? ALL_TABLES is not
a place that really works.
Best regards and many thanks,
GerdHi Gary,
many thanks, the partner uses a Lite client db without sync. The db runs inside an laboratory device and collects measures. There must be a way to estimate the the number of "measures" rows, that stil can be stored in the db.
Than we need to make the deleted space available for new rows. The partner tested defrag.exe and found that it
needs very long time to run, especially if the db is bigger than 2GB. ... and that this run sometimes fails.
Is there any recommendation the partner can follow on?
Thanks,
Gerd -
The percentage of free space is remain unchanged after extend data file.
I have alter database and extend datafile (applsysd03.dbf), the free size is larger than before, but don't know why the percentage (MAX_PER_FREE) is remain unchanged.
FILE_NAME TABLESPACE TOTAL USED FREE PER_FREE MAX_SIZE MAX_FREE MAX_PER_FREE
applsysd03.dbf APPLSYSD 3000 1637.9 1362.1 45.4 2000 362.1 18.1
applsysd03.dbf APPLSYSD 1900 1637.9 262.1 13.8 2000 362.1 18.1
Here is the my scripts:
select b.file_name File_name,
b.tablespace_name Tablespace,
b.bytes/(1024*1024) Total,
round((b.bytes - sum(nvl(a.bytes,0)))/(1024*1024),1) Used,
round(sum(nvl(a.bytes,0))/(1024*1024),1) Free,
round((sum(nvl(a.bytes,0))/(b.bytes))*100,1) per_Free,
round(decode(b.maxbytes,0,b.bytes,b.maxbytes)/(1024*1024),1) Max_Size,
round((sum(nvl(a.bytes,0)) + decode(b.maxbytes,0,0,b.maxbytes-b.bytes))/(1024*1024),1) Max_Free,
round((((sum(nvl(a.bytes,0)) + decode(b.maxbytes,0,0,b.maxbytes-b.bytes))/(1024*1024)) / (decode(b.maxbytes,0,b.bytes,b.maxbytes)/(1024*1024))) * 100,1) Max_per_Free
from sys.dba_free_space a,sys.dba_data_files b
where a.file_id(+) = b.file_id
and exists (
select file_id,recent_record
from ( select file_name,file_id,tablespace_name, max(file_id) over (partition by tablespace_name) recent_record
from sys.dba_data_files
where tablespace_name in ('ALRD','ALRX','APPLSYSD','APPLSYSX','APD','APX','ARD','ARX','CAPD','CAPX','CARD','CARX','CFNDD','CFNDX','CGLD','CGLX','CINVD','CINCX','CPOD','CPOX','CQCD','CQCX','CTXD','GLD','GLX','HRD','HRX','ICXD','ICXX','INVD','INVX','POD','POX','RGD','RGX','CWPLD','CWPLX','CSYND','CSYNX')
) t
where t.file_id = t.recent_record
and t.file_id = b.file_id
group by b.tablespace_name, b.file_name, b.bytes,b.maxbytes
order by 9
Any clues?
FANTo summarize - you want to see what percent of the maximum datafile space is free.
If the maxbyes <= bytes (size of the datafile) it will never autoextend. So, the max size is the current datafile size.
If the maxbytes >bytes, the max available space is the maxbyes.
So, the calculation would be:
max_percent_free = (max_size - used) / (max_size)
where max_size is either maxbytes or bytes (current datafile size).
In the first case, where datafile is 1900 meg that would be:
max_percent_free = (2000-1637) / (2000) = 18% - we use maxbytes since it is 2000, greater than the file size (1900)
After increasing the size to 3000
max_percent_free = (3000-1637) / 3000 = 45% - we use file size, 3000, since it is larger than maxbytes (2000)
If you would set maxbytes to 5 gb
max_percent_free = (5000-1637)/5000 = 67%
Does that make sense? -
How to calculate the Percentage differencebased on two values
Not sure how to do this.
Just want to calculate the % difference of two values (seem to have a problem when one value is zero)
Here is the current output
49 Apr 2
64 Aug 1
55 Feb 0
Here is the output I would like to see
49 Apr 2 4.08%
64 Aug 1 1.56%
55 Feb 0 0.00%
Here is the current SQL
Select TO_CHAR (RCA_CLOSE_DATE, 'Month') "Month",
SUM (CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) "BI&D - CBAT No of Adj",
Count(1) as "Count of Adjustments"
from TW_BILL_ADJ_DATA
where (RCA_CLOSE_DATE between nvl (:P8_DATE_FROM,FORM_RECEIVED)
and nvl (:P8_DATE_TO, FORM_RECEIVED))
group by TO_CHAR (RCA_CLOSE_DATE, 'Month')You can try something like this one:
Select TO_CHAR (RCA_CLOSE_DATE, 'Month') "Month",
SUM (CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) "BI&D - CBAT No of Adj",
Count(1) as "Count of Adjustments",
round(count(1)/SUM(CASE WHEN RCA_CODE = 'BI&D' THEN 1 ELSE 0 END) * 100,2) || '%' percent
from TW_BILL_ADJ_DATA
where (RCA_CLOSE_DATE between nvl (:P8_DATE_FROM,FORM_RECEIVED)
and nvl (:P8_DATE_TO, FORM_RECEIVED))
group by TO_CHAR (RCA_CLOSE_DATE, 'Month')
CODE NOT TESTED !!!
Best Regards
Krystian Zieja / mob -
How to calculate the percentages
Hi Gurus!!
I am having a key figure(say suppose KF1) which had undergone currency conversions in query designer level to USD.
Now i want one more field(KF2) in my report in which i should get the values of percentages based on KF1 and its overall result.
Means i have 1000,2500,3400....under KF1 and the total is 25000. Finally under KF2 i should get as mentioned below
KF1----
>KF2
1000----
>(1000/25000)*100
2500----
>(2500/25000)*100
3400----
>(3400/25000)*100
So like wise i shold get the percentages based on KF1 and its total.
I had tried SUMGT and %GT functions as mentioned below:
kf1/sumgt(kf1) and kf1/%GT(kf1) and for both of them the query is showing errors like you cannot use these functions in the query. correct the query.
Pls suggest me the solution.
Thanks in Advance
Jiten
Edited by: Jitendra Yuddandi on Jun 9, 2009 12:20 PMcheck these links
http://help.sap.com/saphelp_nw04s/helpdata/en/1e/99ea3bd7896f58e10000000a11402f/frameset.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/e2/16f13a2f160f28e10000000a114084/frameset.htm -
Detemining the free space for each tables before Archiving an object.
Hi Everyone,
I want to know,how can i get the information about the how much space will get free from each table which is related to an archiving object <b>before</b> i perform
archiving on that particular object.
Are there any transactions for the same, or some transaction which can be related to these.
eg:FI_DOCUMNT is related to lots of table, before i archive this object, i want to know that space that will be free from all the tables individually which are affected by this object.
Regards,
Nipun SharmaHi Nipun,
as far as I know: there is no easy tool to get this numbers. But on the other hand, you don't need exact numbers, estimations will do.
It's a good idea to start with the biggest objects: take DB02, make a detailed analysis where you select the biggest tables -> corresponding archive objects should be your main focus (for the beginning).
Count for the biggest tables in each objects the entries per year (or month, whatever periods you are interested in). Most tables have creation date to do so, otherwise go for number range. For some numbers you could search the creation date, the rest is estimation again.
Then you will have an idea, which volume was created in which time frame.
Still you need some test archive runs (in PRD or an (old) copy, at least for an example amount of data): you need to know, which % of the documents can technically be archived, how much will stay open because of missing closing. That's critical information (maybe 90% will stay in system) and can only be analyzed by SARA test runs - if you identify the missing object status, you can go on selecting this directly, but in the beginning you need the archive run.
With the volume / time frame and the percentage, which can be deleted you should be able to give estimations based on current total object size. Make clear, that you talk about estimations: every single object will be checked for having correct status - before this isn't done (in a test run), no one can tell exact numbers.
Hope, this will help you,
regards,
Christian -
How to calculate the number of days worked for a given period
I need to calculate the number of days worked by contractor employees for a time period to be entered by a user. I am building a query on an infoset which contains employee information including contract start date and contract end date for the employee.
Ideally I'd like the user to enter the time period which should be reported on e.g. 01.08.2009 to 31.08.2009
The report should then identify all the contractor employees which were working during this period and to work out how many days they worked during this period. Obviously the contract start and end dates could fall both inside and outside the reporting period.
Can this be done and if so, do you have any suggestions as to how to do it?
Thanks.hi
So here you will first have to load the master data table employee in one internal table and read this table with the variables entries.
Your code in the reporting exit should look like that.
bye
data : wa_employee type /bi0/pemployee.
When 'ZDATE1'
if i_step = 2.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDATE2'.
clear l_s_range.
clear wa_employee
1- select the entries from table employees
select single employee dateto datefrom
from /bi0/pemployee
into corresponding fields of wa_employee
where dateto le loc_var_range-low
and datefrom ge loc_var_range-high.
if sy-subrc eq 0.
CALL FUNCTION 'FIMA_DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_von = wa_employee-datefrom
i_kz_ult_von = 'X'
i_datum_bis = wa_employee-dateto
i_kz_ult_bis = 'X'
i_szbmeth = '1'
IMPORTING
e_tage = no_days.
l_s_range-low = no_days.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDIF.
ENDIF.
endloop.
ENDIF.
Boujema -
How to get the primary key names right for child tables?
I have a logical model with a parent table and two child tables. The engineering strategy is "table per child". The parent has an primary key attribute. This is a screen shot:
https://lh5.googleusercontent.com/-iKMtA3Say5c/UIkG1iktgEI/AAAAAAAAAtc/mrwFeHm4gi4/s800/child_pk_log.png
When I engineer the model I get two primary keys with the same name name, which is the name of the parent:
https://lh3.googleusercontent.com/-N88a9VwoPKw/UIkG1spbXpI/AAAAAAAAAtY/eonf8WdUZ6I/s800/child_pk_rel.png
The correct names would be CHILD1_PK and CHILD2_PK. I can change the relational model by applying the naming rules but the next engineering will trash the names again.
How can I fix this?Hi,
the problem with PK name is fixed in Data Modeler 3.2.
You can change PK name in relational model it won't be changed on next engineering
Philip -
How to find the last DML timings on any particular table in oracle 10g?
Hi All,
I need to know in one particular table when the last DML operation happen and what is the dml query ?
Thanks
BalaHi;
Please see:
find last dml operation time on a table
find last dml operation time on a table
Last DML time
find last dml operation time on a table
time of last DML
Regard
Helios -
How to make a proactive view of the Logical Disk Free Space
Hello,
I was wondering how I could make a view (preferably within a dashboard) that monitors the state of the Logical Disk Free Space values for one or more predefined groups. I can only get this to work with line diagrams but that is pretty hard to read.
I would like to make views like:
1) A simple state view that shows the state of the servers (or disks) in three state form (1. Healthy: 80% or lower; 2. Warning: Between 80% and 90%; 3. Alert: 90% or higher).
2) A view of actual percentages of the disk drives in a table form rather than the usual line diagram.
I prefer the first one the most and seems to be the easiest aswell but I can't seem to get this to work.
I hope that this is possible any like to know how to achieve this.
Thanks in advance,
BramHi Bram,
I think you need to create a new dashboard view for this.
Make a new management pack for this.
Once you create a new management pack.
Go to monitoring TAB
Locate the management pack there and right click and select new Dashboard.
Create a summary view dashboard and then once it is created on the right hand side you will see something like
Performance (Which i edited as LDS report for last 24 hrs as per the screenshot)
Above that you will have a configure option. Click on it and mention the Object, counter and instance and of the LDS performance counter and mention the report duration (Last 1hr or 24 hrs )once you do this dashboard will start collecting the report
for you.
Once you scroll down the report you will get the list of servers in which space is low and how old is that alert
Below is the screenshot for your reference.
Gautam.75801 -
How can I get the amount of free space that is on my drive to show at the bottom of the drive in Lion.
This is a must feature for me and I may have to go back to Snow Leopard.
Please help!Right click on your desktop and choose "viewer options". Adjust the spacing and the size of your icons and you should be able to see the size of your drive(s) and the free space available on each drive with the exception of your bootcamp drive which will only show the overall size of the drive you have it on. This may be different if you only have one system drive (like on a Mac Book Pro) with a partition containing bootcamp on it. this may only show you the overall capacity, I can't say for sure though as I only use a Mac Pro with 4 seperate Hard Drives which are showing both overall capacity and free space available. Hope this helps
Denisimo -
how to find the amount of free disk space on my pc
http://onesearch.sun.com/search/onesearch/index.jsp?qt=free+disk+space&subCat=siteforumid%3Ajava31&site=dev&dftab=siteforumid%3Ajava31&chooseCat=javaall&col=developer-forums
-
How do you display the capacity/free space for the hard drive on the desktop, under the hard drive icon.... I have seen this done, but I am not seeing any options to do so.... thanks.
View, Show View Options…, Show item info checkbox.
Maybe you are looking for
-
I keep getting this screen and before I have to call and pay and wanted to see if there was something that I could do. Pavilion dv4-1123us get blue screen with "hardware malfunction call hardware vendor for support" This question was solved. View
-
How do I use my iTunes account w/ iCloud and leave my MobileMe subscription intact?
I use several Mac applications that integrate with MobileMe, so I'd like to keep my MobileMe account intact (NOT move to iCloud) so I can continue to use this functionality until those apps are updated to support iCloud. I am hoping there's a way I c
-
i replaced my old iphone to a new one.. i want to get my photos from icloud,,,, i had almost 3 gb of photos backed up on icloud,,, how can i transfer all those photos to my new phone,, i tried but i only got 90 photos. those are the recent one. i had
-
ICal recurring events function broken
Hi folks, I use my Mac for business, so having iCal broken is a serious problem. I hope someone can help. The problem has crept up on me, so I can't pinpoint when I started to have issues. It seems to be progressive in some way. I've tried to delete
-
Cancel a Goods Return/Sales Return Based on a GRPO
Hello Experts, A wrong Sales Return document has been registerd, this document is based on a GRPO. What is the best way to supress the Sales return and cancel it's effect on the system. (SAP 2007 A Pl 41) Thanks in advance. Amin