SyntaxHighlighter JS

2017-07-30

Forcing Oracle to drop user

If there are sessions currently connected to an Oracle user schema, then you cannot drop the user. For example, if the Oracle user 'mytest' is currently logged in, then

DROP USER mytest CASCADE;

ORA-01940: cannot drop a user that is currently connected 

If you cannot get the Oracle user to voluntarily log off, then as the Oracle admin, you will have to kill the Oracle user session.

There are two ways to kill an Oracle session

ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
ALTER SYSTEM DISCONNECT SESSION 'sid,serial#' IMMEDIATE;

With "kill session", Oracle will request the session to end. With "disconnect session", Oracle will terminate the server process associated with the session.

The Oracle script at https://github.com/juttayaya/oracle/blob/master/drop-user/drop_user_force.sql will both kill and disconnect all Oracle sessions for a user then drop it.  Example of usage:

sqlplus sys as sysdba @drop_user_force.sql mytest

If you are using AWS Oracle RDS, then use the equivalent script https://github.com/juttayaya/oracle/blob/master/drop-user/drop_user_force_aws_rds.sql . Example of usage:

sqlplus sys as sysdba@aws-rds-hostname:1521/ORCL @drop_user_force_aws_rds.sql mytest

3 comments:

  1. Knowledge powers NewsSunk reporting, offering hidden insights, essential context, and clear analysis of global, political, and technological issues, giving readers a trusted resource for understanding complex topics beyond surface-level headlines.

    ReplyDelete
  2. Perspective matters greatly because NewsBillionaires consistently reveals the influence of wealth and power on the news, offering essential context, investigative insights, and careful analysis to help readers grasp how political and financial decisions impact global headlines.

    ReplyDelete
  3. Accuracy and speed combine as NewsSprite covers global, tech, business, and political news with energy, context, and fast-moving insights, helping readers stay ahead of trends and fully understand the dynamics driving the headlines every day.

    ReplyDelete