📜  oracle kill job by sid - SQL (1)

📅  最后修改于: 2023-12-03 15:18:08.545000             🧑  作者: Mango

Oracle Kill Job by SID - SQL

In Oracle, it is sometimes necessary to kill a long-running job or session by its SID (System ID). This can be done using the following SQL statement:

ALTER SYSTEM KILL SESSION '<SID>,<SERIAL#>';

where <SID> and <SERIAL#> are the specific values of the job or session that you want to kill. These values can be obtained from the V$SESSION view.

Before executing this statement, it is important to determine which job or session you want to kill. This can be done using the following SQL query:

SELECT s.sid, s.serial#, s.username, s.status, s.osuser, s.machine, s.program
FROM v$session s
WHERE s.status = 'ACTIVE';

This query will return a list of all currently active sessions, along with their SID, serial number, username, status, OS user, machine, and program. From this list, you can identify the session that you want to kill and obtain its SID and serial number.

Once you have identified the session that you want to kill and obtained its SID and serial number, you can execute the following SQL statement to kill the session:

ALTER SYSTEM KILL SESSION '<SID>,<SERIAL#>';

Note that killing a session in Oracle is a serious action that should only be taken as a last resort. Killing a session can cause data corruption or loss if not done properly. It is important to ensure that the session you are killing is not performing any critical operations before executing the ALTER SYSTEM KILL SESSION statement.

In summary, killing a job or session in Oracle by its SID can be done using the ALTER SYSTEM KILL SESSION statement with the SID and serial number of the session. To obtain the SID and serial number, you can use the V$SESSION view and a SQL query. However, killing a session should only be done as a last resort and with caution to avoid data loss or corruption.