strace the current Oracle session process

Franck Pachot
Jul 6, 2018 · 1 min read

Here is my way to trace system calls from the current session process.
This must not be done in production.
An strace.log file will be generated with system calls

connect / as sysdba
column spid new_value pid
select spid from v$process join v$session on v$session.paddr=v$process.addr where sid=sys_context('userenv','sid');
column spid clear
set escape on
host strace -fyy -p &pid -o strace.log \& :
select * from v$osstat;

I add ‘:’ at the end of the command when used from sqlcl which adds a ‘;’ at the end of the line:

bash: -c: line 0: syntax error near unexpected token `;'
bash: -c: line 0: `SQLCLTERM=`stty -g 2>/dev/null` ; stty sane 2>/dev/null; export PATH="/media/sf_share/19c:$PATH" && strace -fy -p 5380 -o strace.log &; SQLCLEXIT=$? ; if test "M$SQLCLTERM" != "M" ; then stty "$SQLCLTERM" 2>/dev/null ; fi; exit $SQLCLEXIT'

I use ‘set escape on’ as I use the bash ‘&’ for background in the same command where I use the sqlplus ‘&’ for substitution.

An alternative to SET ESCAPE ON is the following:

define bg=&:
host strace -fy -p &pid -o strace.log &bg

Originally posted on Twitter, but improved here

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store