Terminate a session in Oracle

Source: Internet
Author: User
Sometimes it is necessary for oracle to terminate the current session. For example, if you want to perform a management operation, you need to terminate all non-Administrator sessions. The following describes how to terminate sess.

Sometimes it is necessary for oracle to terminate the current session. For example, if you want to perform a management operation, you need to terminate all non-Administrator sessions. The following describes how to terminate sess.

Sometimes it is necessary for Oracle to terminate the current session. For example, if you want to perform a management operation, you need to terminate all non-Administrator sessions. The following describes all aspects of session termination, including:

1. Identify which sessions need to be terminated
2. terminate an Active Session
3. terminate an Inactive Session

When a session is terminated, any active transaction of the session is rolled back and all resources are released immediately, such as locks and memoryareas.
Use altersystem kill session to terminate a SESSION. The following example sid 7, serial #15:
Alter systemkill session '7, 15 ';

1. Identify which sessions need to be terminated
To identify the session to be terminated, you need to know the sid and serial # Of the session. You can query the v $ session to obtain it. For example, the following query identifies all sessions of the user wxlun:

SQL> SELECT SID, SERIAL #, STATUS FROM V $ SESSION WHERE USERNAME = 'wxlun ';

Sid serial # STATUS
----------------------------
19713 ACTIVE
95th 27537 INACTIVE

When a session is calling the database, the session status is ACTIVE. When a session is not calling the database, the session status is INACTIVE.

2. terminate an Active Session
If a user session is processing a transaction (ACTIVE) and terminates the session, the transaction is rolled back and the user immediately receives the following information:
ORA-00028: your session has been killed
If the statement continues until the database is reconnected after a ORA-00028 error is received, oracle returns the following information:
ORA-01012: not loggedon)
When a session is performing network I/O or transaction rollback, it cannot be terminated. This type of session can be terminated only after the operation is completed. In this case, resources are released until the session is terminated. In addition, if an ALTERSYSTEM is sent to terminate a session and the session is not terminated after 60 seconds, a message is received indicating that the session has been marked as ended. The status of the session marked as terminated in v $ seession is KILLED, and the status of some terminated services may be PSEUDO.

3. terminate an Inactive Session
If an InactiveSession is terminated, no ORA-00028 error is received immediately. The ORA-00028 error is not received until the user continues to use the terminated session.
When an inactivesession, the session status changes to KILLED, when the user uses this session again and receives a ORA-00028 error, this terminated session will be deleted from the v $ session.

The following is an example of terminating inactive session.

SQL> SELECT SID, SERIAL #, STATUS FROM V $ SESSION WHERE USERNAME = 'wxlun ';

Sid serial # STATUS
----------------------------
95th 27591 INACTIVE

SQL> alter system kill session '20180101 ';

System altered.

SQL> SELECT SID, SERIAL #, STATUS FROM V $ SESSION WHERE USERNAME = 'wxlun ';

Sid serial # STATUS
----------------------------
95th 27591 KILLED

SQL>

Related reading:

Oracle 10 DBMS_MONITOR tracks and analyzes other session SQL statements

Quickly locate trc files generated by other sessions

Oracle kill session

MySQL Master/Slave troubleshooting-session-level parameter replication error

How to view session blocking of Oracle Database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.