Skip to main content
The CANCEL SESSION statement lets you stop long-running sessions. CANCEL SESSION will attempt to cancel the currently active query and end the session.

Required privileges

To view and cancel a session, the user must be a member of the admin role or must have the VIEWACTIVITY system privilege (or the legacy VIEWACTIVITY role option) and the CANCELQUERY system privilege (or the legacy CANCELQUERY role option) defined. Non-admin users cannot cancel admin users’ sessions.

Synopsis

cancel_session syntax diagram

Parameters

Example

Cancel a single session

In this example, we use the SHOW SESSIONS statement to get the ID of a session and then pass the ID into the CANCEL SESSION statement:
You can also cancel a session using a subquery that returns a single session ID:

Cancel multiple sessions

Use the SHOW SESSIONS statement to view all active sessions:
To cancel multiple sessions, nest a SELECT clause that retrieves session_id(s) inside the CANCEL SESSIONS statement:
All sessions created by maxroach will be cancelled.

See also