Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropping Oracle connections using a query

I wanted to drop/kill connections made to specific schema of a database. Could you please sugest a prudent way to do this?

Cheers

like image 866
Priyank Avatar asked May 15 '26 13:05

Priyank


1 Answers

In order to prevent a user from connecting you could lock the account:

ALTER USER usr ACCOUNT LOCK;

If you want to disconnect all sessions of a user, you could use the method described in another SO:

BEGIN
   FOR x IN (SELECT Sid, Serial# FROM v$session WHERE username = 'USR') LOOP
      EXECUTE IMMEDIATE 'Alter System Kill Session ''' || x.Sid || ',' 
                        || x.Serial# || ''' IMMEDIATE';
   END LOOP;
END;
like image 152
Vincent Malgrat Avatar answered May 19 '26 04:05

Vincent Malgrat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!