问题
I wonder if this could be possible or not.
I am using TOAD, connected to an oracle database (11g) and i have access to the oracle E-BUSINESS-SUITE application.
Basically, i want Toad to trace what sql are being executed by the oracle E-BUSINESS-SUITE application
I have this query:
SELECT nvl(ses.username,'ORACLE PROC')||' ('||ses.sid||')' USERNAME,
SID,
MACHINE,
REPLACE(SQL.SQL_TEXT,CHR(10),'') STMT,
ltrim(to_char(floor(SES.LAST_CALL_ET/3600), '09')) || ':'
|| ltrim(to_char(floor(mod(SES.LAST_CALL_ET, 3600)/60), '09')) || ':'
|| ltrim(to_char(mod(SES.LAST_CALL_ET, 60), '09')) RUNT
FROM V$SESSION SES,
V$SQLtext_with_newlines SQL
where SES.STATUS = 'ACTIVE'
and SES.USERNAME is not null
and SES.SQL_ADDRESS = SQL.ADDRESS
and SES.SQL_HASH_VALUE = SQL.HASH_VALUE
and Ses.AUDSID <> userenv('SESSIONID')
order by runt desc, 1,sql.piece
The oracle application looks like this:
I want to do this because i want to know which tables the oracle application is using in order to obtain the contact information for a certain customer. I mean, when a random guy is using the application, he put the account_number and click on "go". Thats what i need!, i want to know which tables are executed when the guy pressed the "go" button, i want to trace that.
I think that i could get the session_id from the guy that is using the oracle application and then, paste it on the query written above and start working on it.
Something like this:
If it is possible, how could i get the session_id from the guy that is using the oracle E-BUSINESS-SUITE Application?
回答1:
Tracing the queries an active software app is running might take a while. As such it might be easier to dig the data out another way:
You want to know which table and column holds some data, like a user first name.
Generate something unique, like a GUID or some impossible name that never occurs in your db (like 'a87d5iw78456w865wd87s7dtjdi') and enter that as the First name using the UI. Save the data
Run this query against oracle:
SELECT
REPLACE(REPLACE(
'UNION ALL SELECT ''{t}'', ''{c}'' FROM {t} WHERE {c} = ''a87d5iw78456w865wd87s7dtjdi'' ',
'{t}', table_name),
'{c}', column_name
)
FROM USER_TAB_COLUMNS WHERE data_type like '%char%'
This is "an sql that writes an SQL" - It'll generate a result set that is basically a list of sql statements like this:
UNION ALL SELECT 'tablename', 'columnname' FROM tablename WHERE columnname = 'a87d5iw78456w865wd87s7dtjdi'
UNION ALL SELECT 'table2name', 'column2name' FROM table2name WHERE column2name = 'a87d5iw78456w865wd87s7dtjdi'
UNION ALL SELECT 'table3name', 'column3name' FROM table3name WHERE column3name = 'a87d5iw78456w865wd87s7dtjdi'
There will be one query for each column in each table in the db. Only CHARacter columns will be searched, by the way
Remove the first UNION ALL
Run it and wait a looong time while oracle basically searches every column in every table, in the db, for your weird name.
Eventually it produces an output like:
TABLE_NAME COLUMN_NAME
crm_contacts_info first_name
So you know your name a87d5iw78456w865wd87s7dtjdi
was saved, by the UI, in crm_contacts_info.first_name
回答2:
If it is possible, how could i get the session_id from the guy that is using the oracle E-BUSINESS-SUITE Application?
Yes, this is definitely possible. First things first, you need to figure out which schema/username "the guy" is using. If you don't know, you can ask the guy or have him run some simple query (something like select user from dual;
will work) to get that info.
Once you have the schema name, you can query the V$SESSION
table to figure out the session id. Have the guy log in, then query the V$SESSION
table. Your query would look something like this: select * from v$session where username ='[SCHEMA]';
where [SCHEMA]
is the schema name that the guy is using to log in. This will give you the SID, serial #, status etc. You will need this info to trace the guy's session.
Generating a trace file for the session is relatively simple. You can start a trace for the entire database, or just for one session. Since you're only interested in the guy's session, you only need to trace that one. To begin the trace, you could use a command that looks something like this: EXEC DBMS_MONITOR.session_trace_enable(session_id=>[SESSIONID], serial_num=>[SERIAL#]);
where [SESSIONID]
and [SERIAL#]
are the numbers you got from the previous step. Please keep in mind that the guy will need to be logged in for the session trace to give you any results.
Once the guy is logged in and you have enabled session trace, have the guy run whatever commands from the E-Business suite that you're interested in. Be aware that the more the guy (or the application) does while the trace is enabled, the more information you will have to get through to find whatever it is you're looking for. This can be a TON of data with applications. Just warning you ahead of time.
After the guy is finished doing the tasks, you need to disable the trace. This can be done using the DBMS_MONITOR package like before, only slightly different. The command would look something like this: EXEC DBMS_MONITOR.session_trace_disable(session_id=>[SESSIONID], serial_num=>[SERIAL#]);
using the same [SESSIONID]
and [SERIAL#]
as before.
Assuming everything has been done correctly, this will generate the trace file. The reason why @thatjeffsmith mentioned server access is because you will need to access whatever server(s) the database lives on in order to get the trace file. If you do not have access to the server, you will need to work with a DBA or someone with access in order to get it. If you just need help figuring out where the trace file is, you could run the following query using the [SESSIONID]
from before:
SELECT p.tracefile
FROM v$session s
JOIN v$process p ON s.paddr = p.addr
WHERE s.sid = [SESSIONID];
This should return a directory that looks similar to this: /u01/app/oracle/diag/rdbms/[database]/[instance]/trace/[instance]_ora_010719.trc
Simply navigate to that directory, pull the trace file using WinSCP, FileZilla, or the app of your choice, and that should do it.
Good luck, and hope this helps!
回答3:
The SQLs executed from the EBS frontend are usually too fast to be seen in v$session. If a SQL is slower than a second (of if the snapshot timing is right), you would see it in v$active_session_history, which captures a snapshot of all active sessions every second.
The place you should look instead at is v$sqlarea, which can be done by SQL, via Toad using the Database->Monitor->SGA Trace/Optimization menu option or by our Blitz Report https://www.enginatics.com/reports/dba-sga-sql-performance-summary/.
This data however has information on module (i.e. which OAF page, Form, Concurrent etc.) and responsibility (action column) level only and it does not contain session or application user information.
The unique key is sql_id and plan_hash_value, which means that for SQLs executed by different modules and from different responsibilities, only the module executing it first will be shown.
If you sort the data by last_active_time and filter for the module in question, it's almost as good as a trace. Bind values used can be retrieved from v$sql_bind_capture, which above Blitz Report does as well.
来源:https://stackoverflow.com/questions/54075616/trying-to-know-which-tables-are-executed-in-the-oracle-external-application