How to Abort / Kill a Snowflake Session or Cancel a Query

With the correct permissions and a session id, or query id, you either abort an existing session, or cancel / kill a running query.

To abort a session, you must 1st obtain the session id:

Show your own session id:

select current_session();

Show all active sessions:

Both from AccountAdmin role you can:

SHOW TRANSACTIONS IN ACCOUNT

or

select * from snowflake.account_usage.sessions;

Going to have to use AccountAdmin role to use this function.

select SYSTEM$ABORT_SESSION( <session_id> );

Here’s the link in the Snowflake documentation to abort a session:

https://docs.snowflake.com/en/sql-reference/functions/system_abort_session.html#system-abort-session

There is also a system function to cancel all queries for a given session, documented here:

https://docs.snowflake.com/en/sql-reference/functions/system_cancel_all_queries.html

To cancel a given query by query id use this:

https://docs.snowflake.com/en/sql-reference/functions/system_cancel_query.html

select

SYSTEM$CANCEL_QUERY( <query_id> )

Leave a Comment

Scroll to Top