Life Without Tools: Monitoring Database Activity With The Power of SQL
Life Without Tools: Monitoring Database Activity With The Power of SQL
Monitoring
Database Activity
With The Power Of
SQL
Ari Kaplan
Independent Consultant
Topic Overview
Which users are logged on to the database?
V$ROLLNAME V$LOCK
NAME ID1
USN SID
TYPE
V$PROCESS LMODE
ADDR
PID V$SESSION
SPID
SID
USERNAME
TERMINAL PADDR
Which Rollback Segments Are Being
Used By Which User Accounts?
echo “Enter the password for the SYSTEM user:”
read PASSWD
sqlplus system/$PASSWD << EOF
spool temp.lst
set head off
set pagesize 0
connect system\$PASSWD@DBNAME
SELECT to_char(rownum+3)||’) ‘||rpad(r.name,17)||rpad(to_char(p.pid),11) ||
rpad(s.sid,6)|| rpad(p.spid,11) || rpad(nvl(p.username,’NO TRANSACTION’),17) ||
rpad(p.terminal,8)
FROM v\$lock l, v\$process p, v\$rollname r, v\$session s
WHERE l.sid = s.sid (+) AND p.addr = s.paddr AND
l.type(+)=‘TX’ AND l.lmode(+)=6 AND
trunc(l.idl1(+)/65536)=r.usn
UNION
SELECT ‘2) ROLLBACK SEG;ORACLE PID; SYSTEM PID; SID; TRANSACTION;
TERMINAL’
FROM dual
UNION SELECT ‘1) ‘ FROM dual
UNION SELECT ‘3) ---------------- ---------- ---------- ----------- --------’ FROM dual
ORDER BY 1;
EOF
Which Rollback Segments Are Being
Used By Which User Accounts?
Below is a sample output from the preceding SQL:
1)
2) ROLLBACK SEGMENT; ORACLE PID; SYSTEM PID; SID; TRANSACTION; TERMINAL
3)------------------------- --------------- --------------- ---- ----------------- ------------
4) R01 70 1632 14 oracle ?
5) BIG_ROLL 65 1492 21 oracle ?
What Has The Largest Number Of
Concurrent Users Been?
set pagesize 24
SELECT rpad(c.name||’:’,11)||chr(9)||chr(9)||
‘cumulative logons=‘||rpad(substr(a.value,1,12),12)||chr(9)||
‘highwater mark=‘||b.sessions_highwater||chr(9)
Output from
the preceding
SQL:
comp.databases.oracle.server
comp.databases.oracle.tools
comp.databases.oracle.misc
There are over 370 tips and answers to questions that have been posed to me over the
years. This paper will be downloadable from the web page as well.