In many cases, we need to terminate all Oracle processes ). When the database is "locked" and you cannot enter Server Manager to terminate the database, you can use the kill command in UNIX to terminate all Oracle processes. This is one of the common uses of the kill command.
To terminate an Oracle instance on a UNIX server, perform the following steps:
Terminate all Oracle processes related to ORACLE_SID.
Use the ipcs-pmb command to identify all occupied RAM memory fragments.
Use the ipcrm-m command to release the occupied RAM memory from UNIX.
For Non-AIX only: Use the ipcs-sa command to display the occupation mark, and use the ipcrm-s command to release the occupation mark of the instance.
It is very easy to create a single command to terminate the Oracle process related to the hung database instance. In the following example, we use the ps command to identify the Oracle process, and then use the awk program to obtain the process ID (PID) of the Oracle process ). Then, we enter the process ID in the kill command of UNIX.
Root> ps-ef | grep $ ORACLE_SID | grep-v grep | awk '{print $2}' | xargs-I kill-9 {}
After terminating all Oracle processes, we can use the ipcs-pmb command to check the occupied memory and clear the memory occupied by the database. We first show all memory usage on the database server:
Ipstatus from/dev/kmem as of Mon Sep 10 16:45:16 2001
T ID KEY MODE OWNER GROUP SEGSZ CPID LPID
Shared Memory:
M 24064 0x4cb0be18 -- rw-r ----- oracle dba 28975104 1836 23847
M 1 0x4e040002 -- rw-root 31008 572 572
M 2 0x411ca945 -- rw-root 8192 572 584
M 4611 0x0c6629c9 -- rw-r ----- root 7216716 1346
M 4 0x06347849 -- rw-root 77384 1346
Root> ipcs-pmb
Now, we can see that Oracle only has one RAM memory with ID = 24064. The following command releases the memory segment: root> ipcrm-m 24064