I'd like to drop all entities from an Oracle instance. I want to delete all tables, users, indices and so on, just like as if it would be a freshly created instance. The result should look, or at least closely approximate from the viewpoint of the clients, as if I had completely deleted and then reinstalled the instance with the same settings.
Doing this with a complete wipe/reinstall is slow, and it is not easily automatizable. I am looking for better options, but it is a possible solution, if there isn't.
Dropping the schemas is not enough, because some entities still remain in place (for example, users).
Is there an easy way to drop everything, to reach the initial clean and empty state, but more quickly?
Best Answer
In Oracle, a schema is normally linked to a user. So if you drop a user and specify the
CASCADE
parameter, then all objects related to that user will be dropped.You can query the users table with the following query:
This will generate a list of statements for users which aren't created by the system (Oracle) and which, when executed, will drop all users and their related objects. Example:
You are left with an Oracle instance that is pretty clean.
There are objects which will be maintained by the Oracle instance and which might take further combing to remove.
Reference: DROP USER (Oracle | Database SQL Language Reference)