
Oracle Scripts
文章平均质量分 60
leishifei
这个作者很懒,什么都没留下…
展开
-
Using the power of DBMS_JOB.SUBMIT
From: http://www.orafaq.com/node/871Some DBAs complain that Oracle's pre-10g job queue interface is lacking. Unlike cron or Windows Sche转载 2011-08-10 09:46:45 · 454 阅读 · 0 评论 -
Redo Log File Switches – By hour of the day
Redo Log File Switches – By hour of the daypromptprompt "Morning .........."select to_char(first_time,'DD/MON') day,to_char(sum(decode(to_char(first_time,'HH24'),'07',1,0)),'000')"07",to_char(sum(decode(to_char(first_time,'HH24'),'08',1,0)),'000')"原创 2011-05-19 16:40:00 · 346 阅读 · 0 评论 -
Trigger to use with Data Guard to change service name
Trigger to use with Data Guard to change service name<br />CREATE OR REPLACE TRIGGER manage_OCIservice<br />after startup on database<br />DECLARE<br />role VARCHAR(30);<br />BEGIN<br />SELECT DATABASE_ROLE INTO role FROM V$DATABASE;<br />IF role = ‘PRIMAR原创 2011-05-19 16:39:00 · 405 阅读 · 0 评论 -
Script- Track redo generation by day
Script- Track redo generation by dayselect trunc(completion_time) rundate,count(*) logswitch,round((sum(blocks*block_size)/1024/1024)) "REDO PER DAY (MB)"from v$archived_loggroup by trunc(completion_time)order by 1;原创 2011-05-19 16:35:00 · 318 阅读 · 0 评论 -
Query the RMAN catalog to check backup status
Query the RMAN catalog to check backup status<br />This script will query the RMAN catalog and report on the backup status of every database in the catalog.<br /> set lines 80set pages 250ttitle "Daily Backup........"select DB NAME,dbid,NVL(TO_CHA原创 2011-05-19 16:34:00 · 496 阅读 · 0 评论 -
Determing the optimal UNDO tablespace size
Determing the optimal UNDO tablespace sizeSELECT d.undo_size/(1024*1024) “ACTUAL UNDO SIZE [MByte]“, SUBSTR(e.value,1,25) “UNDO RETENTION [Sec]“, (TO_NUMBER(e.value) * TO_NUMBER(f.value) * g.undo_block_per_sec) / (1024*1024)原创 2011-05-19 16:32:00 · 341 阅读 · 0 评论 -
Monitor space used in ASM Disk Groups
Monitor space used in ASM Disk GroupsSET LINESIZE 145SET PAGESIZE 9999SET VERIFY offCOLUMN group_name FORMAT a20 HEAD 'Disk Group|Name'COLUMN sector_size FORMAT 99,999 HEAD 'Sector|Size'COLUMN block_si原创 2011-05-19 16:31:00 · 298 阅读 · 0 评论 -
Identify 'hot' objects when faced with 'Cache Buffers Chains Latch' wait event
Identify 'hot' objects when faced with 'Cache Buffers Chains Latch' wait eventselect count(*) child_count, sum(gets) sum_gets, sum(misses) sum_misses, sum(sleeps) sum_sleepsfrom v$latch_childrenwhere name = 'cache buffers c原创 2011-05-19 16:30:00 · 347 阅读 · 0 评论 -
Monitor the Flashback area space usage
Monitor the Flashback area space usageSELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;SELECT * FROM V$RECOVERY_FILE_DEST;col ROUND(SPACE_LIMIT/1048576) heading "Space Allocated (MB)" format 999999col round(space_used/1048576) heading "Space Used (MB)原创 2011-05-19 16:29:00 · 421 阅读 · 0 评论 -
List all tablespaces with free space < 10%
List all tablespaces with free space原创 2011-05-19 16:26:00 · 225 阅读 · 0 评论 -
Check for dependant foreign keys before dropping Primary Key
Check for dependant foreign keys before dropping Primary Key<br />SELECT A.owner foreign_owner, a.table_name foreign_table, b.owner primary_owner, b.table_name primary_tablefrom dba_constraints a, dba_constraints bwhere a.r_constraint_name = b.constrai原创 2011-05-19 16:44:00 · 358 阅读 · 0 评论 -
Script – Check RMAN Backup Status
Script – Check RMAN Backup StatusScripts to check backup status and timings of database backups -This script will be run in the database, not the catalog.Login as sysdba -This script will report on all backups – full, incremental and archivelog backups -co原创 2011-05-19 15:26:00 · 328 阅读 · 0 评论 -
Check if block change tracking file is being used
Check if block change tracking file is being usedselect file#, avg(datafile_blocks), avg(blocks_read), avg(blocks_read/datafile_blocks) * 100as "% read for backup"from v$backup_datafilewhere incremental_level > 0 and used_change_tracking = 'YES'gro原创 2011-05-19 16:43:00 · 376 阅读 · 0 评论 -
Using DBMS_SCHEDULER to run a UNIX shell script
Using DBMS_SCHEDULER to run a UNIX shell script<br />CREATE A PROGRAM<br />begin<br />dbms_scheduler.create_program<br />(<br />program_name => ‘UPDATE_VERITAS’,<br />program_type => ‘EXECUTABLE’,<br />program_action => ‘/opt/oracle/scripts/blade08/update_原创 2011-05-19 16:38:00 · 390 阅读 · 0 评论 -
Recompiling Objects based on dependencies
Recompiling Objects based on dependencies<br />In order to prevent you from the task from running a recompile script several times so as compile all objects that are dependant on other objects, we need to take into account the dependency of objects – this原创 2011-05-19 16:36:00 · 295 阅读 · 0 评论 -
Identify database SID based on OS Process ID
Identify database SID based on OS Process IDcol sid format 999999col username format a20col osuser format a15select b.spid,a.sid, a.serial#,a.username, a.osuserfrom v$session a, v$process bwhere a.paddr= b.addrand b.spid='&spid'order by b.spi原创 2011-05-19 16:24:00 · 285 阅读 · 0 评论 -
Script - Monitor Data Guard Log Shipping
Monitor Data Guard Log ShippingNote: This query needs to be run on the Primary database.SET PAGESIZE 124COL DB_NAME FORMAT A8COL HOSTNAME FORMAT A12COL LOG_ARCHIVED FORMAT 999999COL LOG_APPLIED FORMAT 999999COL LOG_GAP FORMAT 9999COL APPLIE原创 2011-05-19 16:20:00 · 359 阅读 · 0 评论 -
Script – Query the RMAN catalog to list backup completion status
Script – Query the RMAN catalog to list backup completion status<br />Note – run this query connected as the owner of the RMAN catalogset lines 80set pages 250ttitle "Daily Backup........"select DB NAME,dbid,NVL(TO_CHAR(max(backuptype_db),'DD/M原创 2011-05-19 16:12:00 · 347 阅读 · 0 评论 -
Script – Latch Contention (top 5 latches)
Script – Latch Contention (top 5 latches)<br />This script will display the top 5 latches with the most sleeps.<br />Script can be changed to even sort the display on misses instead.set linesize 120col name format a30select * from (select name, get原创 2011-05-19 15:51:00 · 276 阅读 · 0 评论 -
Data Guard Switchover Unix shell script
Data Guard Switchover Unix shell script<br />The following Unix shell scripts can be used to automate the Data Guard Switchover process of a physical standby database.<br />It is very important that the scripts are run in the correct order and on right mac原创 2011-05-19 15:46:00 · 321 阅读 · 0 评论 -
Script – Tablespace free space and fragmentation
Script – Tablespace free space and fragmentation set linesize 150 column tablespace_name format a20 heading 'Tablespace' column sumb format 999,999,999 column extents format 9999 column bytes format 999,999,999,999 column原创 2011-05-19 15:43:00 · 319 阅读 · 0 评论 -
Identify active transactions in undo and rollback segments
Identify active transactions in undo and rollback segmentscol o format a10col u format a10select osuser o, username u, sid,segment_name s, substr(sa.sql_text,1,200) txtfrom v$session s,v$transaction t,dba_rollback_segs r,v$sqlarea sawhere s原创 2011-05-19 16:21:00 · 304 阅读 · 0 评论 -
Monitor long running operations using v$session_longops
Monitor long running operations using v$session_longopsSELECT SID, SERIAL#, opname, SOFAR, TOTALWORK,ROUND(SOFAR/TOTALWORK*100,2) COMPLETEFROM V$SESSION_LONGOPSWHERETOTALWORK != 0AND SOFAR != TOTALWORKorder by 1;Note: the same query ca原创 2011-05-19 16:19:00 · 333 阅读 · 0 评论 -
Script – List all recent DDL modifications
Script – List all recent DDL modificationsset pagesize 200 colsep ' 'col Owner format a20col Object_Name format a30col Last_DDL format a20break on Ownerselect Owner, Object_typeObject_Name,Timestamp Last_DDLfrom DBA_OBJECTSwhere SysDate原创 2011-05-19 16:13:00 · 327 阅读 · 0 评论 -
Script – Temporary tablespace usage
Script – Temporary tablespace usage<br />– Listing of temp segments.–<br />SELECT A.tablespace_name tablespace, D.mb_total,<br />SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,<br />D.mb_total – SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb原创 2011-05-19 16:17:00 · 342 阅读 · 0 评论 -
Script – List Objects being accessed by a particular SID
Script – List Objects being accessed by a particular SIDset pagesize 300select sid,serial#,username,status from v$sessionWHERE USERNAME IS NOT NULLorder by STATUS DESC;col sid format 999col owner format a10col object format a20col type format原创 2011-05-19 16:16:00 · 248 阅读 · 0 评论 -
Script – Monitor sessions with high Physical Reads
Script – Monitor sessions with high Physical Readsset linesize 120col osuser format a10col username format 10selectOSUSER osuser,username,PROCESS pid,ses.SID sid,SERIAL#,PHYSICAL_READS,BLOCK_CHANGESfrom v$session ses,v$sess_io sio原创 2011-05-19 16:10:00 · 259 阅读 · 0 评论 -
Script – List SQL being executed by a particular SID
Script – List SQL being executed by a particular SIDcol sql_text format a100 heading "Current SQL"select q.sql_textfrom v$session s, v$sql qWHERE s.sql_address = q.addressand s.sql_hash_value + DECODE(SIGN(s.sql_hash_value), -1, POWER( 2, 32),原创 2011-05-19 16:08:00 · 308 阅读 · 0 评论 -
Script – Find SQL being executed by a OS Process ID (PID)
Script – Find SQL being executed by a OS Process ID (PID)prompt "Please Enter The UNIX Process ID"set pagesize 50000set linesize 30000set long 500000set head offselects.username su,substr(sa.sql_text,1,540) txtfrom v$process p,v$session s原创 2011-05-19 16:07:00 · 248 阅读 · 0 评论 -
Script – Segments with highest I/O activity
Script – Segments with highest I/O activityThis script will list the top 10 segments in the database that have the most number ofphysical reads against them.Script can also be changed to query on 'physical writes' instead.set pagesize 200setlines原创 2011-05-19 15:57:00 · 289 阅读 · 0 评论 -
Script – Top SQL (Buffer Gets)
Script – Top SQL (Buffer Gets)<br />This script will list the top 5 SQL statements sorted by the most number of buffer gets or logical readsset serverout on size 1000000declaretop5 number;text1 varchar2(4000);x number;len1 number;Cursor c1 is原创 2011-05-19 15:54:00 · 464 阅读 · 0 评论 -
Script – Sessions with high physical reads
Script – Sessions with high physical reads<br />set linesize 120<br />col os_user format a10<br />col username format a15<br />col pid format 9999999999<br />PROMPT sessions sorted BY physical reads<br />PROMPT<br />SELECT osuser os_user,<br /> user原创 2011-05-19 15:31:00 · 279 阅读 · 0 评论 -
Sample logfile generated by dbupdiag.sql
<br /> *** Start of LogFile ***<br /> Oracle Database Upgrade Diagnostic Utility 07-01-2008 12:17:30<br />===============<br />Database Uptime<br />===============<br />15:16 30-JUN-08<br />=================<br />Database Wo原创 2011-05-19 15:14:00 · 425 阅读 · 0 评论 -
Locked Sessions and Locked Objects
Locked Sessions and Locked ObjectsPROMPT Blocked and Blocker Sessionscol blocker_sid format 99999999999col blocked_sid format 99999999999col min_blocked format 99999999999col request format 9999999select /*+ ORDERED */blocker.sid blocker_sid原创 2011-05-19 16:22:00 · 291 阅读 · 0 评论 -
Identify database idle sessions
Identify database idle sessionsset linesize 140col username format a15col idle format a15col program format a30PROMPT Enter the number of minutes for which the sessions should have been idle:PROMPTselectsid,username,status,to_char(logon原创 2011-05-19 16:23:00 · 307 阅读 · 0 评论 -
Script – Datafiles with highest I/O activity
Script – Datafiles with highest I/O activitycol name format a40set linesize 140select * from (select name,phyrds, phywrts,readtim,writetimfrom v$filestat a, v$datafile bwhere a.file#=b.file#order by readtim desc) where rownum <6;原创 2011-05-19 16:05:00 · 285 阅读 · 0 评论 -
Script – Sessions Waiting On A Particular Wait Event
Script – Sessions Waiting On A Particular Wait EventSELECT count(*), eventFROM v$session_waitWHERE wait_time = 0AND event NOT IN ('smon timer','pipe get','wakeup time manager','pmon timer','rdbms ipc message', 'SQL*Net message from client')GROUP原创 2011-05-19 16:03:00 · 257 阅读 · 0 评论 -
Script – What Wait Events Are Sessions Waiting On
Script – What Wait Events Are Sessions Waiting Onset linesize 120col username format a10col event format a30 select sid, serial#,username, event,seconds_in_wait, wait_timefrom v$session where state = 'WAITING'and wait_class != 'Idle'order b原创 2011-05-19 16:02:00 · 237 阅读 · 0 评论 -
Script – List status of all submitted DBMS jobs
Script – List status of all submitted DBMS jobsset pagesize 100set linesize 120ttitle - center 'Submitted DBMS Jobs' skip 2col job format 99999 heading 'job#'col subu format a10 heading 'Submitter' trunccol lsd format a5 heading '原创 2011-05-19 15:59:00 · 317 阅读 · 0 评论 -
Script – Top SQL (Physical Reads)
Script – Top SQL (Physical Reads)<br />This script will list the top 5 SQL statements sorted by the most number of physical readsset serverout on size 1000000<br />set feedback off<br />declare<br />top5 number;<br />text1 varchar2(4000);<br />x原创 2011-05-19 15:53:00 · 322 阅读 · 0 评论