I only get one sql_address for each session id. I am assuming this is
the sql address of current or last sql statement run by this
session (assmuning sql satements have not been flushed from SGA).
How can I find all the sql's run by a session?
Thanks.
You can enable tracing for your own session,
alter session set sql_trace=true;
...or, if you have execute on sys.dbms_system.set_ev, then for another
existing session:
exec sys.dbms_system.set_ev(sid,serial#,10046,1,'')
In both cases, you will capture the sql from the time tracing was
enabled going forward (but not prior to that time).
You can also set tracing it for all future sessions (which could be too
much if you are doing it on a busy database):
init.ora
sql_trace=true
..or, if you use after logon trigger, for some future sessions (you
decide which ones in the logic of the trigger), e.g.
http://www.oracle.com/technology/oramag/code/tips2003/042703.html
Kirill
Also some of my sql statement are longer than 1000 characters, they get
chopped in statspack output.
I want to find sql statements which take most cpu time etc. All this
information is available in v$ views, but when I started with
V4session, I was surprised to find it only shows me address of one sql
statement, that's why I am posting this question.
>
> How can I find all the sql's run by a session?
Auditing would be a good start.
> What I am looking for is to look at V$sql views and find various types
> of sql statements executed, how long they take etc.
V$SQL doesn't support that. As soon as there is need for space in shared
pool, old SQL is purged out of V$SQL. You can use DBA_HIST views in 10g,
only you have to pay for it. In 9.2 there is no way to do that.
Setting trace on from another session will only trace SQL statements
ran after the trace is set on so I think the only practical solution is
to set trace on when the session of interest starts. If the actual
user task cannot be modified to set trace on then perhaps a database
logon event trigger could be used.
HTH -- Mark D Powell --
> Setting trace on from another session will only trace SQL statements
> ran after the trace is set on so I think the only practical solution is
> to set trace on when the session of interest starts. If the actual
> user task cannot be modified to set trace on then perhaps a database
> logon event trigger could be used.
Mark, the question here is what do you want to see. Usually, the auditing
requirements are to preserve all information pertaining to modifying
business critical data and executing certain privileged operations on the
database. That is covered with auditing. Fine grained auditing (DBMS_FGA)
does preserve SQL and can be triggered by select statement. If, on the
other hand, you want to see how many times did somebody go to football and
NCAA pools, you're out of luck.
statspack also gives you the hash or sql_address
you can look into v$sqltext for full statement.
you can look into v$open_cursor for all sql, but it's not guaranteed
to be there.
also, turning on tracing for 1 or 2 sessions shouldn't be a big deal
as long as you know what you're doing.
.......
We run Oracle 9.2.0.6 on RH4 AMD
remove NSPAM to email