Shell script to DROP an Oracle Database


Many times when cloning a database we might need to drop the previous database and recreate it using the clone. For this, I am sharing a simple shell script to drop the database easily. You can change the code as per your requirement and customize it.



Note: Using the script is totally at your discretion, or you can use individual steps to drop the database manually. Do not use if you are not sure about Oracle database drop.


cat drop_database.sh

echo "Sourcing the environment"
. .bash_profile
echo "Check the Database Name $ORACLE_SID"
echo "ctrl + c to cancel this script"
sleep 30
sqlplus /nolog <<  EOF
connect / as sysdba
shutdown abort
startup mount exclusive
alter system enable restricted session;
exit
EOF
rman target / <<EOF
drop database NOPROMPT;
exit
EOF
lsnrctl stop $ORACLE_SID
lsnrctl start $ORACLE_SID

There are 4 syntax available to drop the database using RMAN :-

1. DROP DATABASE;

2. DROP DATABASE NOPROMPT;

3. DROP DATABASE INCLUDING BACKUPS;

4. DROP DATABASE INCLUDING BACKUPS NOPROMPT;

When "NOPROMPT" is specified RMAN does not prompt for the confirmation before deleting the database.

The "DROP DATABASE" command deletes the

Datafiles
Logfiles
Controlfiles
Spfile

The " DROP DATABASE INCLUDING BACKUPS " command in addition to the above files also removes

Archivelogs
Backup pieces generated by RMAN




If you like please follow and comment