Professional Documents
Culture Documents
Written JP Vijaykumar
Date Jan 4th 2020
Modified Jan 5th 2020
Modified Mar 8th 2020
**************************************************************
This article/script is provided for educational purpose ONLY.
The readers are advised to make necessary changes to the script as may be required
for their use in their respective environments.
Pls test these scripts thoroughly in a lower environment, ONLY if you are satisfied
with the tests' results, then ONLY use in any
higher environments with CAUTION. Readers discretion is advised.
It is advisable to monitor the load on the db/server, while you are testing this
script in your environment.
This script was generated/tested in Oracle 12C environment running on linux os.
This script may not work in other versions of Oracle, pls modify the script as may
be needed using your own discretion/ingenuity.
Pls be extremely careful, while using these scripts. If any of the files are
deleted, due to some typos, there is no ROLLBACK for
unix commands that were executed wrongly.Pls excersize extreme caution while
working with these unix commands. Pls test these script
thoroughly in lower environments.
Dedication towards your job is not a sacrifice. It is the justification for your
existence in this world. Rabindranath Tagore
In this article, I will present, how to monitor the diskspace utilization on unix
servers running Oracle dbs.
All our databases are running on Oracle 12C.
In my current project, I need to present capacity planning report for all the
servers in the enterprise running Oracle databases.
I had setup this process and just run the oneline shell command from my gitbash
console and the diskspace report is ready.
The detailed steps are as follows:
On all the servers, I had included the following shell command, in our regularly
run cronjobs, to capture the df -h command output
into a csv file.
$ cd /home/oracle/jp;>diskspace.csv;export HOST="`hostname`,`date +%Y%m%d`"; df -h
|grep "%"|grep -v export|awk -v OFS=',' -v var="$HOST" '{if ($1 == "tmpfs" || $1 ==
"/dev/sda1" || $1 == "dr-oracle01p:/app" || $1 == "Filesystem" ) {print var,
$2,$3,$4,$5,$6} else {print var,$1,$2,$3,$4,$5}}'>>diskspace.csv
Pls note, the above script is specific to our env, so as to filter unwanted mounts'
information.
pls customize the command, with required filtering, as may be necessary/required to
your specific environment.
$ cat /home/oracle/jp/diskspace.csv
oracle02t,20200104,Size,Used,Avail,Use%,Mounted
oracle02t,20200104,492G,55G,417G,12%,/
oracle02t,20200104,130G,0,130G,0%,/dev/shm
oracle02t,20200104,477M,246M,202M,55%,/boot
oracle02t,20200104,178G,101G,78G,57%,/inst
oracle02t,20200104,5.5T,5.0T,498G,92%,/db
oracle02t,20200104,200G,159G,42G,80%,/app
oracle02t,20200104,800G,44G,757G,6%,/archive
oracle02t,20200104,1.4T,569G,782G,43%,/db_temp
oracle02t,20200104,100G,66G,35G,66%,/mnt/XML
oracle02t,20200104,7.6T,4.0T,3.6T,53%,/backup
oracle02t,20200104,2.6T,467G,2.2T,18%,/backup2
oracle02t,20200104,9.0T,5.6T,3.5T,62%,/backup3
oracle02t,20200104,1.0T,199G,826G,20%,/mnt/Source
Or you can setup a separate shell script to execute the above command daily, and
schedule it via cron.
Create external table, as detailed here below, on each Oracle db(if multiple
instances are running on each host, then one db per host serves the purpose).
SQL>connect Veeksha/Saketh
Once in a while, from my gitbash terminal, I run the following onliner and see the
output.
-----------------------------------------------------------------------------------
------
I am using a common user to loop through different databases and read the contents
of diskspace external table.
For this purpose, I had granted necessary permission in all the databases to the
common user.
-----------------------------------------------------------------------------------
------
I can check a specific mount across all the server and see how the space is
utilized:
$ cat c:/jpscripts/diskspace.sql
set linesize 200 pagesize 100
select cast(server_name as varchar2(20)) server_name, cast(db_unique_name as
varchar2(10)) name,cast(run_date as varchar2(10)) run_date,
cast(disk_size as varchar2(10)) disk_size, cast(used_size as varchar2(10))
used_size,
cast(free_size as varchar2(10)) free_size, cast(used_pct as varchar2(10))
used_pct,
cast(mount_name as varchar2(30)) mount_name from sys.diskspace,v$database;
quit;
Happy scripting.
REFERENCES:
https://asktom.oracle.com/pls/asktom/f?
p=100:11:0::::P11_QUESTION_ID:5088536900346242095
https://asktom.oracle.com/pls/asktom/f?
p=100:11:0::::P11_QUESTION_ID:9533837800346646784
http://www.orafaq.com/node/3139 --Tablespace Capacity Planning Report
https://www.scribd.com/doc/168383882/Tablespace-Growth-Report
http://www.databasejournal.com/features/oracle/article.php/3673616