Oracle 11g has phantom connection
I have 11g installed locally on my machine (Windows 7 64bit).
When I have disconnected all my clients from my oracle (ie no sqlplus running, no weblogic running) and then reconnect using sqlplus and I run the following script:
SQL> set linesize 120
SQL> SELECT s.sid,
2 s.serial#,
3 s.username,
4 s.program
5 from v$session s
6 where username is not null;
SID SERIAL# USERNAME PROGRAM
---------- ---------- ------------------------------ ----------------------------------------------------------------
134 11274 FOO ORACLE.EXE (J000) <-- I want to remove this connection
139 19140 MYADMIN sqlplus.exe <-- My connection
155 8941 FOO ORACLE.EXE (J001) <-- I want to remove this connection
SQL>
So I am trying to programmatically remove the connections that I have labelled in blue.
I am using the following:
SQL> ALTER SYSTEM DISCONNECT SESSION 134,11274 IMMEDIATE;
ALTER SYSTEM DISCONNECT SESSION 134,11274 IMMEDIATE
*
ERROR at line 1:
OR开发者_开发知识库A-00026: missing or invalid session ID
Is this not the correct way? I have also tried
ALTER SYSTEM DISCONNECT SESSION '134,11274' IMMEDIATE;
When I try running the above again I will get the error message:
SQL> ALTER SYSTEM DISCONNECT SESSION '134,11274' IMMEDIATE;
ALTER SYSTEM DISCONNECT SESSION '134,11274' IMMEDIATE
*
ERROR at line 1:
ORA-00031: session marked for kill
So the connection doesn't seem to really go away.
I want to have a script that forces all 'FOO' connections to be terminated so that my build will run properly. But my script is not working. Do you have any ideas? The only reliable way I can get rid of connections is to reboot. Stopping and starting the service sometimes works - but not always - which is really weird.
Here's my PL/SQL script that I ultimately want to be able to run.
SET SERVEROUTPUT ON
SET LINESIZE 120
DECLARE
theKillCmd VARCHAR2(1000);
PROCEDURE msg(msg VARCHAR2) AS
BEGIN
DBMS_OUTPUT.PUT_LINE(msg);
END;
BEGIN
msg(' . ');
msg(' . ');
msg('Killing extraneous sessions.');
msg(' . ');
msg(' . ');
for conn in (SELECT s.sid,
s.serial#,
s.username,
s.program
FROM v$session s
WHERE s.USERNAME IS NOT NULL)
loop
msg( '. ' || conn.sid || ' ' || conn.serial# || ' ' || conn.username || ' ' || conn.program );
IF (conn.username = 'FOO') THEN
-- Following asks client process to kill itself
-- theKillCmd := 'ALTER SYSTEM KILL SESSION ''' || conn.sid || ',' || conn.serial# || ''' IMMEDIATE ';
-- Following tells server to kill process
theKillCmd := 'ALTER SYSTEM DISCONNECT SESSION ' || conn.sid || ',' || conn.serial# || ' IMMEDIATE ';
msg( '. ' || 'Killing connection using command : ' || theKillCmd );
EXECUTE IMMEDIATE theKillCmd ;
ELSE
msg('. Ignoring .. ');
END IF;
end loop;
END;
/
-- exit;
So if anyone has any ideas that would be appreciated.
I'm wondering if maybe I somehow botched the oracle installation - I don't want to yet go down the path of re-installing - would rather have a script that just kills oracle connections before I run ant oracle.
That Jnnn (J000 and J001) syntax indicates it is a "Job Queue Slave Process". If you kill it, the scheduler will probably just restart it.
Look at the appropriate DBMS_JOB or DBMS_SCHEDULER API.
精彩评论