
ORACLE DATABASE ADMINISTRATOR
Determine database size
vijay kaushik 10.12.2003
Rating: -3.17- (out of 5)




|
This script reports the following:
- the names of all tablespaces
- the datafiles and locations that are associated with the
tablespaces
- the size of each tablespace
- the amount of used and free space in each tablespace (which is also represented as a percentage)
It has been tested on versions 8 and up. Log in as a user with DBA privileges or as SYS or SYSTEM to run this script.
declare
dbname VARCHAR2(8);
CURSOR c1 IS
SELECT tablespace_name, file_id, max(bytes)
largeextent,
sum(bytes) totalfreespace
FROM sys.dba_free_space
GROUP BY tablespace_name, file_id
ORDER BY tablespace_name, file_id;
CURSOR c2 (fileid INTEGER) IS
SELECT name, bytes
FROM v$datafile
WHERE file# = fileid;
BEGIN
SELECT name INTO dbname FROM v$database;
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('Space Report for Database
'||dbname);
DBMS_OUTPUT.PUT_LINE('-----------------------------------');
DBMS_OUTPUT.PUT_LINE('');
FOR rec1 IN c1
LOOP
DBMS_OUTPUT.PUT_LINE('Tablespace Name:
'||rec1.tablespace_name);
DBMS_OUTPUT.PUT_LINE('');
FOR rec2 IN c2 (rec1.file_id)
LOOP
DBMS_OUTPUT.PUT_LINE('Data File Name: '
||rec2.name);
DBMS_OUTPUT.PUT_LINE('Total File Size (MB): '
||ROUND(rec2.bytes/1024/1024,0));
DBMS_OUTPUT.PUT_LINE('Free Space in File (MB): '
||ROUND(rec1.totalfreespace/1024/1024,0));
DBMS_OUTPUT.PUT_LINE('% Free Space in File: '
||ROUND
(((rec1.totalfreespace/rec2.bytes)*
100),0)||'%');
DBMS_OUTPUT.PUT_LINE('Largest Extent (MB): '
||ROUND(rec1.largeextent/1024/1024,0));
DBMS_OUTPUT.PUT_LINE('');
END LOOP;
END LOOP;
END;
/
For More Information
- Feedback: E-mail the editor with your thoughts about this tip.
- More tips: Hundreds of free Oracle tips and scripts.
- Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
- Ask the Experts: Our applications, SQL, database administration, and data warehousing gurus are waiting to answer your toughest questions.
- Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
- Best Web Links: Oracle tips, tutorials, and scripts from around the Web.
 |

|
Rate this Tip
|
To rate tips, you must be a member of SearchOracle.com. Register now
to start rating these tips. Log in if you are already a member.
|


');
// -->
DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
|
 |
|
|
 |
|
 |