iTranslated by AI
How to Terminate Sessions in Amazon RDS for Oracle and SQL Server
1. Introduction
In this article, I will introduce how to forcefully terminate sessions in Amazon RDS for Oracle/SQL Server.
When attempting to disconnect a session using a database management tool, you may encounter the following error.
In this post, I will share SQL statements that allow you to disconnect sessions even in such cases.
[Error when trying to disconnect a session using the Oracle SQL Developer GUI]
ORA-01031: insufficient privileges
ORA-06512: at line 8
ORA-06512: at line 8
01031. 00000 - "insufficient privileges"
*Cause: An attempt was made to perform a database operation without
the necessary privileges.
*Action: Ask your database administrator or designated security
administrator to grant you the necessary privileges
2. Termination Method Using SQL
You can forcefully terminate a session by executing the following SQL.
■ Oracle
DECLARE
CURSOR c_sessions IS
SELECT sid, serial#
FROM v$session
WHERE username LIKE 'your_username';
BEGIN
FOR sess IN c_sessions LOOP
rdsadmin.rdsadmin_util.kill(sess.sid, sess.serial#);
END LOOP;
END;
■ SQL Server
DECLARE @KillCmd NVARCHAR(MAX) = N'';
SELECT @KillCmd = @KillCmd + 'KILL ' + CAST(session_id AS NVARCHAR(10)) + '; '
FROM sys.dm_exec_sessions
WHERE login_name LIKE 'your_username';
EXEC sp_executesql @KillCmd;
Appendix
How to Disconnect via Database Management Tools
I will also introduce how to disconnect sessions using database management tools.
■ Oracle SQL Developer
Launch Oracle SQL Developer.
Select "Tools" -> "Monitor Sessions".

Right-click the target session and select "Terminate Session".

■ SQL Server Management Studio
Launch SQL Server Management Studio.
Click the area indicated by the red line in the image below.

Right-click the target session and click "Kill Process".

Discussion