Today,One of the users told me that they cannot connect to one of our QA environment. Initially i though that database was down. But i was wrong, DB was up and running. When I tried logging in i got an error ORA-00020: maximum number of processes 300 exceeded.
At first i tried killing inactive session
select 'ALTER SYSTEM KILL SESSION '''||SID||','||SERIAL#||''' ;' from v$session where status='INACTIVE';
But this did not help and though number of sessions from v$session were reduced number of processes(v$process) were still the same.
After some googling i found a good query on Clean up sessions/processes to clean up sessions depending on processes.
SELECT 'ALTER SYSTEM KILL SESSION '''||s.SID||','||s.SERIAL#||''' ;' FROM gv$session s JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id WHERE s.type != 'BACKGROUND';
Be careful not to kill sys or oracle sessions. Your database may crash.
Some other workarounds are
- Restart your database so that any orphan processes are cleaned up
- Kill session from os level by looking at v$process or
ps -ef | grep ora --(Think before doing this and kill only unwanted processes)
- Increase processes parameter using below query and then reboot your system
alter system set processes=some_high_number scope=spfile;