When trying to drop a schema that has connected users, Oracle will not allow that schema to be dropped. This creates problems when trying to reset a schema to a prior exported version.
There are two separate ways to disconnect the user. The first is to shut down and restart Oracle and the other is to explicitly disconnect the session that is keeping the schema from being dropped. There are times when the shutdown of the database is not an option. So here is alternate way to disconnect a session. This has been tested on Oracle 18.104.22.168, 22.214.171.124, 126.96.36.199, 188.8.131.52, and 184.108.40.206. I have only tested this script as the sys user.
FIND THE CONNECTED SESSION:
select username, process, sid, serial#, machine, status, program from v$session order by username;DISCONNECT INVALID SESSION:
alter system kill session '<sid of invalid session>,<serial# of invalid session>';Make sure that you only do this to database sessions that are not being currently used.
For More Information
- Feedback: E-mail the editor with your thoughts about this tip.
- More tips: Hundreds of free Oracle tips and scripts.
- Tip contest: Have an Oracle tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
- Ask the Experts: Our applications, SQL, database administration, and data warehousing gurus are waiting to answer your toughest questions.
- Forums: Ask your technical Oracle questions--or help out your peers by answering them--in our active forums.
- Best Web Links: Oracle tips, tutorials, and scripts from around the Web.