Find last query executed by specific session in Snowflake

Snowflake enables you to check last query executed by each session.

To list sessions: List active sessions

Notes

Function used in this query return query activity within the last 7 days and maximum 100 of them.

Query

select query_text,
       warehouse_name,
       database_name,
       schema_name,
       user_name,
       role_name,
       execution_status,
       error_code,
       error_message,
       start_time,
       end_time
from table(information_schema.query_history_by_session(session_id))
order by start_time desc                        -- put session id here
limit 1;

Columns

  • query_text - most recent query text
  • warehouse_name - name of warehouse in which query was executed
  • database_name - name of database in which query was executed
  • schema_name - name of schema in which query was executed
  • user_name - name of user who executed query
  • role_name - role name of user who executed query
  • execution_status - current status of executed query
  • error_code - error code, if the query returned an error
  • error_message - error message, if the query returned an error
  • start_time - start time of query
  • end_time - end time of query

Rows

Query return just one row with last query information executed by specific session.

Sample results

sample results

Using Web User Interface

In Web User Interface you can watch last query by clicking on Query tab (1) . To obtain last query excuted by specific session, we need to add filter by clicking on Add a filter (2).

Next, select Session ID type of filter (3) and provide session id in text box (4).

The first row shows last query executed by provided session id.

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.