Delete an oracle instance, the right way

You can delete databases with DBCA which takes care of most of it.

Or you can do as below, but this will do the same as removing the datafiles, redo logs, controlfiles manually.

sqlplus / as sysdba
startup mount exclusive restrict
exit
rman target /
drop database including backups noprompt;
exit

After this, you still have to remove the entry that belongs to the database from /etc/oratab, remove init.ora/spfile, password file from $ORACLE_HOME/dbs, and clean log directories (adump, bdump, cdump, udump).


If you decide to use DBCA to delete the database, you can do this:

If you want to completely remove an Oracle 10.2g instance from an Oracle home directory you first need to identify the instance in the oratab file. For example, this entry shows that the testdb Oracle database instance is associated with the following ORACLE_HOME:

testdb:/u01/app/oracle/product/11.2.0/db_1:Y
mydb:/u01/app/oracle/product/10.2.0/db_1:N

Next, you need to set the environment for the database that you want to remove, for example:

/usr/local/bin/oraenv
ORACLE_SID = [testdb] ? mydb

Now you can start the Database Configuration Assistant (DBCA):

dbca

Then, select the Database to delete (mydb) and click finish.

You can also delete a database using DBCA in silent mode. For example, for single instance database:

dbca -silent -deleteDatabase -sourceDB <Oracle_Sid>

Removing an Oracle database deletes all of the data in the database. For example, among other things, this action will delete:

1) All files resulting from this query (for mydb):

SELECT name FROM v$datafile
   UNION
SELECT name FROM v$controlfile
   UNION
SELECT name FROM v$tempfile
   UNION
SELECT member FROM v$logfile

2) Entry associated with mydb in oratab

3) Entries associated with mydb in listener.ora and tnsnames.ora

If you want to keep this data, make sure that you back up the database before deleting it.

Starting with Oracle Database 11g Release 2 (11.2), you can take advantage of the deinstall command.