Kill Session Privileges To Users

PC & Tech Category

Last week I have faced one interested issue in my development database.

Our Application team tested one module in our database. They raised a database support request to our DBA team. Refer to the issue details.

Yesterday we have tested our application. There are numerous issues on the application side and also the database side. Large numbers of sessions are opened while accessing the database through the front end. Whenever we have to exit the application, sessions are not closed (Database sessions are hanging). Tonight we will plan to test the same application. The SCHEMA NAME is TEST. So we will need to kill the session privileges.

I am seeking any privilege is there, to kill the particular sessions. No direct session kill privileges are not available in oracle. I have found out the one article related to this same issue. They handled Created one procedure used to kill the session and grant execute on privileges to the users.

Steps

Step 1:

Create the procedure in Other schema (DBA LOGIN SCHEMA’S)

PROCEDURE NAME : kill_your_session


Create or replace procedure kill_your_session (in_sid in sys.v_$session.sid%type,
in_serial# in sys.v_$session.serial#%type)
as
row_count pls_integer ;
begin
select count (*)
into row_count
from v$session
where username = 'TEST' and sid = in_sid and serial# = in_serial# ;
if row_count > 0
then
execute immediate 'alter system kill session ''' ||
to_char (in_sid) || ', ' || to_char (in_serial#) || '''' ;
end if ;
end ;

Note:

Why am I not created the procedure in TEST schema?

The developer will change the code (like schema name change), its affect the another schema in database. So i have created the procedure in another schema.

Step 2:

Privileges assigned to execute the kill_your_session procedure to TEST schema.


GRANT EXECUTE ON kill_your_session to TEST;

Step 3:

Login as TEST schema.

Create the procedure in TEST schema

PROCEDURE NAME : pro_killsession


create or replace procedure pro_killsession(sid in number, serialnumber in number) as
begin
DBA.kill_your_session(in_sid => sid,in_serial# => serialnumber);
end;

Step 4:

Execute the below query to get SID, SERIAL# belongs to the user.


Select sid, serial#, status from v$session where username='TEST';

Step 5:

Execute the pro_killsession procedure & pass the arguments (Sid, Serial#)

I hope this article helped you to understand a kill the session privileges. Suggestions are welcome.

Tags:

Edward Ramamoorthy Avatar

Help Us Grow

If you like this post, please share it with your friends.

You are free to copy and redistribute this article in any medium or format, as long as you keep the links in the article or provide a link back to this page.

Subscribe to Newsletter




Privacy Settings

Privacy & Cookie Overview

Our website uses cookies to provide you with the best user experience possible. These cookies are stored in your browser and perform essential functions such as recognizing you when you return to our website, as well as helping us to understand which sections of the website you find most useful and engaging.

To learn more, you can read our Privacy & Cookie Policy or reach out through our Contact form.

Strictly Necessary Cookies

Strictly Necessary Cookies must always be enabled to ensure the proper functioning of this website and to allow us to provide you with excellent service. These cookies are also essential for saving your cookie preferences.

Google Adsense

We use Google AdSense to keep this site free by displaying relevant ads. AdSense requires essential cookies that cannot be disabled, but you can manage other cookies. We respect your privacy and provide options to control non-essential cookies.

For more details on how Google handles your data, visit Google's Data Usage Policy. Please review our Privacy Policy for more information on how we protect your data.

AddToAny

We use AddToAny for social sharing. It doesn’t store cookies, ensuring a privacy-friendly experience. AddToAny complies with GDPR and CCPA by default.

For more, see their Privacy Policy.

OneSignal

We use OneSignal to send notifications to users who opt in. OneSignal complies with GDPR and is certified under the EU-US and Swiss-US Privacy Shield frameworks.

For more, see their Privacy Policy.

3rd Party Cookies

This website utilizes third-party cookies, which can enhance your experience and support our ongoing efforts to improve our services.

Google Analytics

We use Google Analytics to collect anonymous data, such as visitor numbers and popular pages, to improve user experience and site performance. Keeping this cookie enabled helps us refine the site based on visitor activity.

For more information, see Google’s Privacy Policy.

Discover more from Prime Inspiration

Subscribe now to keep reading and get access to the full archive.

Continue reading