Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't Oracle DROP USER CASCADE removing all remants of a user from disk?

I need to eliminate all remnants of specific users from an Oracle 11g R2 database. This means not only deleting the users one by one, but also deleting all objects associaated with that user, in addition to all physical remnants on the disk, such as .dbf files.

I read several articles suggesting syntax for this, and settled on the following series of two lines for each user:

DROP USER <username> CASCADE;
DROP TABLESPACE <username> INCLUDING CONTENTS AND DATAFILES;  

I then typed SELECT USERNAME, DEFAULT_TABLESPACE FROM DBA_USERS; and confirmed that the USER with the specific username was not included in the results.

But I also have the folder containing the .DBF files open, and I notice that the .DBF files are not deleted even though the Oracle SQL Developer interface tells me that both of the two above commands succeeded.

What specific syntax or other actions do I need to take in order to delete EVERY remnant of the user and its associated schema, etc. from an Oracle 11g R2 database?


ONGOING RESEARCH:


After reading @EliasGarcia's approach, I tried his first command select tablespace_name from dba_data_files where file_name = 'file_including_path' for the same username that was used in the preceding commands in the OP. But this query did not produce any results because the table space was deleted by the two commands shown above in my OP.

Given that I have to delete the user and all objects related to the user also, can someone please show how to combine the OP approach with @EliasGarcia's approach? For example, the OP is asking for something like DROP USER username CASCADE INCLUDING CONTENTS AND DATAFILES;

I hesitate to simply delete the .dbf files after running the above commands.

like image 578
HereAndThere Avatar asked Feb 27 '16 00:02

HereAndThere


People also ask

How do I drop a user cascade in Oracle?

You must have the DROP USER system privilege. Specify the user to be dropped. Oracle Database does not drop users whose schemas contain objects unless you specify CASCADE or unless you first explicitly drop the user's objects. Specify CASCADE to drop all objects in the user's schema before dropping the user.

What keyword can you add to drop user to automatically drop all objects in the user's schema?

Specify CASCADE to drop all objects in the user's schema before dropping the user. You must specify this clause to drop a user whose schema contains any objects.

Can not drop a user that is currently connected Oracle?

Cause: An attempt was made to drop a user that was currently logged in. Action: Make sure the user is logged out, then re-execute the command. The ORA-01940 can always be cured by bouncing the source and replicated instance. First, double-check to ensure that the user is not connected to the current instance.

Can we drop users tablespace?

You cannot drop the SYSTEM tablespace. You can drop the SYSAUX tablespace only if you have the SYSDBA system privilege and you have started the database in MIGRATE mode. You may want to alert any users who have been assigned the tablespace as either a default or temporary tablespace.


Video Answer


1 Answers

Datafiles are allocated to tablespaces, not users. Dropping the users will remove the tables etc. from the tablespace, but the underlying storage is not affected.

Don't delete the dbf files from the filesystem directly, you'll get your database into a mess. To remove them, find which tablespace the files belong to using the following statement:

select tablespace_name
from   dba_data_files
where  file_name = <file name with full path>;

You can then remove the file(s) by dropping the tablespace:

drop tablespace <tablespace_name> including contents and datafiles;

Before doing this you should verify that there aren't any objects still allocated to the tablespace for other users however. You can find this by running:

select * from dba_segments
where  tablespace_name = <tablespace to drop>;

If this returns anything, move the objects to another tablespace if you want to keep them before dropping the tablespace.

like image 60
Elias Garcia Avatar answered Sep 27 '22 21:09

Elias Garcia