The title pretty much says it. In Oracle 11.2, if you have the Diag+Tuning Pack licenses and the SQL monitoring kicks in for your SQL statement, then instead of the old fashioned ERRORSTACK dump reading you can just query the V$SQL_MONITOR.BIND_XML to find the values and metadata of your SQL statement’s bind variables.
I’ve written an example here:
And a related comment – V$SQL_BIND_CAPTURE is not a reliable way for identifying the current bind variable values in use. Oracle’s bind capture mechanism does not capture every single bind variable into SGA (it would slow down apps which run lots of short statements with bind variables). The bind capture only selectively samples bind values, during the first execution of a new cursor and then every 15 minutes from there (controlled by _cursor_bind_capture_interval parameter), assuming that new executions of that same cursor are still being started (the capture happens only when execution starts, not later during the execution).





I just made an update to the tech.e2sn article and added a comment about a related parameter “_sqlmon_binds_xml_format”
One word: WOOOW !!
Thanks,
Dani
I think my first comment went into spam. Now it is not allowing me to post that again but i just wanted to say “awesome” ;)
Tanel,
this is for session which is currently running now, what about the session which was completed few min/hour back and I want to capture all sql’s and used binds that session executed, is this possible in 11g R2 ?
I am on 11.1 and facing really touch time for bind capturing as there is no column for sid, I have to trust sql_id.
can you hack binds in 11.1 for sid’s ? (sessions completed / currently running)
Rich
@Rich
If the session / SQL is already finished, then this information is gone. If you know in advance that you want to capture a session, then SQL_TRACE with bind tracing enabled will capture everything you need…
I mentioned that V$SQL_BIND_CAPTURE is unreliable for capturing ALL binds used… but it can be enough if you want just occasional bind variable samples (taken 1st hard parse and every 15mins if new executions keep being done)
I trust you completely that sql_bind_capture is unreliable, its good but too late that Oracle thought about real time bind capture ..
thanks for this info.
Rich ..
I forgot about one thing,
with the help of dbms_xplan we can get the info of peeked bind.
select child_number, executions, buffer_gets, is_bind_sensitive, is_bind_aware, is_shareable,PLAN_HASH_VALUE,hash_value,sql_profile,OBJECT_STATUS from v$sql where sql_id = ‘&sql_id’ ;
CHILD_NUMBER EXECUTIONS BUFFER_GETS IS_BIND_SENSITI IS_BIND_AWARE IS_SHAREABLE PLAN_HASH_VALUE HASH_VALUE SQL_PROFILE OBJECT_STATUS
———— ———- ———– ————— ————— ————— ————— ———- ————————- ——————–
0 711331 105370222 N N Y 1242873453 2773956540 VALID
1 486416 71533540 N N Y 1242873453 2773956540 VALID
2 404571 59230134 N N Y 1242873453 2773956540 VALID
4 678763 100323603 N N Y 1242873453 2773956540 VALID
Select * from table(dbms_xplan.display_cursor(‘&&sql_id’, &&child_num,’basic +PEEKED_BINDS’));
Yes that’s right V$SQL_BIND_CAPTURE is not reliable.
Tanel, thanks, useful !
However, I discovered that V$SQL_MONITOR doesn’t show all bind variables.
For example ( I am on 11.2.0.2 ), it doesn’t show inputs to pipelined table functions made as bind variables ( Errorstack dump reading does this ).
This reproduces for me:
Then, in another session
Note that bind variable named INL is not listed here.
Errorstack however shows
Are you aware of any workaround ?
Thanks
Matthias
Thanks for the comment, no I didn’t know about this limitation. So I don’t know of any other workarounds, other than the errorstack approach…
Hello,
I just want to let you know that (thanks to this post) i created an sql script to retrieve peeked and passed values per execution, see: http://bdrouvot.wordpress.com/2013/04/29/bind-variable-peeking-retrieve-peeked-and-passed-values-per-execution-in-oracle-11-2/
One more time: Thanks Tanel ! ;-)
Bertrand