Download - SQL Notools99
-
8/8/2019 SQL Notools99
1/27
Life Without Tools:Life Without Tools:MonitoringMonitoring
Database ActivityDatabase ActivityWith The Power OfWith The Power Of
SQLSQLAri KaplanAri Kaplan
Independent ConsultantIndependent Consultant
-
8/8/2019 SQL Notools99
2/27
Topic OverviewWhich users are logged on to the database?Which users are logged on to the database?
What SQL statement is a particular user accountWhat SQL statement is a particular user account
executing?executing?
Setting up an interactive script for viewing users and SQLSetting up an interactive script for viewing users and SQL
What is myWhat is my datafiledatafile activity like?activity like?
Which rollback segments are being used by which userWhich rollback segments are being used by which user
accounts?accounts?
What has the largest number of concurrent users been?What has the largest number of concurrent users been?Which locks are being held?Which locks are being held?
Which users have hogged up the most CPU usage?Which users have hogged up the most CPU usage?
What is the archiving status of the database?What is the archiving status of the database?
-
8/8/2019 SQL Notools99
3/27
Quick Overview of TypicalQuick Overview of TypicalMonitoring ViewsMonitoring Views
DDaattaaDDiiccttiioonnaarryyVViieeww WWhhaattIItt hhoowwss
DDBB __FFRREEEE__SSPP EE FFrreeeecchhuunnkkssooffttaabblleessppaaccee
DDBB __DD TT __FFIILLEESS DDaattaa FFiilleellooccaattiioonn aann ssiizzeess
VV$$FFIILLEESSTT TT RReeaa ss//WWrriitteessttoo aattaaffiilleess
VV$$SSGG SSTT TT DDeettaaiillee sshhaarree ppooooll iinnffoorrmmaattiioonn ((ffrreeeemmeemmoorryy,, eettcc))
VV$$RROOLLLLSSTT TT RRoollllbbaacckk SSeeggmmeennttIInnffoorrmmaattiioonn ((sshhrriinnkkss,, ooppttiimmaall ssiizzee,, ))
VV$$SSEESSSSIIOONN IInnffoorrmmaattiioonn oonn ccoonnnneeccttiioonnss
VV$$SSYYSSSSTT TT 220000 ssyysstteemm--wwii eessttaattiissttiiccss
VV$$PP RR MMEETTEERR IInniittiiaalliizzaattiioonn ppaarraammeetteerr sseettttiinnggss
VV$$LLOO LLoocckksswwiitthhiinn tthhee aattaabbaassee
DDBB __SSEEGGMMEENNTTSS SSeeggmmeennttssaann hhooww mmaannyy eexxtteennttss,, nneexxtteexxtteenntt
-
8/8/2019 SQL Notools99
4/27
Who Is Logged On?Who Is Logged On?
The $SESSION view containsThe $SESSION view containsinformation on all active sessions:information on all active sessions:
SELECTSELECT sid, schemaname, osusersid, schemaname, osusersubstr(machine,1,20) Machinesubstr(machine,1,20) Machine
FROMFROM v$sessionv$session
ORDER BYORDER BY schemaname;schemaname;
-
8/8/2019 SQL Notools99
5/27
A sample output from the above SQL follows:A sample output from the above SQL follows:
SIDSID SCHEMANAMESCHEMANAME OSUSEROSUSER MACHINEMACHINE
11 SYSSYS
22 SYSSYS
33 SYSSYS
44 SYSSYS
77 SYSTEMSYSTEM platplat headqheadq1313 SYSTEMSYSTEM oracleoracle headqheadq
66 WWW_DBAWWW_DBA oracleoracle uk_officeuk_office
1414 WWW_DBAWWW_DBA oracleoracle uk_officeuk_office
1212 PRODMANPRODMAN mr_bossmr_boss ny_officeny_office
Who Is Logged On?Who Is Logged On?
SELECT sid, schemaname, osuser, substr(machine,1,20) Machine
FROM v$session
ORDER BY schemaname;
-
8/8/2019 SQL Notools99
6/27
What QL tate ent Is AWhat QL tate ent Is A
articular User Acc
ount xec
uting?ar
ticular User Acc
ount
xecut
ing?SELECTSELECT sql_textsql_text
FROMFROM v$sqlareav$sqlarea
WHEREWHERE (address, hash_value)(address, hash_value) ININ
((SELECTSELECT sql_address,sql_address,
sql_hash_valuesql_hash_value
FROMFROM v$sessionv$sessionWHEREWHERE sid = &sid_number);sid = &sid_number);
-
8/8/2019 SQL Notools99
7/27
A sample output from the above SQL follows:A sample output from the above SQL follows:Enter value for sid_numberEnter value for sid_number:: 1717
old 1: WHERE SID = &sid_numberold 1: WHERE SID = &sid_number
new 1: WHERE USERNAME = 17new 1: WHERE USERNAME = 17SQL_TEXTSQL_TEXT
Update EMP set first_name = Ari whereUpdate EMP set first_name = Ari wherefirst_name = Arie;first_name = Arie;
What QL tate entIs A articular User AccountWhat QL tate entIs A articular User Accountxecuting?xecuting?
SELECTSELECT sql_textsql_text
FROMFROM v$sqlareav$sqlarea
WHEREWHERE (address, hash_value)(address, hash_value) ININ((SELECTSELECT sql_address,sql_address,
sql_hash_valuesql_hash_value
FROMFROM v$sessionv$session
WHEREWHERE sid = &sid_number);sid = &sid_number);
-
8/8/2019 SQL Notools99
8/27
UNIX Script SQL_RUNUNIX Script SQL_RUN
SELECTSELECT sid, schemaname, osuser,sid, schemaname, osuser,
substr(machine,1,20) Machinesubstr(machine,1,20) Machine FROMFROM v$sessionv$session
ORDER BYORDER BY schemaname;schemaname;
Setting Up An InteractiveScript or ViewingSetting Up An InteractiveScript or ViewingUsers AndSQLUsers AndSQL
SQL Script SQL1.SQLSQL Script SQL1.SQL
SELECTSELECT sql_textsql_text
FROMFROM v$sqlareav$sqlarea
WHEREWHERE (address, hash_value)(address, hash_value) ININ
((SELECTSELECT sql_address,sql_address,
sql_hash_valuesql_hash_value
FROMFROM v$sessionv$sessionWHEREWHERE sid= sid_number;sid= sid_number;
SQL Script SQL2.SQLSQL Script SQL2.SQL
Who is logged
in to the
database?
What SQL is
used?
echo Enter the database to connect to:
read DATABASEecho Enter the password for the SYSTEM user:
stty -echoecho Password:\c
read PASSWD
stty echo
echo sqlplus system/$PASSWD\@DATABASE
-
8/8/2019 SQL Notools99
9/27
SELECTSELECT file_name, phyrds, phywrts,file_name, phyrds, phywrts,
decode(phyrds,0,0,phyblkrd/phyrds) Blocks/Readdecode(phyrds,0,0,phyblkrd/phyrds) Blocks/Read
decode(phywrts,0,0,phyblkwrt/phywrts) Blocks/Writedecode(phywrts,0,0,phyblkwrt/phywrts) Blocks/Write
FROMFROM dba_data_files, v$filestatdba_data_files, v$filestat
WHEREWHERE dba_data_files.file_id=v$filestat.file#dba_data_files.file_id=v$filestat.file#;;
FILE_NAMEFILE_NAME PHYRDSPHYRDS PHYWRTSPHYWRTS BLOCKS/READBLOCKS/READ BLOCKS/WRITEBLOCKS/WRITE
/u01/oradata/PRODDB/system01.dbf 10243 3478 4.928/u01/oradata/PRODDB/system01.dbf 10243 3478 4.928 11
/u02/oradata/PRODDB/rbs01.dbf 1759 49649 1/u02/oradata/PRODDB/rbs01.dbf 1759 49649 1 11
/u03/oradata/PRODDB/temp01.dbf 0 0 0/u03/oradata/PRODDB/temp01.dbf 0 0 0 00
/u04/oradata/PRODDB/tools01.dbf 0 0 0/u04/oradata/PRODDB/tools01.dbf 0 0 0 00/u05/oradata/PRODDB/ctxdata01.dbf 187293 15846 1.959/u05/oradata/PRODDB/ctxdata01.dbf 187293 15846 1.959 11
/u05/oradata/PRODDB/ctxdata02.dbf 455377 397 4 14. 258/u05/oradata/PRODDB/ctxdata02.dbf 455377 397 4 14. 258 11
/u05/oradata/PRODDB/ctxindex01.dbf 332860 616291 1.248 1/u05/oradata/PRODDB/ctxindex01.dbf 332860 616291 1.248 1
/u02/oradata/PRODDB/rbs02.dbf 91528 11593 6.130/u02/oradata/PRODDB/rbs02.dbf 91528 11593 6.130 11
What is y datafile activity like?What is y datafile activity like?
-
8/8/2019 SQL Notools99
10/27
Which oll ack Seg ents AreWhich oll ack Seg ents Areeing Used y Which Usereing Used y Which User
Accounts?Accounts? SET T A SACTIO USE OLL ACKSEGMENT
roll ack seg ent_na e specifies a roll ack seg entto
use. This is issued first, or i ediately after COMMIT orOLL ACK.
UseV OLLSTAT andV OLLNAME to getgeneralroll ack seg entactivity
LinkV OLLNAME withV LOCKandV SESSION todeter ine whichusers areusing which roll ack seg ents.
More infor ation on theusers can e collected y furtherjoining withtheV OC ESS view.
-
8/8/2019 SQL Notools99
11/27
Which oll ack Seg ents AreWhich oll ack Seg ents Areeing Used y Which Usereing Used y Which User
Accounts?Accounts? When a user is doing roll ack activity, Oracle creates a
latch (lock oftype TX) on an extentof a roll ack
seg ent.
The USN (UniqueSerial Number) ofV OLLNAME linkswithV LOCKsID1 column. TheID1 column containstheobject idoftheobject(rollback segment) being locked.
TheV LOCKview contains a SID column which linkstotheSID column ofV SESSION.
TheV SESSION view linkstotheV OC ESS view via theADDR column.
-
8/8/2019 SQL Notools99
12/27
NAMENAME
USNUSN
WhichRollback Segments Are eingWhichRollback Segments Are eingUsed y Which User Accounts?Used y Which User Accounts?
V$ROLLNAMEV$ROLLNAME
ID1ID1
SIDSID
TYPETYPE
LMODELMODE
V$LOCKV$LOCK
SIDSID
PADDRPADDR
V$SESSIONV$SESSIONADDRADDRPIDPID
SPIDSPID
USERNAMEUSERNAME
TERMINALTERMINAL
V$PROCESSV$PROCESS
NOTE: Only relevant columns are listed with tables
-
8/8/2019 SQL Notools99
13/27
echo Enter the password for the SYSTEM user:echo Enter the password for the SYSTEM user:
read PASSWDread PASSWD
sqlplus system/$PASSWD
-
8/8/2019 SQL Notools99
14/27
-
8/8/2019 SQL Notools99
15/27
WhatHas The LargestNumber OfWhatHas The LargestNumber OfConcurrentUsers een?ConcurrentUsers een?
setpagesize 24setpagesize 24
set linesize 100set linesize 100
SELECTSELECT rpad(c.name||:,11)||chr(9)||chr(9)||rpad(c.name||:,11)||chr(9)||chr(9)||
rpad( current logons=||(to_number(b.sessions_current)rpad( current logons=||(to_number(b.sessions_current)--1),20)||chr(10)||1),20)||chr(10)||
cumulative logons=||rpad(substr(a.value,1,12),12)||chr(9)||cumulative logons=||rpad(substr(a.value,1,12),12)||chr(9)||
highwater mark=||b.sessions_highwater||chr(9)highwater mark=||b.sessions_highwater||chr(9)
FROMFROM v$sysstat a, v$license b, v$database cv$sysstat a, v$license b, v$database c
WHEREWHERE a.name = logons cumulative;a.name = logons cumulative;
-
8/8/2019 SQL Notools99
16/27
PINDB: current logons=298 cumulativePINDB: current logons=298 cumulative
logons=7967 highwater mark=391logons=7967 highwater mark=391
Output from
the preceding
SQL:
WhatHas The LargestNumber OfWhatHas The LargestNumber OfConcurrentUsers een?ConcurrentUsers een?
-
8/8/2019 SQL Notools99
17/27
WhatHas The LargestNumber OfWhatHas The LargestNumber OfConcurrentUsers een?ConcurrentUsers een?
export LOGDIR=$ORACLE_HOME/udumpecho Enterthe password forthe SYSTEM user:
read PASSWD
for SID inPRODDB TESTDB TRAINDB DEVDB
do
sqlplus system/$PASSWD@$SID > $LOGDIR/temp_users.lstset linesize 100SELECT rpad(c.name||:,11)||chr(9)||chr(9)||
rpad( current logons=||(to_number(b.sessions_current)-1),20)||chr(10)||
cumulative logons=||rpad(substr(a.value,1,12),12)||chr(9)||
highwater mark=||b.sessions_highwater||chr(9)
FROM v\$sysstat a, v\$license b, v\$database cWHERE a.name = logons cumulative;
EOF
done
cat$LOGDIR/temp_users.lst |grep LOG > $LOGDIR/archive`date +%m%d`.log
rm $LOGDIR/temp_users.lst
Loop through
four
databases
-
8/8/2019 SQL Notools99
18/27
PRODDB: current logons=298 cumulative logons=7967 highwater mark=391PRODDB: current logons=298 cumulative logons=7967 highwater mark=391
TESTDB: current logons=15 cumulative logons=187 highwater mark=15TESTDB: current logons=15 cumulative logons=187 highwater mark=15
TRAINDB: current logons=8 cumulative logons=613 highwater mark=25TRAINDB: current logons=8 cumulative logons=613 highwater mark=25
DEVDB: current logons=23 cumulative logons=1024 highwater mark=30DEVDB: current logons=23 cumulative logons=1024 highwater mark=30
Output from the preceding SQL for
four databases:
WhatHas The LargestNumber OfWhatHas The LargestNumber OfConcurrentUsers een?ConcurrentUsers een?
-
8/8/2019 SQL Notools99
19/27
Which Locks Are eing Held?Which Locks Are eing Held?---- V LOCK V LOCKholds information on internal Oracle locks.holds information on internal Oracle locks.
---- Six viewsshow information more clearly:Six viewsshow information more clearly:
DBA_LOCK:DBA_LOCK: locksheld and locks requested;isblocking?locksheld and locks requested;isblocking?
DBA_LOCK_INTERNAL:DBA_LOCK_INTERNAL: locksheld and locks requestedlocksheld and locks requested
DBA_DML_LOCKS:DBA_DML_LOCKS: DML locks (subsetofDBA_LOCK)DML locks (subsetofDBA_LOCK)
DBA_DDL_LOCKS:DBA_DDL_LOCKS: DDL locks (subsetofDBA_LOCK)DDL locks (subsetofDBA_LOCK)DBA_WAITERS:DBA_WAITERS: whichsessions areholding and waitingwhichsessions areholding and waiting
for locks?for locks?
DBA_BLOCKERS:DBA_BLOCKERS: whichsessions areholding locksbutwhichsessions areholding locksbutare notwaiting on another lock themselves?are notwaiting on another lock themselves?
---- These are createdby theThese are createdby theORACLE_HOME/rdbms/admin/catblock.sqlORACLE_HOME/rdbms/admin/catblock.sql scriptscript
---- UseUse ORACLE_HOME/rdbms/admin/utllockt.sqlORACLE_HOME/rdbms/admin/utllockt.sql to analyzetheseto analyzethese
views.views.
-
8/8/2019 SQL Notools99
20/27
SELECT * FROM DBA_LOCK;SELECT * FROM DBA_LOCK;
SESSION_ID TYPE MODE_HELD MODE_REQUESTEDSESSION_ID TYPE MODE_HELD MODE_REQUESTED------------------------------ -------------------------------------- ------------------------------ ----------------------------------------------LOCK_ID1 LOCK_ID2 LAST_CON ERT BLOCKING_OTHERSLOCK_ID1 LOCK_ID2 LAST_CON ERT BLOCKING_OTHERS------------------------ ------------------------ ------------------------------------ ------------------------------------------------2 Media Recovery Share None2 Media Recovery Share None
212 0 113054 Not Blocking212 0 113054 Not Blocking
4 Redo Thread Exclusive None4 Redo Thread Exclusive None1 0 0 Not Blocking1 0 0 Not Blocking
310 Transaction Exclusive None310 Transaction Exclusive None196612 399886 123 Not Blocking196612 399886 123 Not Blocking
310 DML Row310 DML Row--X (SX) NoneX (SX) None438580 0 123 Not Blocking438580 0 123 Not Blocking
Which Locks AreBeing Held?Which Locks AreBeing Held?
-
8/8/2019 SQL Notools99
21/27
-
8/8/2019 SQL Notools99
22/27
SELECTSELECT lpad( ,3*levellpad( ,3*level--1)) || waiting_sessions1)) || waiting_sessions
WAITING SESSION,WAITING SESSION,
lock_type, mode_requested, mode_held,lock_type, mode_requested, mode_held,
lock_id1, lock_id2lock_id1, lock_id2
FROMFROM lock_holderslock_holdersCONNECT BY PRIORCONNECT BY PRIOR
waiting_session=holding_sessionwaiting_session=holding_session
START WITH holding_session IS NULL;START WITH holding_session IS NULL;WAITING_ LOCK_ MODE_ MODE_ LOCK_WAITING_ LOCK_ MODE_ MODE_ LOCK_
LOCK_LOCK_
SESSION TYPE REQUESTED HELD ID1 ID2SESSION TYPE REQUESTED HELD ID1 ID2
-------------------- -------------- -------------------------- -------------- ---------------- ------------133 None133 None
319 Transaction Exclusive Exclusive 196613 406415319 Transaction Exclusive Exclusive 196613 406415
Which Locks AreBeing Held?Which Locks AreBeing Held?
-
8/8/2019 SQL Notools99
23/27
NAMENAME
STATISTIC#STATISTIC#
CLASSCLASS
Which Users Have Hogged Up TheWhich Users Have Hogged Up TheMostCPU Usage?MostCPU Usage?
V$STATNAMEV$STATNAME
PROGRAMPROGRAM
TYPETYPE
SQL_ADDRESSSQL_ADDRESS
SQL_HASH_VALUESQL_HASH_VALUE
MODULEMODULE
MODULE_HASHMODULE_HASH
ACTIONACTION
ACTION_HASHACTION_HASH
CLIENT_INFOCLIENT_INFO
FIXED_TABLE_SEQUENCEFIXED_TABLE_SEQUENCE
ROW_WAIT_OBJ#ROW_WAIT_OBJ#
ROW_WAIT_FILE#ROW_WAIT_FILE#
ROW_WAIT_BLOCK#ROW_WAIT_BLOCK#
ROW_WAIT_ROW#ROW_WAIT_ROW#
LOGON_TIMELOGON_TIME
LAST_CALL_ETLAST_CALL_ET
PDML_ENABLEDPDML_ENABLED
FAILOVER_TYPEFAILOVER_TYPE
FAILOVER_METHODFAILOVER_METHODFAILED_OVERFAILED_OVER
V$SESSIONV$SESSION
SIDSID
STATISTIC#STATISTIC#
VALUEVALUE
V$SESSTATV$SESSTATSADDRSADDR
SIDSIDSERIAL#SERIAL#
AUDSIDAUDSID
PADDRPADDRUSER#USER#
USERNAMEUSERNAMECOMMANDCOMMAND
OWNERIDOWNERID
TADDRTADDR
LOCKWAITLOCKWAIT
STATUSSTATUS
SERVERSERVER
SCHEMA#SCHEMA#
SCHEMANAMESCHEMANAME
OSUSEROSUSER
PROCESSPROCESS
MACHINEMACHINETERMINALTERMINAL
like %CPU used by
this session%
-
8/8/2019 SQL Notools99
24/27
SELECTSELECT substr(sn.name,1,30) parameter,substr(sn.name,1,30) parameter,
ss.username || (|| se_sid ||) user_process, se.valuess.username || (|| se_sid ||) user_process, se.value
FROMFROM v$session ss, v$sesstat se, v$statname snv$session ss, v$sesstat se, v$statname sn
WHEREWHERE se. statistic# = sn.statistic#se. statistic# = sn.statistic# ANDAND
sn.namesn.name LIKELIKE %CPU used by this session%%CPU used by this session%ANDAND
se.sid=ss.sidse.sid=ss.sid
ORDER BYORDER BY sn.name, se_valuesn.name, se_value DESC;DESC;
PARAMETER USER_PROCESS VALUEPARAMETER USER_PROCESS VALUE---------------------------------------------------------------- ------------------------------------------------ ------------------------------
CPU used by this session OLAP_MAN (390) 15230CPU used by this session OLAP_MAN (390) 15230
CPU used by this session PIN (35) 4324CPU used by this session PIN (35) 4324
CPU used by this session OPERATOR (17) 157CPU used by this session OPERATOR (17) 157
CPU used by this session SYS (11) 0CPU used by this session SYS (11) 0
Which Users Have Hogged Up TheWhich Users Have Hogged Up TheMostCPU Usage?MostCPU Usage?
-
8/8/2019 SQL Notools99
25/27
SVRMGRL>SVRMGRL> ARCHIVE LOG LIST;ARCHIVE LOG LIST;
Database log modeDatabase log mode No Archive ModeNo Archive Mode
Automatic archivalAutomatic archival DisabledDisabledArchive DestinationArchive Destination ?/dbs/arch?/dbs/arch
Oldest online log sequenceOldest online log sequence 45254525
Current log sequenceCurrent log sequence 45284528
WhatIs The Archiving Status Of TheWhatIs The Archiving Status Of TheDatabase?Database?
Why is archiving important?What happens when the archive volume fills up?How do you find the archiving status?
How do you turn on archiving?
-
8/8/2019 SQL Notools99
26/27
SELECTSELECT NAME=|| a.name, LOG_MODE=|| a.log_mode,NAME=|| a.name, LOG_MODE=|| a.log_mode,
LOG_ARCHIVE_START=|| b.value,LOG_ARCHIVE_START=|| b.value,
LOG_ARCHIVE_DEST=|| c.value,LOG_ARCHIVE_DEST=|| c.value,
LOG_ARCHIVE_FORMAT=|| d.valueLOG_ARCHIVE_FORMAT=|| d.value
FROMFROM v$database a, v$parameter b, v$parameter c,v$database a, v$parameter b, v$parameter c,v$parameter dv$parameter d
WHEREWHERE b.name=log_archive_startb.name=log_archive_startANDAND
c.name=log_archive_destc.name=log_archive_destANDAND
d.name=log_archive_formatd.name=log_archive_format;;NAME=PINDBNAME=PINDB
LOG_MODE=NOARCHIVELOGLOG_MODE=NOARCHIVELOG
LOG_ARCHIVE_START=TRUELOG_ARCHIVE_START=TRUE
LOG_ARCHIVE_DEST=/u01/oracle/product/8.0.3/dbs/archLOG_ARCHIVE_DEST=/u01/oracle/product/8.0.3/dbs/arch
LOG_ARCHIVE_FOMAT=_%s_%t.logLOG_ARCHIVE_FOMAT=_%s_%t.log
WhatIs The Archiving Status Of TheWhatIs The Archiving Status Of TheDatabase?Database?
-
8/8/2019 SQL Notools99
27/27
Where to Now?Where to Now? There are many discussion Newsgroups on the internet for you to give questionsThere are many discussion Newsgroups on the internet for you to give questions
and get answers:and get answers:
comp.databases.oracle.servercomp.databases.oracle.server
comp.databases.oracle.toolscomp.databases.oracle.tools
comp.databases.oracle.misccomp.databases.oracle.misc
These can be accessed through a newsgroup program or These can be accessed through a newsgroup program or www.deja.comwww.deja.com
Aris free Oracle Tips web page at:Aris free Oracle Tips web page at:
There are over 370 tips and answers to questions that have been posed to me over theThere are over 370 tips and answers to questions that have been posed to me over theyears. This paper will be downloadable from the web page as well.years. This paper will be downloadable from the web page as well.
Other good sites with links:Other good sites with links: www.orafaq.org, www.orafans.com, www.ioug.org,www.orafaq.org, www.orafans.com, www.ioug.org,www.orasearch.com, www.revealnet.comwww.orasearch.com, www.revealnet.com