Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword or section
Like this
P. 1
Important Oracle Query & Script

Important Oracle Query & Script

|Views: 55|Likes:
Published by Biswajit Das
SQL queries you should know during monitoring of oracle databases
SQL queries you should know during monitoring of oracle databases

More info:

Published by: Biswajit Das on Jul 31, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





STATUSStartup time
selectto_char(startup_time, 'HH24:MI DD-MON-YY') "Startup time"fromv$instance/
How large is the database
col "Database Size" format a20col "Free space" format a20col "Used space" format a20selectround(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size",round(sum(used.bytes) / 1024 / 1024 / 1024 ) -round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space",round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"from (selectbytes from v$datafileunionallselectbytes from v$tempfileunion allselectbytes from v$log) used,(select sum(bytes) as p from dba_free_space) freegroup by free.p/
Distribution of objects and data
Which schemas are taking up all of the space
set pages 999col "size MB" format 999,999,999col "Objects" format 999,999,999selectobj.owner "Owner",obj_cnt "Objects",decode(seg_size, NULL, 0, seg_size) "size MB"from (select owner, count(*) obj_cntfrom dba_objects group by owner) obj,(select owner, ceil(sum(bytes)/1024/1024) seg_sizefrom dba_segments group by owner) segwhere obj.owner = seg.owner(+)orderby 3 desc ,2 desc, 1/
Show the ten largest objects in the database
Col owner format a15Col segment_name format a30Col segment_type format a15Col mb format 999,999,999select owner,segment_name,segment_type,mbfrom(select owner,segment_name,segment_type,bytes / 1024 / 1024 "MB"from dba_segmentsorder by bytes desc)whererownum < 11/
Is java installed in the database?
This will return 9000'ish if it is...
select count(*)from all_objectswhere object_type like '%JAVA%'and owner = 'SYS'/
Display character set information
select * from nls_database_parameters/
Show all used features
selectname,detected_usagesfromdba_feature_usage_statisticswhere detected_usages > 0/
Show all connected users
set lines 100 pages 999col ID format a15select username,sid || ',' || serial# "ID",status,last_call_et "Last Activity"from v$sessionwhere username is not nullorder by status desc,last_call_et desc
Time since last user activity
set lines 100 pages 999select username, floor(last_call_et / 60) "Minutes", statusfrom v$sessionwhere username is not nullorder by last_call_et
Sessions sorted by logon time
set lines 100 pages 999col IDformat a15col osuserformat a15col login_timeformat a14select username,osuser,sid || ',' || serial# "ID",status,to_char(logon_time, 'hh24:mi dd/mm/yy') login_time,last_call_etfromv$sessionwhereusername is not nullorderby login_time
Show user info including os pid
col "SID/SERIAL" format a10col username format a15col osuser format a15col program format a40selects.sid || ',' || s.serial# "SID/SERIAL",s.username,s.osuser,p.spid "OS PID",s.program

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->