SHELL SCRIPT TO GET DATABASE SIZE IN ORACLE

You can use the below script to get the database size from rman when the database is in mount state.

Use report schema to get the size of each datafiles

[oracle@orcl19x ~]$ cat rman_schema.cmd
connect target /
run
{
report schema;
}

From the report schema information, we can grab the database size by redirecting the information to output file

Create a shell script ~] vi dbsize.sh

#!/bin/bash
export PATH=/apps01/product/12.1.0/dbhome_1/bin:/usr/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin
export ORACLE_HOME=/apps01/product/12.1.0/dbhome_1
export ORACLE_SID=orcl19x
touch dbsize dbsize1
export SIZELOG=dbsize
export DBSIZELOG=dbsize1
while true;do
rman cmdfile=rman_schema.cmd msglog=$SIZELOG >/dev/null 2>&1;grep -v 'TEMP' dbsize|awk '{print $2}'|grep -Eo '[0-9]{1,9}'|awk '{sum+=$1;}END{print sum;}'|tee -a $DBSIZELOG >/dev/null 2>&1
break
done
echo "the database size is $(cat $DBSIZELOG|grep -Eo '[0-9]{1,9}')"
cat /dev/null > $DBSIZELOG
cat /dev/null > $SIZELOG

Display the database size output

[oracle@orcl19x ~]$ ./dbsize.sh
the database size is 4437

Leave a Reply