Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
12 views
15 SQL Script For Monitoring
SQL Script for Monitoring
Uploaded by
Saj Plus
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 15 SQL Script for Monitoring For Later
Download
Save
Save 15 SQL Script for Monitoring For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
12 views
15 SQL Script For Monitoring
SQL Script for Monitoring
Uploaded by
Saj Plus
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 15 SQL Script for Monitoring For Later
Carousel Previous
Carousel Next
Save
Save 15 SQL Script for Monitoring For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 6
Search
Fullscreen
15 DB Monitoring SQL Scripts for DBAs Asfaw Gedamu1. List of active sessions in the database set echo off set linesize 95 set head on set feedback on col sid head "Sid" form 9999 trunc col serial# form 99999 trunc head "Ser" col username form ab teune col osuser form a7 trunc col machine form 20 trunc head "Client |Machine" col program form 215 trunc head "Client |Program” col login form all col “last cali" form 9999999 trunc head "Last Call|In Secs" col status form aé trunc select sid,serial#, substr (username, 1,10) username, substr(osuser, 1,10) osuser, substr(program| |module, 1,15) program, substr (machine, 1,22) machine, to_char(Logon_time, 'ddéon hh24:mi') Login, last_call_et “last call", status from gv$session where status="ACTIVE" order by 1 / 2. Current tablespace usage: set feedback off sel pagesize 70; set Linesize 2000 set head on COLUMN Tablespace format a25 heading ‘Tablespace Name* COLUMN autoextensible format all heading ‘AutoExtend’ COLUMN files in tablespace format 999 heading 'Files' COLUMN total_tablespace_space format 99999999 heading 'Totalspace* COLUMN total_used_space format 99999999 heading 'UsedSpace’ COLUMN total_tablespace_free_space format 99999999 heading 'FreeSpace" COLUMN total used pet format 9999 heading 'tUsed* COLUMN total free pet format 9999 heading ‘tree! COLUMN max size of tablespace format 99999999 heading 'ExtendUpte! COLUM total auto used pet format 999.99 heading 'MaxSUsed' COLUMN total_aute_fres_pct format 999.99 heading 'MaxtFree! WITH ths_auto AS (SELECT DISTINCT tablespace _name, autoextensible FROM dba data files WHERE autoextansible files AS (SELECT tablespace_name, COUNT (*) tbs_files, SUM (BYTES/1024/1024) total_ths_bytes FROM dba_data_ files GROUP BY tableapa: fragments AS (SELECT tablespace_name, COUNT (*) ths_fragments, SUM (BYTES) /1024/1024 total_tbs_free_ bytes, MAX (BYTES) /1024/1024 max_free_shunk_bytes| FROM dba_free_space "YES"), name),GROUP BY tablespace_name), AUTOEXTEND AS (SELECT tablespace_name, SUM (size _to_grow) total_growth tbs FROM (SELECT tablespace name, SUM (maxbytes)/1024/1024 size to_grow ROW dba data files WHERE autoextensible = 'YES* GROUP BY tablespace_nane oNzoN SELECT tablespace name, SUM (BYTES) /1024/1024 size _to_grow FROM dba data files WHERE autoextensible = ‘No’ GROUP BY tablespace name) GROUP BY tablespace_name) SELECT c, instance_name, 2.tablespace_name Tablespace, CASE ths _auto.autoextensible WHEN "YES THEN 'YES* ELSE ‘NO! END AS autoextensible, files.ths files files_in_tablespace, files.total_ths_bytes total_tablespace_space, (files.total_ths bytes - fragments.total_ths free bytes ) total used space, fragments.total tbs free bytes total tablespace free space, round({ { (files.total_tbs bytes - fragments.total_tbs_free bytes) / files.total_ths_bytes ) * 100 )) total _used pet, round(((Fragments.total_tbs free bytes / files.total_tbs bytes) * 100 )) total_free_pet FROW dba_tabléspaces a,vSinstance c , files, fragments, AUTOEXTEND, ths_auto WHERE a.tablespace_name ~ files. tablespace name AND a.tablespace_name = fragments. tablespace_name AND a.lablespace name = AUTOZXTEND. tablespace name AND a.tablespace_name = tbs_auto.tablespace_name(+) order by total_free_pet; 3. Find the blocking session detail SELECT sinst_id, -blocking_session, tsid, iseriall, s.seconds_in_wait FROW gv$session 5 WHERE blocking session IS NOT NULL;4. Monitor TEMP tablespace usage: select a.tablespace name tablespace, 4. TEMP_TOTAZ_MB, sum (2;used blocks * d.block size) / 1024 / 1024 TEMP_USED_MB, G.TEMP TOTAL MB - sum (2.used blocks * d.block size) 7 1024 / 1024 TEMP_PREE MB from v$sort_segment a, ‘ select b.name, c.block_size, sum (c.bytes) / 1024 / 1024 TSMP_TOTAL_MB from vStablespace b, vStempfile c where b.tsit= c.tat group by b.name, c.block_size da where a.tablespace_name = d.name group by a.tablespace name, d.TEMP_TOTAL MB; 5. d the long running queries: select sid, inst_id, opname, totalwork, sofar, start_time, time_remaining from gy$session_longops where totalwork@>sofar / 6. Get os spid from sid: set lines 123 col USERNAME for al5 col OSUSER for ab col MACHINE for alS col PROGRAM for a20 select b.spid, a,username, a.program , a.osuser ,a.machine, a.sid, a.serial#, a.status from gv§session 2, gvSprocess b wheze addr=paddr(+) and sid-ssid; 7. Get sid from os spid: col sid format 999999 col username format a20 col osuser format al select b.spid,a.sid, a.serial#,a.username, a.osuser from v§session a, vSprocess b where a.paddr= badder and b.spid="sspia" order by b.spid; 8. Monitor undo tablespace usage: select a.tablespace_name, SIZEMB, USAGEMS, (SIZEMB - USAGEMB) FREEMEfrom (select sum(bytes} / 1024 / 1024 SIZEMB, b.tablespace_name from dba_data_files a, dba_tablespaces b where a.tablespace name = b.tablespace_name and b.contents = 'ONDO" group by b.tablespace name) a, (select c.tablespace name, sum(bytes) / 1024 / 1024 USAGEMB from DBA_UNDO_EXTENTS © where status <> 'EXPIRED’ group by ¢.tablespace_name) b where a.tablespace_name = b.tablespace_name; 9, Get sql_text of an SID: col sql_text form a80 set lines 120 select sql_text from gvSsqltext where hash_value: (select sql_hash_value from qvSsession where sid order by piace / 1 and inst_id=sinst_id) 10. Locks present in the database col session_id head ‘Sid’ form 9999 col object fame head "Table|Locked" form col oracle_username head "Oracle|Username" form al0 truncate col os user name head "OS|Username" form al0 truncate col process head "Client|Process|1D" form 99999999 col mods held form al5 select 16.session_id, lo.oracle username, lo.os_user_name, 1o.process, do.object_name, decode (10. locked mode,0, 'None',1, 'Null',2, ‘Row Share (SS)', 3, "Row Excl (SX)",4, 'Share',5, "Share Row Excl (SSX)',6, ‘Exclusive’, to char(1e.lecked mode)} mode’ held from v$locked object lo, dba objects de where lo.objest_id = do.cbject_id order by 1,5 / 11. Find the sessi ns generating lot of redo: set lines 2000 set pages 1000 col sid for 99999 col name for 3209 col username for al4 col PROGRAM for aZ1 col MODULE for a25 select s.sid,sn.SERIAL#,n.name, round(value/1024/1024,2) redo_mb, sn.username,sn.status, substr (sn.program,1,21) “program”, sn.type, sn.module,sn.sql_id from v§sesstat s join vSstatname n on a.statistict = s.statistic#join v§session sn on sn.sid = s.sid where n.name like 'redo size! and S.value!-0 order by redo_mb desc; 12, Find the session generating undo data: select a.sid, a.serial#, s.username, b.used_urec used_undo_record, b,used_ublk Lsed_undo_blocks from v§session a, v$transaction b where a.saddr-b.ses_addr ; 13. Find temp usage of the sessions: SELECT b. tablespace, ROUND { (b.blocks*p. value) /1024/1024), 2) ||"M" AS temp_size, a-inst_id as Instance, a.sid||','||a.serial# AS sid serial, NVL(a-username, '(eracle)') AS username, a.program, a.status, a.sql_id FROM GvSsession a, gvésert_usage b, gvSparameter p WHERE p.name = ‘db_block_size" AND a.saddr = b.seasion addr AND a.inst_ideb.inst_id AND a.inst_idep.inst id ‘ORDER BY Lemp size desc / 14, Monitor rollback transactions: select state, UNDOBLOCKSDONE, UNDOBLOCKSTOTAL, UNDOBLOCKSDONE/UNDOBLOCKSTOTAL*100 from gv$fast_start_transactions; 15. Top queries with h elapsed_time: — Queries in last 1 hour ( Run from Toad, for proper view) Select module, parsing_schema_name, inst_id, sql_id, CHILD_NUMBER, sql_plan_baseline, sql__ profile,plan_hash_value,sql_fulltext, to_char{last_active time, 'DD/MM/YY HH24:MI:SS" ), executions, elapsed_tine/executions/1000/1000, rows_pracessed, sql_plan_baseline from gvSsql where last_active_time>sysdate- 1/2 and executions <> 0 order by elapsed_time/executions desc
You might also like
All Scripts
PDF
100% (1)
All Scripts
88 pages
All Commands - DBA
PDF
100% (1)
All Commands - DBA
42 pages
How To Check UNDO Tablespace Usage
PDF
No ratings yet
How To Check UNDO Tablespace Usage
8 pages
DB Monitoring & Performance Script
PDF
No ratings yet
DB Monitoring & Performance Script
14 pages
Check List (DBA Checklist (Activities of Oracle DBA) )
PDF
No ratings yet
Check List (DBA Checklist (Activities of Oracle DBA) )
17 pages
ORACLE DBA Activity Checklist
PDF
71% (17)
ORACLE DBA Activity Checklist
23 pages
15 DB Monitoring SQL Scripts For Dbas: (Document Subtitle)
PDF
No ratings yet
15 DB Monitoring SQL Scripts For Dbas: (Document Subtitle)
6 pages
Efficient Database Monitoring Query Scripts - 240318 - 142050-1
PDF
No ratings yet
Efficient Database Monitoring Query Scripts - 240318 - 142050-1
45 pages
Monitoring Scripts12
PDF
No ratings yet
Monitoring Scripts12
47 pages
Top 20 DB Monitoring SQL Scripts For DBAs-2
PDF
No ratings yet
Top 20 DB Monitoring SQL Scripts For DBAs-2
11 pages
Important Oracle Query & Script
PDF
90% (10)
Important Oracle Query & Script
57 pages
Usefull SQL For Tablespace Alerts: Normal Tablespaces
PDF
No ratings yet
Usefull SQL For Tablespace Alerts: Normal Tablespaces
10 pages
Oracle SQL Commands
PDF
No ratings yet
Oracle SQL Commands
8 pages
Health Check SQL
PDF
No ratings yet
Health Check SQL
5 pages
Queries
PDF
No ratings yet
Queries
31 pages
Daily Tasks: Ps - Ef - Grep rwmts60 You Should Get Output Like Applmgr ....... rwmts60 Name REP60 - VISION
PDF
No ratings yet
Daily Tasks: Ps - Ef - Grep rwmts60 You Should Get Output Like Applmgr ....... rwmts60 Name REP60 - VISION
8 pages
DBA Scripts
PDF
100% (2)
DBA Scripts
25 pages
Tuning_BST
PDF
No ratings yet
Tuning_BST
15 pages
knowledge_base_TEMP
PDF
No ratings yet
knowledge_base_TEMP
2 pages
Oracle - Database - Health - Check PDF
PDF
No ratings yet
Oracle - Database - Health - Check PDF
14 pages
Security Grants
PDF
No ratings yet
Security Grants
3 pages
Quries
PDF
No ratings yet
Quries
13 pages
Tuning
PDF
No ratings yet
Tuning
12 pages
Sqls
PDF
No ratings yet
Sqls
5 pages
Database Health Monitoring
PDF
No ratings yet
Database Health Monitoring
3 pages
How To Perform DBHealth Checkwith SQLScripts
PDF
No ratings yet
How To Perform DBHealth Checkwith SQLScripts
37 pages
Purging Oracle SYSAUX Table
PDF
No ratings yet
Purging Oracle SYSAUX Table
12 pages
DB_Query_Indo
PDF
No ratings yet
DB_Query_Indo
23 pages
Dba Role
PDF
No ratings yet
Dba Role
76 pages
Performance Check DBA
PDF
No ratings yet
Performance Check DBA
3 pages
Workshop DBA Operation 2023
PDF
No ratings yet
Workshop DBA Operation 2023
15 pages
How To Remove Duplicate Rows Without Using DISTINCT or ROWID or GROUP by Methods in Oracle
PDF
0% (1)
How To Remove Duplicate Rows Without Using DISTINCT or ROWID or GROUP by Methods in Oracle
36 pages
Mastering_Database_Health_Check_1742363375876
PDF
No ratings yet
Mastering_Database_Health_Check_1742363375876
37 pages
Db2 Tuning
PDF
No ratings yet
Db2 Tuning
4 pages
Oracle PT Queries
PDF
No ratings yet
Oracle PT Queries
19 pages
Oracle Performance Checks
PDF
No ratings yet
Oracle Performance Checks
6 pages
Oracle Checklist
PDF
No ratings yet
Oracle Checklist
20 pages
ORACLE DBA Activity Checklist
PDF
No ratings yet
ORACLE DBA Activity Checklist
12 pages
Oracle Queries For Checkpoint
PDF
No ratings yet
Oracle Queries For Checkpoint
13 pages
What Database Administrators Query Before Anything Else
PDF
No ratings yet
What Database Administrators Query Before Anything Else
6 pages
Table Space
PDF
No ratings yet
Table Space
17 pages
Dba Scripts All in One
PDF
100% (2)
Dba Scripts All in One
71 pages
Tuning Area View Description
PDF
No ratings yet
Tuning Area View Description
6 pages
My Daily For Oracle Apps DBA
PDF
100% (1)
My Daily For Oracle Apps DBA
17 pages
SYSAUX and purging big objects
PDF
No ratings yet
SYSAUX and purging big objects
13 pages
Daily Activity
PDF
No ratings yet
Daily Activity
15 pages
Space MGMT
PDF
No ratings yet
Space MGMT
15 pages
Create - Grant User - Blocking Session
PDF
No ratings yet
Create - Grant User - Blocking Session
5 pages