In my previous articles I have given the way to find cumulative sum and queries like that. In this article I would like to give you the straightforward steps to find the Username who executed query with example. This is key DBA task. There are sometime DBA will face scenario where some people are running queries wrongly and due to that the DB will get locked. This article will give 3 simple queries with using which you can find out the username who executed query.
The question in mind that why we require to find the username for executed query. There are so many real world scenarios where you require to find out the username. The most common scenario is when application was facing the performance issue due to some queries. As in industry we are working with distributed environment and there are so many user sessions running parallelly. In this kind of situation you require to find out the username who executed the query so that we can find the root cause of the problem. Sometimes in reporting also we require usernames who are executing specific SQL statements.
We require to use the Oracle System tables to find out the Username who executed query. We commonly need to use the following 2 system tables and one system view which will give you the username.
1.DBA_HIST_ACTIVE_SESS_HISTORY
2.DBA_USERS
3.V$ACTIVE_SESSION_HISTORY
Scenario 1 : When you know the SQL query ID.
If you know the SQL query id you can use the System view directly to find out the User who has executed the query. Lets say the SQL id is “am66usf0p71f”
Query :
Select USER_ID from V$ACTIVE_SESSION_HISTORY where SQL_ID = ‘am66usf0p71f’;
Output:
3430
Scenario 2 : When you know the SQL query ID but don’t have access to system views
Sometimes you may not have access for system views. You require to use system tables.
Query :
select USER_ID from DBA_HIST_ACTIVE_SESS_HISTORY where SQL_ID = ‘da66usnr0p71f’;
Scenario 3 : You need to find out the Username by User_id
You can find out the user_id by above two scenarios. But if you want to find out username use below query.
Query :
select USER_ID,USERNAME from DBA_USERS where USER_ID = ‘3430’;
These are few queries with using which you can find out the Username for particular user. I hope you like this article. If you like this article or if you have any issues with same kindly comment in comments section.
In my previous article I have given details about application support engineer day to day…
In my previous articles I have given the roles and responsibilities of L1,L2 and L3…
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…