isitdevops.com/databases

Useful computing notes
  • Archive
  • Home
  • Posts

Categories

  • Chef (Cat) (2)
  • Chef Cookbook Tutorials (8)
  • CHEF Full Tutorial (18)
  • Jernkins (Cat) (1)
  • Oracle (354)
    • Oracle 11g (Sect) (309)
      • Oracle 11.2 Notes (Cat) (18)
      • Oracle ASM (Cat) (1)
      • Oracle Data Guard Notes (Cat) (45)
      • Oracle DB and SQL performance analysis (Cat) (67)
      • Oracle DB Objects (tables, sql etc) (Cat) (56)
      • Oracle Exadata (Cat) (21)
      • Oracle Flashback Notes (Cat) (12)
      • Oracle Golden Gate (Cat) (11)
      • Oracle odds and ends (Cat) (39)
      • Oracle oui and dbca (Cat) (4)
      • Oracle RAC (Cat) (24)
      • Oracle Rman Notes (Cat) (10)
      • Oracle sql one liners (Cat) (1)
    • Oracle 12c (Sect) (45)
      • 12c Cloud control (Cat) (4)
      • 12c Cloud Control Agent (Cat) (2)
      • 12c General (Cat) (19)
      • 12c Performance (Cat) (4)
      • 12c rman (cat) (16)
  • SQL Server (Sect) (31)
    • MS SQL Server (Cat) (31)
  • Uncategorized (7)
  • Unix Notes (Sect) (50)
    • Configuration (Cat) (16)
    • Resource Management (Cat) (18)
    • Unix notes (Cat) (16)

Categories

  • Chef (Cat)
  • Chef Cookbook Tutorials
  • CHEF Full Tutorial
  • Jernkins (Cat)
  • Oracle
    • Oracle 11g (Sect)
      • Oracle 11.2 Notes (Cat)
      • Oracle ASM (Cat)
      • Oracle Data Guard Notes (Cat)
      • Oracle DB and SQL performance analysis (Cat)
      • Oracle DB Objects (tables, sql etc) (Cat)
      • Oracle Exadata (Cat)
      • Oracle Flashback Notes (Cat)
      • Oracle Golden Gate (Cat)
      • Oracle odds and ends (Cat)
      • Oracle oui and dbca (Cat)
      • Oracle RAC (Cat)
      • Oracle Rman Notes (Cat)
      • Oracle sql one liners (Cat)
    • Oracle 12c (Sect)
      • 12c Cloud control (Cat)
      • 12c Cloud Control Agent (Cat)
      • 12c General (Cat)
      • 12c Performance (Cat)
      • 12c rman (cat)
  • SQL Server (Sect)
    • MS SQL Server (Cat)
  • Uncategorized
  • Unix Notes (Sect)
    • Configuration (Cat)
    • Resource Management (Cat)
    • Unix notes (Cat)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

list waiting and blocking users.sql

on June 23, 2008 at 12:40 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— waiters.sql
— from chap 8 of bee book
—
SELECT substr(s1.username,1,12)    “WAITING User”,
       substr(s1.osuser,1,8)            “OS User”,
       substr(to_char(w.session_id),1,5)    “Sid”,
       P1.spid                              “PID”,
       substr(s2.username,1,12)    “HOLDING User”,
       substr(s2.osuser,1,8)            “OS User”,
       substr(to_char(h.session_id),1,5)    “Sid”,
       P2.spid                              “PID”
FROM   sys.v_$process P1,   sys.v_$process P2,
       sys.v_$session S1,   sys.v_$session S2,
       dba_locks w,     dba_locks h
WHERE  h.mode_held        = ‘None’
AND    h.mode_held        = ‘Null’
AND    w.mode_requested  != ‘None’
AND    w.lock_type (+)    = h.lock_type
AND    w.lock_id1  (+)    = h.lock_id1
AND    w.lock_id2  (+)    = h.lock_id2
AND    w.session_id       = S1.sid  (+)
AND    h.session_id       = S2.sid  (+)
AND    S1.paddr           = P1.addr (+)
AND    S2.paddr           = P2.addr (+)
/
— EOF

 Comment 

list views with name like.sql

on June 23, 2008 at 12:39 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

set pause on
set pages 24
set pause ‘Any Key>’
spool vw_lst.lst
select view_name, owner from all_views where view_name like UPPER(nvl(‘&VIEW_NAME’,’WHOOPS’)||’%’)
/
spool off

 Comment 

list users on this instance.sql

on June 23, 2008 at 12:39 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

REM SQL to display current user connections in the database
REM NOTE: only shows activity on whichever node of the OPS
REM       is referred to by the user-s TWO_TASK environment variable
REM       (usually cas1)

set linesize 100;
set pagesize 200;

column os_user format A10 trunc;
column db_user format A20 trunc;
column machine format A10 trunc;
column program format A30 trunc;
column login_time format A20;

select osuser os_user, username||decode(status,’ACTIVE’,’**active**’,’INACTIVE’,’-‘) db_user, machine,
  decode (  substr(program,1,instr(program,’@’)-1), ‘oracle’,  ‘(parallel query)’, substr(program,1,instr(program,’@’)-1)  ) program,
to_char(logon_time, ‘dd-MON-yyyy hh24:mi:ss’) login_time
from
v$session
where
sid in (select min(sid) from v$session where username is not null group by process)
order by osuser, username, program;

 

 Comment 

list users and default tablespace.sql

on June 23, 2008 at 12:39 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— usr_lst.sql
— mdw 8/8/97
—
— simple list of users and their defaults
—
set pause on pause ‘Any Key…>’
set pages 24
col username form A12 word wrap
spool usr_lst.lst
select username, user_id, substr(default_tablespace,1,15) dflt_tabspace, substr(temporary_tablespace,1,15) temp_tabspace, created
from sys.dba_users
where username like upper(‘&usr_nm’||’%’)
order by 1,2
/
spool off

 Comment 

list tablespaces.sql

on June 23, 2008 at 12:38 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— ts_lst.sql
— mdw 23/6/97
— simple list of tablespaces
set pause on
set pages 24
set pause ‘Any Key>’
col ini_ext_k form 9,999,999
col next_ext_k form 9,999,999
col min_ex form 999
col min_extln form 999,999
spool ts_lst.lst
select substr(tablespace_name,1,17)       ts_name
      ,initial_extent/1024                ini_ext_K
      ,next_extent/1024                   next_ext_K
      ,min_extents                        min_ex
      ,max_extents                        max_ex
      ,substr(to_char(pct_increase),1,3)  pct
      ,min_extlen/1024                    min_extln
      ,decode(status,’ONLINE’     ,’ON’,  ‘READ ONLY’, ‘R-O’, substr(status,1,3) )        st
from sys.dba_tablespaces
where tablespace_name like upper(‘&ts_name’||’%’)
order by 1
/
spool off
clear colu
—
— End of File
—

 Comment 

list tablespaces and free space.sql

on June 23, 2008 at 12:38 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— free spc.sql
— mdw – check free space for (possibly) stated tablespace
—
set veri off
set pause on
set pause ‘Any Key…>’
set pages 24
spool free_spc.lst
break on t_name skip 1
select tablespace_name t_name
      ,blocks          blocks
      ,bytes           bytes
      ,to_char(bytes/1024,’9,999,999′) k_free
from sys.dba_free_space
where tablespace_name like upper(‘&tab_space’||’%’)
and    blocks > nvl(to_number(‘&blk_lim’),0)
order by tablespace_name,blocks desc
/
spool off

 Comment 

list tables and when they were last analyzed.sql

on June 23, 2008 at 12:38 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

select substr(owner,1,12) tab_owner,substr(table_name,1,40) tab_name
,last_analyzed
,num_rows
from dba_tables
where owner not like ‘SYS%’
and last_analyzed > sysdate-10
union
select substr(table_owner,1,12) tab_owner,substr(table_name||’ ‘||partition_name,1,40) tab_name
,last_analyzed
,num_rows
from dba_tab_partitions
where table_owner not like ‘SYS%’
and last_analyzed > sysdate-10
/

 Comment 

list tables and their partitions.sql

on June 23, 2008 at 12:37 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— par_dets.sql
— mdw 13/7/01
— details of partition table partitions s
col table_owner form a8 head ownr
col table_name  form a15 word wrap
col tablespace_name  form a10 word wrap head ts_name
col partition_name  form a13 word wrap head part_name
col blocks form 9999,999
col empty_blocks form 99,999 head e_blks
col high_value form a11 wrap
break on table_owner nodup on table_name nodup
spool par_dets.lst
select table_owner
,table_name
,partition_name
,tablespace_name
,blocks
,empty_blocks
,high_value
from dba_tab_partitions dtp
where table_name like upper(nvl(‘&ptab_name’,’eric’))||’%’
and   partition_name like upper(‘&part_name’)||’%’
order by table_name,table_owner,partition_position
/
clear col
clear break
spool off

 Comment 

list synonyms.sql

on June 23, 2008 at 12:37 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— syn_lst.sql
— mdw – simple synonym listing
set pause on
set pages 24
set pause ‘Any Key>’
col owner         form a10 wrap
col synonym_name  form a20 word wrap
col table_owner   form a10 wrap
col table_name    form a20 word wrap
col db_link       form a14 word wrap
spool syn_lst.lst
select owner
,synonym_name
,table_owner
,table_name
,db_link
from dba_synonyms
where synonym_name like upper(nvl(‘&syn_name’,’WHOOPS’)||’%’)
/
spool off
clear columns
— EOF

 Comment 

list segmet usage by type and name.sql

on June 23, 2008 at 12:36 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— par_size.sql
— mdw 10/03/97
— show current allocated space for (by default tables) specifed objects
— mdw 24/04/01
— adding in the checking of user to look at – sanger uses multiple schemas
—
clear break
break on o_type nodup on owner nodup on obj_name nodup skip 1 on tablespace nodup
set veri off
set pause on
set pages 24
set lines 80
col o_type form a8 truncate
col owner form a8 word wrap
col obj_name form a22 word wrap
col tablespace form a14 word wrap
— mdw temp change to spool file
spool par_siz.lst
select segment_type                                 o_type
,owner                                        owner
,segment_name||’ ‘||partition_name            obj_name
,tablespace_name                              tablespace
,substr(extent_id,1,3)                        num
,substr(to_char(bytes/1024,’99,999,999′),1,11) K_bytes                 
,substr(to_char(blocks,’999,999′),1,8)        blocks
from sys.dba_extents
where segment_name like upper(nvl(‘&nme’,’WHOOPS’)||’%’)
and   segment_type like upper(nvl(‘&typ’,’TABLE’)||’%’)
and   partition_name like upper(‘&ptn’||’%’)
and   owner like upper(nvl(‘&own’,user)||’%’)
order by 1,2,3,5
/
clear colu
spool off

 Comment 

list segment types per tablespace and user.sql

on June 23, 2008 at 12:35 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— ts_usage
— summary of how each none sys/tmp/rbs ts is being used
spool ts_usage.lst
col tablespace_name form a10 head ts_name
col owner form a12
col segment_type form a15
select tablespace_name, owner, segment_type, count(*)
from dba_segments
where tablespace_name not like ‘SYS%’ and tablespace_name not like ‘RBS%’ and tablespace_name not like ‘TEMP%’
group by tablespace_name,owner,segment_type
order by tablespace_name,owner,segment_type
/
spool off
clear col

 Comment 

list rollback segment details.sql

on June 23, 2008 at 12:33 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— rbs_dets.sql
— mdw 02/02/00
— list of rollback seg details
set pause on pages 30 pause ‘Any Key..> ‘
col owner form a7
col instance_num form a1 head I
col rb_name form a15 wrap
col ts_name form a12 wrap
col ini_e_k form 999,999
col nxt_e_k form 999,999
col min_e form 999
col max_e form 99,999
col stat  form A7
spool rbs_dets.lst
—
select
owner
,instance_num
,segment_name     rb_name
,tablespace_name   ts_name
,initial_extent/1024    ini_e_k
,next_extent/1024       nxt_e_k
,min_extents       min_e
,max_extents       max_e
,status            stat
from dba_rollback_segs
order by owner,segment_name
/
spool off
clear col
— EOF

 Comment 

list index partition details.sql

on June 23, 2008 at 12:32 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— par_ind_dets.sql
— mdw 13/7/01
— details of partition index partitions
col index_owner form a8 wrap head ownr
col index_name  form a15 word wrap
col tablespace_name  form a8 word wrap head ts_name
col partition_name  form a10 word wrap head part_name
col leaf_blocks form 999,999 head lf_blks
col high_value form a12 wrap
spool par_dets.lst
select index_owner
,index_name
,partition_name
,tablespace_name
,leaf_blocks
,substr(status,1,5) sts
,to_char(last_analyzed,’DD-MON-YY’) last_anal
,high_value
from dba_ind_partitions dip
where index_name like upper(nvl(‘&pind_name’,’eric’))||’%’
order by index_name,index_owner,partition_position
/
clear col
spool off

 Comment 

list index and column names for a table.sql

on June 23, 2008 at 12:32 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— ind_cols.sql
— mdw – list of all indexes and columns for given table_name start
clear breaks
clear col
col ind_owner form a11 wrap
col ind_name form a18 wrap
col tab_name form a18 wrap
col col_name form a20 wrap
set pause on
set pause ‘Any Key…>’
set array 1
set pages 24
break on ind_owner nodup on ind_name nodup on tab_name skip 1
spool ind_cols.lst
 select
 INDEX_OWNER                 ind_owner
,INDEX_NAME                  ind_Name
,TABLE_NAME                  tab_Name
,substr(column_position,1,3) Psn
,COLUMN_NAME                 Col_Name
from all_ind_columns
–where table_name like upper(nvl(‘ampersanstab_name’,’WHOOPS’)||’%’)
where table_name = upper(nvl(‘&tab_name’,’WHOOPS’))
and table_owner like upper(nvl(‘&tab_own’,’WHOOPS’)||’%’)
order by 3,1,2,4,5
/
spool off

 Comment 

list index and column names for a table again.sql

on June 23, 2008 at 12:32 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— ind_lst.sql
— mdw – list of all indexes and columns for given table_name start
clear breaks
clear col
col ind_own form a8 wrap
col ind_name form a15 wrap
col tab_own form a8 wrap
col tab_name form a12 wrap
col ind_type form a8 wrap
col unq      form a4  trunc
col ts_name  form a8 wrap
col status   form a5  trunc
set pause on
set pause ‘Any Key…>’
set array 1
set pages 24
break on ind_owner nodup on ind_name nodup on tab_name skip 1
spool ind_lst.lst
 select
 OWNER                 ind_own
,INDEX_NAME                  ind_Name
,TABLE_owner                 tab_own
,TABLE_NAME                  tab_Name
,tablespace_name             ts_name
,index_type                  ind_type
,uniqueness                  unq
,partitioned                 part
,status
from dba_indexes
where table_name like upper(nvl(‘&tab_name’,’WHOOPS’)||’%’)
order by 3,1,2,4,5
/
spool off

 Comment 

list gv$resource limits.sql

on June 23, 2008 at 12:31 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— chk_gv_res.sql
— mdw 01/08/01
— quick check on the gv$resource entries. NB most of use on OPS
col inst_id    form 999 head inst
col resource_name form a25 word wrap
col current_utilization head curr_util
col max_utilization     head max_util
col initial_allocation  head ini_alloc
col limit_value         head  Limit_val
spool chk_gv_res.lst
select * from gv$resource_limit where upper(resource_name) like upper(‘&res_name’)||’%’ order by inst_id,resource_name
/
clear colu
spool off

 Comment 

list foreign keys on a table and all foreign references.sql

on June 23, 2008 at 12:31 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— mdw modified to not stick to current user
— and to allow owner to be limited.
— 23/4/04
— nb shit table aliases
— and reciprocal bit bust
— All in all a bit of a crap query
REM Displays all foreign keys for a given table, plus all foreign key references
REM from other tables to this one
REM Modified from the ‘forgnkey.sql’ script on page 439 of ‘Oracle
REM Performance Tuning’
REM SJM, 21.1.98

set echo off
set pages 32

accept tablename prompt ‘View constraints on table: ‘
accept tableowner prompt ‘for tables owned by: ‘
set verify off
column Constraint_from_to format A63
column Constraint_name format A16
spool tab_cols.lst
select unique a.constraint_name,a.table_name||’.’||c.column_name ||’ -> ‘||b.table_name||’.’||d.column_name Constraint_from_to
from dba_constraints  a,
     dba_constraints  b,
     dba_cons_columns c,
     dba_cons_columns d
where
a.r_constraint_name   = b.constraint_name
and a.constraint_type = ‘R’
and b.constraint_type = ‘P’
and a.r_owner         = b.owner
and a.constraint_name = c.constraint_name
and b.constraint_name = d.constraint_name
and a.owner           = c.owner
and a.table_name      = c.table_name
and b.owner           = d.owner
and b.table_name      = d.table_name
and b.constraint_name = d.constraint_name
and a.table_name      like upper(nvl(‘&&tablename’,’whoops’)||’%’)
and a.owner           like upper(‘&&tableowner’||’%’);

PROMPT Reciprocal constraints:

select unique a.constraint_name,a.table_name||’.’||c.column_name ||’ -> ‘||b.table_name||’.’||d.column_name Constraint_from_to
from dba_constraints a
   , dba_constraints b
   , dba_cons_columns c
   , dba_cons_columns d
where
a.r_constraint_name   = b.constraint_name
and a.constraint_type = ‘R’
and b.constraint_type = ‘P’
and a.r_owner         = b.owner
and a.constraint_name = c.constraint_name
and b.constraint_name = d.constraint_name
and a.owner           = c.owner
and a.table_name      = c.table_name
and b.owner           = d.owner
and b.table_name      = d.table_name
and b.table_name      like upper(nvl(‘&&tablename’,’whoops’)||’%’)
and b.owner           like upper(‘&&tableowner’||’%’);
spool off
clear colu

 Comment 

list foreign keys on a table and all foreign references again.sql

on June 23, 2008 at 12:31 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

REM Displays all foreign keys for a given table, plus all foreign key references
REM from other tables to this one
REM Modified from the ‘forgnkey.sql’ script on page 439 of ‘Oracle
REM Performance Tuning’
REM SJM, 21.1.98

set echo off
set pagesize 66

accept tablename prompt ‘View constraints on table: ‘
set verify off
column Constraint_from_to format A49

select unique a.constraint_name,a.table_name||’.’||c.column_name ||’ -> ‘||b.table_name||’.’||d.column_name Constraint_from_to
from dba_constraints a, dba_constraints b, dba_cons_columns c, dba_cons_columns d
where
a.owner = (select user from dual)
and a.r_constraint_name = b.constraint_name
and a.constraint_type = ‘R’
and b.constraint_type = ‘P’
and a.r_owner = b.owner
and a.constraint_name = c.constraint_name
and b.constraint_name = d.constraint_name
and a.owner = c.owner
and a.table_name = c.table_name
and b.owner = d.owner
and b.table_name = d.table_name
and a.table_name = upper(‘&&tablename’);

PROMPT Reciprocal constraints:

select unique a.constraint_name,a.table_name||’.’||c.column_name ||’ -> ‘||b.table_name||’.’||d.column_name Constraint_from_to
from dba_constraints a, dba_constraints b, dba_cons_columns c, dba_cons_columns d
where
a.owner = (select user from dual)
and a.r_constraint_name = b.constraint_name
and a.constraint_type = ‘R’
and b.constraint_type = ‘P’
and a.r_owner = b.owner
and a.constraint_name = c.constraint_name
and b.constraint_name = d.constraint_name
and a.owner = c.owner
and a.table_name = c.table_name
and b.owner = d.owner
and b.table_name = d.table_name
and b.table_name = upper(‘&&tablename’);

 Comment 

list db sessions.sql

on June 23, 2008 at 12:30 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SELECT nvl(S.OSUSER,S.type) OS_Usercode,
       S.USERNAME           Oracle_Usercode,
       S.sid                Oracle_SID,
       S.serial#            serial_#,
       S.process            F_Ground,
       P.spid               B_Ground
FROM   V$SESSION S,
       V$PROCESS P
WHERE  nvl(upper(S.OSUSER),’KKK’)   like nvl(upper(‘&OS_User’),’%’)
And    nvl(upper(S.Username),’KKK’) like nvl(upper(‘&Oracle_User’),’%’)
And    s.paddr  = p.addr
order by  s.sid
/
prompt kill with alter system kill session ‘sid,serial#’

 Comment 

list basic segment details.sql

on June 23, 2008 at 12:30 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— seg_par_dets.sql
— mdw 17/09/01
— quick display of basic segment details
set recsep off
col owner     form a8 word wrap
col seg_name  form a15 word wrap
col seq_type  form a3  head typ
col ts_name   form a8 word wrap
col bytes_k   form 99999,999
col blocks    form 9999,999
col extents   form 9999 head exts
col ini_k     form 999999
col extents   form 999
col nxt_k     form 999999
spool seg_dets.lst
select owner
,segment_name||’ ‘||partition_name seg_name
,decode (segment_type,’TABLE’,’TAB’
                     ,’INDEX’,’IND’
                     ,’TABLE PARTITION’,’TP’
                     ,’INDEX PARTITION’,’IP’
                     ,’ROLLBACK’,’ROL’
                     ,’CLUSTER’,’BLX’
                               ,’OTH’)        seg_type
,tablespace_name                              ts_name
,bytes/1024                                   bytes_k
,blocks
,extents
,initial_extent/1024                          ini_k
,next_extent/1024                             nxt_k
from dba_segments
where segment_name like nvl(upper(‘&seg_name’),’WHOOPS’)||’%’
and partition_name like nvl(upper(‘&par_name’),’WHOOPS’)||’%’
and owner like upper(‘&owner’)||’%’
order by segment_name||’ ‘||partition_name, owner
/
spool off
clear colu
— EOF

 

 Comment 

list basic segment details again.sql

on June 23, 2008 at 12:29 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— seg_dets.sql
— mdw 17/09/01
— quick display of basic segment details
set recsep off
col owner     form a8 word wrap
col seg_name  form a15 word wrap
col seq_type  form a3  head typ
col ts_name   form a8 word wrap
col bytes_k   form 99999,999
col blocks    form 9999,999
col extents   form 9999 head exts
col ini_k     form 999999
col extents   form 999
col nxt_k     form 999999
spool seg_dets.lst
select owner
,segment_name||’ ‘||partition_name seg_name
,decode (segment_type,’TABLE’,’TAB’
                     ,’INDEX’,’IND’
                     ,’TABLE PARTITION’,’TP’
                     ,’INDEX PARTITION’,’IP’
                     ,’ROLLBACK’,’ROL’
                     ,’CLUSTER’,’BLX’
                               ,’OTH’)        seg_type
,tablespace_name                              ts_name
,bytes/1024                                   bytes_k
,blocks
,extents
,initial_extent/1024                          ini_k
,next_extent/1024                             nxt_k
from dba_segments
where segment_name like nvl(upper(‘&seg_name’),’WHOOPS’)||’%’
and owner like upper(‘&owner’)||’%’
order by segment_name||’ ‘||partition_name, owner
/
spool off
clear colu
— EOF

 

 Comment 

list all waits by time waited.sql

on June 23, 2008 at 12:29 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— chk_waits.sql
spool chk_waits.lst
set timi on pause on pages 32
col event form a40 wrap
col total_waits form 999999,999
col total_timeouts form 999999,999 head tot_timouts
select event,total_waits,total_timeouts,time_waited
from v$system_event
order by time_waited desc
/
clear colu
spool off

 Comment 

list all tables.sql

on June 23, 2008 at 12:28 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— tab_lst.sql
— mdw – very simple tables listing
set pause on pages 24 pause ‘Any Key>’
colu num_rows form 9999,999,999
spool tab_lst.lst
select table_name
      ,owner
      ,num_rows
from  all_tables
where table_name like upper(nvl(‘&Tab_name’,’WHOOPS’)||’%’)
and owner not in (‘SYS’,’SYSTEM’)
/
spool off
clear colu

 Comment 

list all sql in sga assigned to a sid.sql

on June 23, 2008 at 12:28 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— sid_sga.sql
— mdw 11/97
— pinched from ‘bee’ book
— list all sql in SGA attached to a given sid.
—
set pause on
set pages 24
set pause ‘Any Key>’
spool sid_sga.lst
select s.process fground
,p.spid bkgrnd,
x.disk_reads,
x.rows_processed,x.users_executing
,x.sql_text
from sys.v_$session s
,sys.v_$process p
,sys.v_$sqlarea x
where s.sid = &sid
and  s.paddr = p.addr
and s.type != ‘BACKGROUND’
and s.sql_address=x.address
and s.sql_hash_value = x.hash_value
order by s.sid
/
spool off
— EOF

 Comment 

list all sequences.sql

on June 23, 2008 at 12:28 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— seq_lst.sql
— mdw 03/09/02
— summary list of sequences
set pages 32
–set pause on
accept seq_name char prompt ‘enter seq name> ‘
col owner    form a10 word wrap
col seq_name form a22 word wrap
col min      form 999
col inc      form 999
col cach     form 9,999
col lst_num  form 9,999,999,999
spool seq_lst.lst
select sequence_owner owner
      ,sequence_name  seq_name
      ,last_number    lst_num
      ,min_value      min
      ,increment_by   inc
      ,cache_size     cach
      ,max_value      mx
from dba_sequences
where sequence_name like upper(‘&seq_name’)||’%’
and sequence_owner !=’SYS’
order by 2,1
/
spool off
clear col
—
— EOF
—

 Comment 

list all objects.sql

on June 23, 2008 at 12:27 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— obj_lst.sql
— mdw 02/02/00
— very simple tables listing
set pause on pages 24 pause ‘Any Key>’
col owner form a10 wrap
col object_name form a20 word wrap
spool obj_lst.lst
select owner
,object_name
,substr(object_type,1,10)  obj_type
,to_char(created,’DD-MON-YY’) cre_date
,to_char(last_ddl_time,’DD-MON-YY HH24:MI:SS’) last_ddl
from  dba_objects
where object_name like upper(nvl(‘&obj_name’,’WHOOPS’)||’%’)
and object_type like upper(nvl(‘&obj_type’,’TABLE’)||’%’)
order by object_name,owner
/
spool off

 Comment 

list all initialisation parameters.sql

on June 23, 2008 at 12:27 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— prm_lst.sql
— mdw 8/97 List all initialisation parameters like param 
— nb spools to 64 lines
set pause on
set pages 30
set pause ‘Any Key..>’
col p_name  format a32 word wrap head “Parameter Name”
col p_value format a35 word wrap head “Parameter Value”
col typ     format a3
col num     format a3
accept param char prompt ‘Search string for parameters (auto wildcarded)> ‘
spool prm_lst.lst
select
 name                           p_name
,value                          p_value
,substr(decode(isdefault
       ,’TRUE’,’Y’
       ,’N’)
       ,1,4)                    dlft
,decode(type
       ,1,’B’
       ,2,’C’
       ,3,’N’
       ,’?’)
                                typ
,substr(num,1,3)                num
from sys.v_$parameter
where name like ‘¶m’||’%’
order by p_name
/
undefine param
spool off
set pages 24
— EOF

 Comment 

list all awr metrics being collected.sql

on June 23, 2008 at 12:27 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— show_awr_metrics
— quickly pull up the metrics being collected by AWR and the units
—
spool show_awr_metrics.lst
col grp form 999
col mtr_id for 99999
col group_name form a20 wrap
col metric_name form a22 wrap
col metric_unit form a22 wrap
select –dbid,
group_id      grp
,group_name
,metric_id   mtr_id
,metric_name
,metric_unit
from dba_hist_metric_name
where lower(metric_name) like ‘&metric’||’%’
order by 2,3,4,5
/
spool off
—

 Comment 

list a tables columns.sql

on June 23, 2008 at 12:26 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— col_lst.sql
set pause off
col owner form a10
col table_name form a20 word wrap
col column_name form a20 word wrap
spool col_lst.lst
select owner,table_name,column_name
from dba_tab_columns
where column_name like (nvl(upper(‘&col_nam’),’WHOOPS’)||’%’)
ORDER BY TABLE_NAME,OWNER
/
clear colu
SPOOL OFF

 Comment 

getsql text for a given hash value again.sql

on June 23, 2008 at 12:26 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— get_text.sql
— get the sqltext for a stated hash_value (which may or may not be
— unique)
set pages 42
set pause on
set trim on
spool get_text.lst
select sql_text
from v$sqltext
where hash_value = ‘&hash_val’
order by address,piece
/
spool off

 Comment 

get sql text for a given hash value.sql

on June 23, 2008 at 12:25 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— get_text.sql
— get the sqltext for a stated hash_value (which may or may not be unique)
set pages 42
set pause on
set trim on
spool get_text.lst
select sql_text
from v$sqltext where hash_value = ‘&hash_val’ order by address,piece
/
spool off

 Comment 

get os info and hostname.sql

on June 23, 2008 at 12:25 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

–os_chk.sql
— mdw 99
— quick check of what server you are on. Wrote before V$instance available?
— NB Gives full OS info – no available from v$instance
set serveroutput on;
begin
declare
v_temp varchar2(255) := ‘hello world’;
begin
  v_temp := dbms_utility.port_string;
  dbms_output.put_line(v_temp);
end;
end;
/

 Comment 

get general tablespace info.sql

on June 23, 2008 at 12:24 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— ts_lst.sql
— mdw 23/6/97
— simple list of tablespaces
set pause on
set pages 24
set pause ‘Any Key>’
col ini_ext_k form 9,999,999
col next_ext_k form 9,999,999
col min_ex form 999
col min_extln form 999,999
spool ts_lst.lst
select substr(tablespace_name,1,15)       ts_name
      ,initial_extent/1024                ini_ext_K
      ,next_extent/1024                   next_ext_K
      ,min_extents                        min_ex
      ,max_extents                        max_ex
      ,substr(to_char(pct_increase),1,3)  pct
      ,min_extlen/1024                    min_extln
      ,status            st
from sys.dba_tablespaces
where tablespace_name like upper(‘&ts_name’||’%’)
order by 1
/
spool off
clear colu
—
— End of File
—

 Comment 

get general tablespace info another.sql

on June 23, 2008 at 12:24 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— ts_ro_lst.sql
— mdw 08/09/04
— simple list of tablespaces
set pause on
set pages 24
set pause ‘Any Key>’
col ini_ext_k form 9,999,999
col next_ext_k form 9,999,999
col min_ex form 999
col min_extln form 999,999
spool ts_ro_lst.lst
select substr(tablespace_name,1,17)       ts_name
      ,initial_extent/1024                ini_ext_K
      ,next_extent/1024                   next_ext_K
      ,min_extents                        min_ex
      ,max_extents                        max_ex
      ,substr(to_char(pct_increase),1,3)  pct
      ,min_extlen/1024                    min_extln
      ,decode(status,’ONLINE’     ,’ON’
                      ,’READ ONLY’, ‘R-O’
                                  ,substr(status,1,3) )        st
from sys.dba_tablespaces
where tablespace_name like upper(‘&ts_name’||’%’)
and status = ‘READ ONLY’
order by 1
/
spool off
clear colu

 

 Comment 

get general tablespace info again.sql

on June 23, 2008 at 12:24 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— tab_detf.sql
— mdw – show details of selected tables.
set pause on pages 24
clear col
clear breaks
spool tab_detf.lst
col own         form A8
col name        form A25 trunc
col tblspc      form A8  trunc
col clu         form A4
col pctf        form 99
col pctu        form 99
col it          form 99
col mt          form 999
col intl_k      form 9999,999
col next_k      form 9999,999
col pct         form 999
col min_e       form 99999
col max_e       form 99999
col n_rows      form 999,999,999
col n_blocks    form 999,999,999
col empty       form 999,999
col avg_spc     form 9,999
col av_len      form 9999
select
 owner            own
,table_name       name
,tablespace_name  tblspc
,cluster_name     clu
,pct_free         pctf
,pct_used         pctu
,ini_trans        it
,max_trans        mt
,initial_extent/1024   intl_k
,next_extent/1024      next_k
,pct_increase     pct
,min_extents      min_e
,max_extents      max_e
,num_rows         n_rows
,blocks           n_blocks
,empty_blocks     empty
,avg_space        avg_spc
,avg_row_len      av_len
,logging          log
from all_tables
where table_name like upper(nvl(‘&tab_name’,’WHOOPS’)||’%’)
order by table_name,owner
/
clear colu
spool off

 Comment 

get general tablespace info again again.sql

on June 23, 2008 at 12:23 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— tab_det.sql
— mdw – show brief details of selected tables.
–       cut-down version of tab_dets.
set pause on pages 24
clear col
clear breaks
break on own nodup on name nodup
spool tab_det.lst
col own         form A8
col name        form A15 word wrap
col tblspc      form A8  word wrap
col pctf        form 99
col pctu        form 99
col in_ext      form 9999,999 head ‘in extK’
col n_ext       form 9999,999 head ‘nxt exK’
col pct         form 99
select
 owner            own
,table_name       name
,tablespace_name  tblspc
,to_char(last_analyzed,’DD-MM-YY HH24:MI’) anlyzd
,pct_free         pctf
,pct_used         pctu
,initial_extent/1024   in_ext
,next_extent/1024      n_ext
,pct_increase     pct
from all_tables
where table_name like upper(nvl(‘&tab_name’,’WHOOPS’)||’%’)
order by table_name,owner
/
clear colu
spool off

 Comment 

explain plan template.sql

on June 23, 2008 at 12:23 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— explain template
set pages 5000
set pause off
undef statement
set verify off  feedback off
explain plan
set statement_id = ‘mdw’
into plan_table
for
— insert sql here
—
SELECT MAX(MIN_ID)
FROM (  SELECT MIN(UNIQUEID) MIN_ID
       FROM BOBJ_LOGIN.ORDERS
       WHERE STATUS = :B2 AND UNIQUEID >= :B1
       UNION ALL
       SELECT MIN(UNIQUEID) MIN_ID
       FROM BOBJ_LOGIN.ORDERS
       WHERE STATUS = :B2 AND UNIQUEID > :B1 )
/
—
spool exp1.lst
select operation||’ ‘||to_char(timestamp,’DD/MM HH24:MI:SS’)||’ ‘||optimizer||’
cst:’||to_char(cost)||’ crd:’||to_char(cardinality) Plan
from plan_table
where statement_id = ‘mdw’
and id = 0
/
select lpad(‘ ‘,2*level)||operation||’ ‘||options||’ ‘||object_name
  ||decode(cost,null,decode(partition_start,null,null
                           ,    ‘ strt ‘||partition_start
                               ||’ stp ‘||partition_stop)
              ,    ‘ cst:’||to_char(cost)||’ rws:’||cardinality
          )
            Plan
from plan_table
where statement_id = ‘mdw’
connect by prior id = parent_id
and        prior statement_id = ‘mdw’
start with id = 1
/
spool off
delete from plan_table
where statement_id = ‘mdw’
/
set verify on  feedback on  pause on  pause ‘Any Key…>’
—
— End of File
—

 

 Comment 

explain plan template again.sql

on June 23, 2008 at 12:23 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— explain template
set pages 5000
set pause off
undef statement
set verify off  feedback off
explain plan
set statement_id = ‘mdw’
into plan_table
for
— insert sql here
—
—
spool exp1.lst
select operation||’ ‘||to_char(timestamp,’DD/MM HH24:MI:SS’)||’ ‘||optimizer||’ cst:’||to_char(cost)||’ crd:’||to_char(cardinality) Plan
from plan_table
where statement_id = ‘mdw’
and id = 0
/
select rpad(to_char(id),2*level)||operation||’ ‘||options||’ ‘||object_name
  ||decode(cost,null,decode(partition_start,null,null
                           ,    ‘ strt ‘||partition_start
                               ||’ stp ‘||partition_stop)
               ,      decode(partition_id,null,”
                       ,     ‘ P’||partition_id)
                      ||’ cst:’||to_char(cost)||’ rws:’||cardinality
          )
            Plan
from plan_table
where statement_id = ‘mdw’
connect by prior id = parent_id
and        prior statement_id = ‘mdw’
start with id = 1
/
spool off
delete from plan_table
where statement_id = ‘mdw’
/
set verify on  feedback on  pause on  pause ‘Any Key…>’
—
— End of File
—

 

 Comment 

detiled info on a table columns.sql

on June 23, 2008 at 12:22 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— col_stats
— mdw 21/03/2003
— more detailed info on cols
col owner        form a6 word wrap
col table_name   form a12 word wrap
col column_name  form a22 word wrap
col M            form a1
col num_vals     form 999,999,999
col dnsty        form 0.9999
col num_nulls    form 999,999,999
break on owner nodup on table_name nodup
spool col_counts.lst
select owner
      ,table_name
      ,column_name
      ,decode (nullable,’N’,’Y’,’N’)  M
      ,num_distinct num_vals
      ,num_nulls
      ,density dnsty
from dba_tab_columns
where table_name like upper(nvl(‘&tab_name’,’WHOOPS’)||’%’)
and   owner      like upper(‘&tab_own’||’%’)
ORDER BY owner,table_name,COLUMN_ID
/
clear colu
spool off
clear breaks

 Comment 

describe multiple tables.sql

on June 23, 2008 at 12:22 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

 — tab_dc.sql
 — MDW – Allows repeat running, having started own spooling
 SET PAUSE off
 SET PAUSE ‘Any Key…>’
 SET PAGES 32
 break on tab_own skip 1 on tab_name skip 1
 SELECT
substr(OWNER,1,10)           Tab_Own
,substr(TABLE_NAME,1,23)    Tab_Name
,substr(COLUMN_NAME,1,28)   Col_Name
,decode(NULLABLE,’Y’,’N’,’Y’)        Mand
,substr(data_type||decode(data_type
       ,’NUMBER’,'(‘
        ||decode(to_char(data_precision)
                ,null,’38’
                ,     to_char(data_precision)||
                      decode(data_scale,null,”
                                      ,      ‘,’||data_scale)
                 )
                    ||’)’
       ,’DATE’,null
       ,’LONG’,null
       ,’LONG RAW’,null
       ,'(‘||Substr(DATA_LENGTH,1,5)||’)’
       ) ,1,12)  col_def
FROM ALL_TAB_COLUMNS
where table_name like upper (nvl(‘&TAB_NAME’,’WHOOPS’)) –||’%’)
order by 1,2,column_id,3,4
/
— EOF

 Comment 

describe a table.sql

on June 23, 2008 at 12:22 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

—
— tab_desc.sql
— mdw date? way back in the mists of time
— my own replacement for desc.
— 16/11/01 improved the data_type section
 SET PAUSE ON
 SET PAUSE ‘Any Key…>’
 SET PAGES 24
 col Tab_own form A10
 col tab_name form a22 wrap
 col col_name form a28 wrap
 col col_def form A14
 break on tab_own skip 1 on tab_name skip 1
 spool tab_desc.lst
 select
 owner                               Tab_Own
,table_name             Tab_Name
,column_name            Col_Name
,decode(NULLABLE,’Y’,’N’,’Y’)        Mand
,data_type||decode(data_type
       ,’NUMBER’,'(‘
        ||decode(to_char(data_precision)
                ,null,’38’
                ,     to_char(data_precision)||
                      decode(data_scale,null,”
                                      ,      ‘,’||data_scale)
                 )
                    ||’)’
       ,’DATE’,null
       ,’LONG’,null
       ,’LONG RAW’,null
       ,'(‘||Substr(DATA_LENGTH,1,5)||’)’
         )  col_def
from dba_tab_columns
where table_name like upper (nvl(‘&TAB_NAME’,’WHOOPS’)||’%’)
order by 1,2,column_id,3,4
/
spool off
clear col
—

 Comment 

create script to rebuild all invalid objects.sql

on June 23, 2008 at 12:21 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— cre_re_bld_objs.sql
— adb 18/11/02
— create a script to re-build all invalid objects, inc sys ones.
—
set pagesize 2000
set linesize 100
set head off
set feed off
set verify off
set pause off
set escape \

spool re_bld_objs.sql

select ‘alter procedure ‘|| owner||’.’||object_name
      ||’ compile;’
from dba_objects
where status != ‘VALID’
and   object_type = ‘PROCEDURE’;

select ‘alter function ‘|| owner||’.’||object_name
      ||’ compile;’
from dba_objects
where status != ‘VALID’
and   object_type = ‘FUNCTION’;

select ‘alter package ‘|| owner||’.’||object_name
      ||’ compile;’
from dba_objects
where status != ‘VALID’
and   object_type = ‘PACKAGE’;

select ‘alter package ‘|| owner||’.’||object_name
      ||’ compile body;’
from dba_objects
where status != ‘VALID’
and   object_type = ‘PACKAGE BODY’;

select ‘alter view ‘|| owner||’.’|| object_name
      ||’ compile;’
from dba_objects
where status != ‘VALID’
and   object_type = ‘VIEW’;

spool off

set head on
select count(*) “Invalid count:” from dba_objects where status != ‘VALID’;

prompt
pause Hit RETURN to compile or ctrl-d to quit…

spool comp.lst

@re_bld_objs

select count(*) “Invalid count:” from dba_objects where status != ‘VALID’;

prompt
prompt (several runs may be reqd if you have complex dependencies)

spool off

 

 Comment 

create a test dba schema.sql

on June 23, 2008 at 12:20 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— cre_dbav_usr
— create a schema to be used by dba’s for viewing and testing any database.
— Need to alter ts’s for each instance.
— Where can, use temp_02 and data_01
drop user dbaview cascade;
—
create user dbaview identified by &1
temporary tablespace temp_01
default tablespace   data_01
/
grant connect to dbaview;
grant resource to dbaview;
grant select any table to dbaview;
grant unlimited tablespace to dbaview;

 Comment 

crate a stats table.sql

on June 23, 2008 at 12:20 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— cre_stats_tab.sql
— create it owned by oradba in the dbaadmin_dat TS for now.
drop public synonym stattab;
EXEC dbms_stats.create_stat_table(‘SYSTEM’,’CMC_STATS’,’DBAADMIN_DAT’);
create public synonym cmc_stats for system.cmc_stats;
grant all on system.cmc_stats to oradba;
grant all on system.cmc_stats to orasup;

 

 Comment 

check_hidden_params.sql

on June 23, 2008 at 12:19 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

select
  substr(x.ksppinm,1,40)  name,
  substr(y.ksppstvl,1,20)  value,
  substr(x.ksppdesc, 1, 64) description,
  substr(y.ksppstdf, 1, 5)  “DEFAULT”,
  substr(decode(bitand(ksppiflg/256,1),1,’TRUE’,’FALSE’), 1, 5)  ses_mod,
  substr(decode(
    bitand(ksppiflg/65536,3),
    1,’IMMEDIATE’,
    2,’DEFERRED’,
    3,’IMMEDIATE’,
      ‘FALSE’
  ), 1, 10)  sys_mod ,
  substr(decode(bitand(y.ksppstvf,2),2,’TRUE’,’FALSE’), 1, 5)  is_adjusted
from
  sys.x_$ksppi x,
  sys.x_$ksppcv y
where
  x.indx = y.indx
order by
  translate(x.ksppinm, ‘ _’, ‘ ‘)
/

 Comment 

check for analyzed tables with chaining.sql

on June 23, 2008 at 12:19 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

— tab_chain.sql
— mdw 10/07/01
— check for any analysed tables with significant chaining
set pages 24
set pause on
set pause ‘Any Key…’
col table_name form a25 word wrap
col owner      form a15 word wrap
col num_rows   form 999,999,999
col chain_cnt  form 9,999,999
col pct_chn  form 99.99
accept tab_name char prompt ‘which tables are to be checked ? >’
prompt only works on analyzed tables/partitioned tables
spool tab_chain.lst
select table_name
      ,owner
      ,num_rows
      ,chain_cnt
      ,(nvl(chain_cnt,1)/nvl(num_rows,1))*100 pct_chn
from sys.dba_tables
— NB keep greatest for num_rows and  percentage in line else a table with
— (in this case) less than 1000 rows will always be detected.
where greatest(nvl(chain_cnt,1),1)
     /greatest(nvl(num_rows,1),1000)   > 0.001
and table_name like upper(‘&tab_name’||’%’)
and owner not in (‘SYS’,’SYSTEM’)
union
select table_name||’ ‘||partition_name table_name
      ,table_owner                     owner
      ,num_rows
      ,chain_cnt
      ,(nvl(chain_cnt,1)/nvl(num_rows,1))*100 pct_chn
from sys.dba_tab_partitions
— NB keep greatest for num_rows and  percentage in line else a table with
— (in this case) less than 1000 rows will always be detected.
where greatest(nvl(chain_cnt,1),1)
     /greatest(nvl(num_rows,1),1000)   > 0.001
and table_name like upper(‘&tab_name’||’%’)
and table_owner not in (‘SYS’,’SYSTEM’)
order by 1,2
/
spool off
clear colu

 Comment 

alter all users to new default temp tablespace

on June 23, 2008 at 12:18 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

— cre_alt_usr_ts.sql
— mdw 02/02/00
— create alt_usr_ts.sql to alter all users to new temp ts
set pause off
set head off
set feed off veri off
accept ts_name prompt ‘what tablespace are users to be swapped to? >’
spool alt_usr_ts.sql
select ‘alter user ‘||username||’ temporary tablespace ‘||
       nvl(‘&ts_name’,’TEMP_02′)||’;’
from dba_users
where temporary_tablespace like ‘T%’
/
undefine ts_name
spool off
set head on veri on
set pause on
set pause ‘Any Key…>’
set feed on

 Comment 

tablespace size and free space

on June 17, 2008 at 8:04 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

select

   a.tablespace_name, to_char((sum(a.bytes)/1024/1024),’999999′),
          (select to_char((sum(b.bytes)/1024/1024),’999999′) from dba_data_files b where a.tablespace_name = b.tablespace_name)
from

dba_free_space a

group by a.tablespace_name

order by a.tablespace_name;

 Comment 

select extents

on June 17, 2008 at 7:59 pm
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

col owner form a15
col seg_name form a38
col extent_id form 9999 head extno
col ext_sizek form 9999,999,999

select owner, segment_name||’-‘||partition_name seg_name, extent_id, trunc(bytes/1024) ext_sizek
from
  dba_extents
where
  segment_name like nvl(upper(‘&seg_name’),’WHOOPS’)||’%’
  and owner like upper(‘&owner’)||’%’
  and partition_name like nvl(upper(‘&parname’),’%’)||’%’
order by
  seg_name,owner,extent_id;

 Comment 

sql to list users to kill

on June 17, 2008 at 7:57 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSLKILL.SQL
REM USAGE:”@path/tfslkill”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$LOCK, V$SESSION, SYS.USER$, SYS.OBJ$
REM ————————————————————————
REM PURPOSE:
REM    The report generated by this script gives information on sessions
REM    which are holding locks and gives the information needed to kill
REM    using the ALTER SYSTEM KILL SESSION command.
REM ————————————————————————
REM Main text of script follows:
 
set linesize 132 pagesize 66
break on Kill on username on terminal
column Kill heading ‘Kill String’ format a13
column res heading ‘Resource Type’ format 999
column id1 format 9999990
column id2 format 9999990
column lmode heading ‘Lock Held’ format a20
column request heading ‘Lock Requested’ format a20
column serial# format 99999
column username  format a10  heading “Username”
column terminal heading Term format a6
column tab format a35 heading “Table Name”
column owner format a9
column Address format a18
select nvl(S.USERNAME,’Internal’) username,
 nvl(S.TERMINAL,’None’) terminal,
 L.SID||’,’||S.SERIAL# Kill,
 U1.NAME||’.’||substr(T1.NAME,1,20) tab,
 decode(L.LMODE,1,’No Lock’,
  2,’Row Share’,
  3,’Row Exclusive’,
  4,’Share’,
  5,’Share Row Exclusive’,
  6,’Exclusive’,null) lmode,
 decode(L.REQUEST,1,’No Lock’,
  2,’Row Share’,
  3,’Row Exclusive’,
  4,’Share’,
  5,’Share Row Exclusive’,
  6,’Exclusive’,null) request
from V$LOCK L, 
 V$SESSION S,
 SYS.USER$ U1,
 SYS.OBJ$ T1
where L.SID = S.SID 
and T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2) 
and U1.USER# = T1.OWNER#
and S.TYPE != ‘BACKGROUND’
order by 1,2,5
/

 Comment 

list running jobs dba_jobs

on June 17, 2008 at 7:54 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSDBJRN.SQL
REM USAGE:”@path/tfsdbjrn”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on DBA_JOBS, DBA_JOBS_RUNNING
REM ————————————————————————
REM PURPOSE:
REM    Lists all jobs that are currently running in the local databbase.
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 80
ttitle –
  center  ‘List Running Jobs’  skip 2
 
col sess format 99   heading ‘Ses’
col jid  format 999  heading ‘Id’
col subu format a10  heading ‘Submitter’     trunc
col secd format a10  heading ‘Security’      trunc
col proc format a20  heading ‘Job’           word_wrapped
col lsd  format a5   heading ‘Last|Ok|Date’ 
col lst  format a5   heading ‘Last|Ok|Time’
col nrd  format a5   heading ‘This|Run|Date’
col nrt  format a5   heading ‘This|Run|Time’
col fail format 99 heading ‘Err’
 
select
  djr.sid                        sess,
  djr.job                        jid,
  dj.log_user                    subu,
  dj.priv_user                   secd,
  dj.what                        proc,
  to_char(djr.last_date,’MM/DD’) lsd,
  substr(djr.last_sec,1,5)       lst,
  to_char(djr.this_date,’MM/DD’) nrd,
  substr(djr.this_sec,1,5)       nrt,
  djr.failures                   fail
from
  sys.dba_jobs dj,
  sys.dba_jobs_running djr
where
  djr.job = dj.job
/

 Comment 

list submitted jobs dba_jobs

on June 17, 2008 at 7:53 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSDBJBS.SQL
REM USAGE:”@path/tfsdbjbs”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on DBA_JOBS
REM ————————————————————————
REM PURPOSE:
REM    Lists all jobs that have been submitted to run in the
REM    local database job queue.
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 80
ttitle –
  center  ‘List Submitted Jobs’ skip 2
 
col jid  format 999  heading ‘Id’
col subu format a10  heading ‘Submitter’     trunc
col secd format a10  heading ‘Security’      trunc
col proc format a20  heading ‘Job’           word_wrapped
col lsd  format a5   heading ‘Last|Ok|Date’ 
col lst  format a5   heading ‘Last|Ok|Time’
col nrd  format a5   heading ‘Next|Run|Date’
col nrt  format a5   heading ‘Next|Run|Time’
col fail format 999  heading ‘Errs’
col ok   format a2   heading ‘Ok’
 
select
  job                        jid,
  log_user                   subu,
  priv_user                  secd,
  what                       proc,
  to_char(last_date,’MM/DD’) lsd,
  substr(last_sec,1,5)       lst,
  to_char(next_date,’MM/DD’) nrd,
  substr(next_sec,1,5)       nrt,
  failures                   fail,
  decode(broken,’Y’,’N’,’Y’) ok
from
  sys.dba_jobs
/

 Comment 

more sql users and locks

on June 17, 2008 at 7:52 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:    TFSLKSQL.SQL
REM USAGE:”@path/tfslksql”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$SQLTEXT, V$SESSION, and V$ACCESS
REM ————————————————————————
REM PURPOSE:
REM    This script will report the SQL text of some of the locks 
REM    currently being held in the database.
REM ————————————————————————
REM EXAMPLE:
REM    USERNAME                              SID
REM    —————————— ———-
REM    OBJECT
REM    ——————————————————————-
REM    LOCKWAIT SQL
REM    ——– ———————————————————-
REM    SYSTEM                                 11
REM    SCOTT.TABLE_CONFIG
REM    E0034A5C update scott.table_config set tabno=99 where tabno=9
REM    
REM    SYS                                     6
REM    SCOTT.TABLE_CONFIG
REM    E0034C98 update scott.table_config set capacity=28 where capacity=4
REM 
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 60
set linesize 132
select s.username username, 
       a.sid sid, 
       a.owner||’.’||a.object object, 
       s.lockwait, 
       t.sql_text SQL
from   v$sqltext t, 
       v$session s, 
       v$access a
where  t.address=s.sql_address 
and    t.hash_value=s.sql_hash_value 
and    s.sid = a.sid 
and    a.owner != ‘SYS’
and    upper(substr(a.object,1,2)) != ‘V$’;
/* OR
select s.username username, s.sid, s.serial#, 
       t.sql_text SQL
from   v$sqltext t, 
       v$session s
where  t.address=s.sql_address 
and    t.hash_value=s.sql_hash_value
and     s.type = ‘USER’
*/
;

 Comment 

show all users and locks

on June 17, 2008 at 7:47 pm
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSLCKWT.SQL
REM USAGE:”@path/tfslckwt”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$SESSION, V$LOCK
REM ————————————————————————
REM PURPOSE:
REM    Reports users waiting for locks.
REM ————————————————————————
REM EXAMPLE:
REM    USERNAME          SID TYPE HELD        REQ           ID1        ID2
REM    ————— —– —- ———– ———– ——– ——–
REM    SYSTEM             12 TX   Exclusive   None          131087     2328
REM    SCOTT               7 TX   None        Exclusive     131087     2328 
REM    SCOTT               8 TX   Exclusive   None          131099     2332
REM    SYSTEM             10 TX   None        Exclusive     131099     2332
REM    SYSTEM             12 TX   None        Exclusive     131099     2332
REM 
REM ————————————————————————
REM
column username format  A15
column sid      format  9990    heading SID
column type     format  A4
column lmode    format  990     heading ‘HELD’
column request  format  990     heading ‘REQ’
column id1      format  9999990
column id2 format  9999990
break on id1 skip 1 dup
spool tfslckwt.lst

SELECT sn.username, m.sid, m.type,
        DECODE(m.lmode, 0, ‘None’,
                        1, ‘Null’,
                        2, ‘Row Share’,
                        3, ‘Row Excl.’,
                        4, ‘Share’,
                        5, ‘S/Row Excl.’,
                        6, ‘Exclusive’,
                lmode, ltrim(to_char(lmode,’990′))) lmode,
        DECODE(m.request,0, ‘None’,
                         1, ‘Null’,
                         2, ‘Row Share’,
                         3, ‘Row Excl.’,
                         4, ‘Share’,
                         5, ‘S/Row Excl.’,
                         6, ‘Exclusive’,
                         request, ltrim(to_char(m.request,
                ‘990’))) request, m.id1, m.id2
FROM v$session sn, v$lock m
WHERE (sn.sid = m.sid AND m.request != 0)
OR    (sn.sid = m.sid AND m.request = 0 AND lmode != 4
       AND (id1, id2)
          IN (SELECT s.id1, s.id2 FROM v$lock s
              WHERE request != 0 AND s.id1 = m.id1 AND s.id2 = m.id2
             )
      )
ORDER BY id1, id2, m.request;
spool off
clear breaks;

 Comment 

rman and nls date format – until time

on June 17, 2008 at 8:16 am
Posted In: Oracle Rman Notes (Cat)

— Before invoking RMAN, set the NLS_DATE_FORMAT and NLS_LANG environment variables.

— These variables determine the format used for the time parameters in RMAN commands such as RESTORE, RECOVER, and REPORT.

— The following example shows typical language and date format settings:

export NLS_LANG=english.WE8MSWIN1252
export NLS_DATE_FORMAT=’Mon DD YYYY HH24:MI:SS’

set NLS_LANG=english.WE8MSWIN1252
set NLS_DATE_FORMAT=Mon DD YYYY HH24:MI:SS

— To perform an incomplete recovery, shutdown the databases, startup mount

Shutdown immediate;
startup mount;
RUN
{
  SET UNTIL TIME ‘Oct 28 2005 11:00:00’;
  # SET UNTIL SCN 1000;       # alternatively, you can specify SCN
  # SET UNTIL SEQUENCE 9923;  # alternatively, you can specify log sequence number
  RESTORE DATABASE;
  RECOVER DATABASE;
}
ALTER DATABASE OPEN RESETLOGS;

– Shutdown the database and perform a full backup

 

 Comment 

report sql text of locks in database

on June 17, 2008 at 8:14 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:    TFSLKSQL.SQL
REM USAGE:”@path/tfslksql”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$SQLTEXT, V$SESSION, and V$ACCESS
REM ————————————————————————
REM PURPOSE:
REM    This script will report the SQL text of some of the locks 
REM    currently being held in the database.
REM ————————————————————————
REM EXAMPLE:
REM    USERNAME                              SID
REM    —————————— ———-
REM    OBJECT
REM    ——————————————————————-
REM    LOCKWAIT SQL
REM    ——– ———————————————————-
REM    SYSTEM                                 11
REM    SCOTT.TABLE_CONFIG
REM    E0034A5C update scott.table_config set tabno=99 where tabno=9
REM    
REM    SYS                                     6
REM    SCOTT.TABLE_CONFIG
REM    E0034C98 update scott.table_config set capacity=28 where capacity=4
REM 
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 60
set linesize 132
select s.username username, 
       a.sid sid, 
       a.owner||’.’||a.object object, 
       s.lockwait, 
       t.sql_text SQL
from   v$sqltext t, 
       v$session s, 
       v$access a
where  t.address=s.sql_address 
and    t.hash_value=s.sql_hash_value 
and    s.sid = a.sid 
and    a.owner != ‘SYS’
and    upper(substr(a.object,1,2)) != ‘V$’
/

/*

set pagesize 60
set linesize 132
select s.username username, s.sid, s.serial#, 
       t.sql_text SQL
from   v$sqltext t, 
       v$session s
where  t.address=s.sql_address 
and    t.hash_value=s.sql_hash_value
and     s.type = ‘USER’
/
*/

 Comment 

list all queued jobs

on June 17, 2008 at 8:12 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSDBJBS.SQL
REM USAGE:”@path/tfsdbjbs”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on DBA_JOBS
REM ————————————————————————
REM PURPOSE:
REM    Lists all jobs that have been submitted to run in the
REM    local database job queue.
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 80
ttitle –
  center  ‘List Submitted Jobs’ skip 2
 
col jid  format 999  heading ‘Id’
col subu format a10  heading ‘Submitter’     trunc
col secd format a10  heading ‘Security’      trunc
col proc format a20  heading ‘Job’           word_wrapped
col lsd  format a5   heading ‘Last|Ok|Date’ 
col lst  format a5   heading ‘Last|Ok|Time’
col nrd  format a5   heading ‘Next|Run|Date’
col nrt  format a5   heading ‘Next|Run|Time’
col fail format 999  heading ‘Errs’
col ok   format a2   heading ‘Ok’
 
select
  job                        jid,
  log_user                   subu,
  priv_user                  secd,
  what                       proc,
  to_char(last_date,’MM/DD’) lsd,
  substr(last_sec,1,5)       lst,
  to_char(next_date,’MM/DD’) nrd,
  substr(next_sec,1,5)       nrt,
  failures                   fail,
  decode(broken,’Y’,’N’,’Y’) ok
from
  sys.dba_jobs
/

 Comment 

list running db jobs

on June 17, 2008 at 8:11 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSDBJRN.SQL
REM USAGE:”@path/tfsdbjrn”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on DBA_JOBS, DBA_JOBS_RUNNING
REM ————————————————————————
REM PURPOSE:
REM    Lists all jobs that are currently running in the local databbase.
REM ————————————————————————
REM Main text of script follows:
 
set pagesize 80
ttitle –
  center  ‘List Running Jobs’  skip 2
 
col sess format 99   heading ‘Ses’
col jid  format 999  heading ‘Id’
col subu format a10  heading ‘Submitter’     trunc
col secd format a10  heading ‘Security’      trunc
col proc format a20  heading ‘Job’           word_wrapped
col lsd  format a5   heading ‘Last|Ok|Date’ 
col lst  format a5   heading ‘Last|Ok|Time’
col nrd  format a5   heading ‘This|Run|Date’
col nrt  format a5   heading ‘This|Run|Time’
col fail format 99 heading ‘Err’
 
select
  djr.sid                        sess,
  djr.job                        jid,
  dj.log_user                    subu,
  dj.priv_user                   secd,
  dj.what                        proc,
  to_char(djr.last_date,’MM/DD’) lsd,
  substr(djr.last_sec,1,5)       lst,
  to_char(djr.this_date,’MM/DD’) nrd,
  substr(djr.this_sec,1,5)       nrt,
  djr.failures                   fail
from
  sys.dba_jobs dj,
  sys.dba_jobs_running djr
where
  djr.job = dj.job
/

 Comment 

list inactive db users

on June 17, 2008 at 7:54 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSINSES.SQL
REM USAGE:”@path/tfsinses.sql”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$SESSION, V$PROCESS, V$SESSION_WAIT
REM ————————————————————————
REM PURPOSE:
REM    This script lists inactive users in the database.  The wait
REM    sequence can be monitored to check whether this really is an
REM    inactive user or not.  The process id’s can assist you to
REM    remove the process
REM ————————————————————————
REM EXAMPLE:
REM                                         Shadow     Parent      Wait
REM    ORACLE/OS User   Term    SID SERIAL# Process ID Process ID  Sequence
REM    —————- —— —- ——- ———- ———- ———
REM    SYSTEM usupport  ttype     6      21 26351      26350       28
REM
REM ————————————————————————
REM DISCLAIMER:
REM    This script is provided for educational purposes only. It is NOT
REM    supported by Oracle World Wide Technical Support.
REM    The script has been tested and appears to work as intended.
REM    You should always run new scripts on a test instance initially.
REM ————————————————————————
REM Main text of script follows:
set heading on feedback on pages 66
column userinfo heading “ORACLE/OS User” format a19
column terminal heading “Term” format a6
column process heading “Parent|Process ID” format a10
column spid heading “Shadow|Process ID” format a10
column seq# heading “Wait|Sequence” format 99999990
select s.username ||’ ‘|| s.osuser userinfo, s.terminal, s.sid, s.serial#, p.spid, s.process , w.seq#
from
  v$session s, v$process p, v$session_wait w
where
  p.addr = s.paddr
  and s.sid = w.sid
  and w.event = ‘SQL*Net message from client’
  and s.status = ‘INACTIVE’
order by
  s.osuser, s.terminal
/

 Comment 

list extents by owner

on June 17, 2008 at 7:51 am
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

col owner form a15
col seg_name form a38
col extent_id form 9999 head extno
col ext_sizek form 9999,999,999

select owner, segment_name||’-‘||partition_name seg_name, extent_id, trunc(bytes/1024) ext_sizek
from
  dba_extents
where
  segment_name like nvl(upper(‘&seg_name’),’WHOOPS’)||’%’
  and owner like upper(‘&owner’)||’%’
  and partition_name like nvl(upper(‘&parname’),’%’)||’%’
order by
  seg_name,owner,extent_id;

 Comment 

display sessions holding locks

on June 17, 2008 at 7:47 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSLKILL.SQL
REM USAGE:”@path/tfslkill”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$LOCK, V$SESSION, SYS.USER$, SYS.OBJ$
REM ————————————————————————
REM PURPOSE:
REM    The report generated by this script gives information on sessions
REM    which are holding locks and gives the information needed to kill
REM    using the ALTER SYSTEM KILL SESSION command.
REM ————————————————————————
REM Main text of script follows:
 
set linesize 132 pagesize 66
break on Kill on username on terminal
column Kill heading ‘Kill String’ format a13
column res heading ‘Resource Type’ format 999
column id1 format 9999990
column id2 format 9999990
column lmode heading ‘Lock Held’ format a20
column request heading ‘Lock Requested’ format a20
column serial# format 99999
column username  format a10  heading “Username”
column terminal heading Term format a6
column tab format a35 heading “Table Name”
column owner format a9
column Address format a18
select nvl(S.USERNAME,’Internal’) username,
 nvl(S.TERMINAL,’None’) terminal,
 L.SID||’,’||S.SERIAL# Kill,
 U1.NAME||’.’||substr(T1.NAME,1,20) tab,
 decode(L.LMODE,1,’No Lock’,
  2,’Row Share’,
  3,’Row Exclusive’,
  4,’Share’,
  5,’Share Row Exclusive’,
  6,’Exclusive’,null) lmode,
 decode(L.REQUEST,1,’No Lock’,
  2,’Row Share’,
  3,’Row Exclusive’,
  4,’Share’,
  5,’Share Row Exclusive’,
  6,’Exclusive’,null) request
from V$LOCK L, 
 V$SESSION S,
 SYS.USER$ U1,
 SYS.OBJ$ T1
where L.SID = S.SID 
and T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2) 
and U1.USER# = T1.OWNER#
and S.TYPE != ‘BACKGROUND’
order by 1,2,5
/

 Comment 

dbms_metadata to get ddl for creating objects

on June 17, 2008 at 7:45 am
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

 

select  dbms_metadata.get_ddl(‘INDEX’, a.object_name)
from    dba_objects a
where object_name like ‘%ORDERS%’ AND
          OWNER = ‘BOBJ_LOGIN’ AND
          OBJECT_TYPE = ‘INDEX’

SET LONG 2000000
SET PAGESIZE 0
SELECT DBMS_METADATA.GET_XML(‘TABLE’,’EMP’,’SCOTT’) FROM DUAL;

select dbms_metadata.get_ddl(‘TABLESPACE’,a.name) from v$tablespace a;

select dbms_metadata.get_ddl(‘TABLESPACE’,a.name) from v$tablespace a where a.name=’ORDERAUDIT_PAR02′;

DBMS_METADATA.GET_DDL(‘TABLESPACE’,A.NAME)
——————————————————————————–

CREATE TABLESPACE “ORDERAUDIT_PAR02” DATAFILE ‘+ASM_ORADATA41/p01dwh/datafile/orderaudit_par02.386.635681395’ SIZE 30064771072
  AUTOEXTEND ON NEXT 2G MAXSIZE 31744M LOGGING ONLINE PERMANENT BLOCKSIZE 8192
  EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO
  ALTER DATABASE DATAFILE ‘+ASM_ORADATA41/p01dwh/datafile/orderaudit_par02.386.635681395’ RESIZE 42949672960

 

explain plan for select min(ORDER_ID), max(ORDER_ID) from MIDDLEOFFICE.ORDERS PARTITION (NOT_PENDING);
SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());

 

 Comment 

users waiting for locks

on June 17, 2008 at 7:44 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET ECHO off
REM NAME:   TFSLCKWT.SQL
REM USAGE:”@path/tfslckwt”
REM ————————————————————————
REM REQUIREMENTS:
REM    SELECT on V$SESSION, V$LOCK
REM ————————————————————————
REM PURPOSE:
REM    Reports users waiting for locks.
REM ————————————————————————
REM EXAMPLE:
REM    USERNAME          SID TYPE HELD        REQ           ID1        ID2
REM    ————— —– —- ———– ———– ——– ——–
REM    SYSTEM             12 TX   Exclusive   None          131087     2328
REM    SCOTT               7 TX   None        Exclusive     131087     2328 
REM    SCOTT               8 TX   Exclusive   None          131099     2332
REM    SYSTEM             10 TX   None        Exclusive     131099     2332
REM    SYSTEM             12 TX   None        Exclusive     131099     2332
REM 
REM ————————————————————————
REM Main text of script follows:
 
column username format  A15
column sid      format  9990    heading SID
column type     format  A4
column lmode    format  990     heading ‘HELD’
column request  format  990     heading ‘REQ’
column id1      format  9999990
column id2 format  9999990
break on id1 skip 1 dup
spool tfslckwt.lst
SELECT sn.username, m.sid, m.type,
        DECODE(m.lmode, 0, ‘None’,
                        1, ‘Null’,
                        2, ‘Row Share’,
                        3, ‘Row Excl.’,
                        4, ‘Share’,
                        5, ‘S/Row Excl.’,
                        6, ‘Exclusive’,
                lmode, ltrim(to_char(lmode,’990′))) lmode,
        DECODE(m.request,0, ‘None’,
                         1, ‘Null’,
                         2, ‘Row Share’,
                         3, ‘Row Excl.’,
                         4, ‘Share’,
                         5, ‘S/Row Excl.’,
                         6, ‘Exclusive’,
                         request, ltrim(to_char(m.request,
                ‘990’))) request, m.id1, m.id2
FROM v$session sn, v$lock m
WHERE (sn.sid = m.sid AND m.request != 0)
        OR (sn.sid = m.sid
                AND m.request = 0 AND lmode != 4
                AND (id1, id2) IN (SELECT s.id1, s.id2
     FROM v$lock s
                        WHERE request != 0
              AND s.id1 = m.id1
                                AND s.id2 = m.id2)
                )
ORDER BY id1, id2, m.request;
spool off
clear breaks

 Comment 

list asm file creation dates

on June 17, 2008 at 6:25 am
Posted In: Oracle odds and ends (Cat)

From ASM instance.

SQL> select to_char(f.creation_date,’dd-mon-yyyy’), a.name, a.group_number, a.file_number
 from v$asm_file f, v$asm_alias a
 where a.name like ‘%AUX%’
 and    a.group_number = f.group_number 
 and    a.file_number = f.file_number;

date             name                            grp no  file no
======== ===============  ====  ====
09-aug-2007  SYSAUX.303.630175843    1       303
10-aug-2007  SYSAUX.307.630234687    1       307
09-aug-2007  SYSAUX.257.630159243    2       257
09-aug-2007  SYSAUX.308.630174583    6        30

 Comment 

how to rename asm files

on June 17, 2008 at 6:24 am
Posted In: Oracle odds and ends (Cat)

RMAN>
startup mount;
copy datafile 5 to ‘+DATA’;
list copy;
switch datafile 5 to copy;

RMAN> run {
set newname for tempfile 1 to ‘+DATA’;
set newname for tempfile 2 to ‘+DATA’;
…
switch tempfile all;
}

SQL> alter database datafile ‘+ASM_ORADATA31/pc01bko/xdb_01.dbf’ offline;

RMAN> copy datafile ‘+ASM_ORADATA31/pc01bko/xdb_01.dbf’ to ‘+ASM_ORADATA31/p01bko/xdb_01.dbf’;

RMAN> run {
RMAN> set newname for datafile  ‘+ASM_ORADATA31/pc01bko/xdb_01.dbf’ to ‘+ASM_ORADATA31/p01bko/xdb_01.dbf’;
RMAN> switch datafile all;
RMAN> }

RMAN> recover datafile  ‘+ASM_ORADATA31/p01bko/xdb_01.dbf’;

SQL> alter database  datafile  ‘+ASM_ORADATA31/p01bko/xdb_01.dbf’ online;

From ASM instance
SQL> alter diskgroup asm_oradata31 drop file ‘+ASM_ORADATA31/pc01bko/xdb_01.dbf’ ;

 

 Comment 

show all running sql text

on June 17, 2008 at 6:23 am
Posted In: Oracle DB and SQL performance analysis (Cat)

set pagesize 66
col c1 for a9
col c1 heading “OS User”
col c2 for a9
col c2 heading “Oracle User”
col b1 for a9
col b1 heading “Unix PID”
col b2 for 9999 justify left
col b2 heading “SID”
col b3 for 99999 justify left
col b3 heading “SERIAL#”
col sql_text for a35
break on b1 nodup on c1 nodup on c2 nodup on b2 nodup on b3 skip 3

select c.spid b1, b.osuser c1, b.username c2, b.sid b2, b.serial# b3,
a.sql_text
  from v$sqltext a, v$session b, v$process c
   where a.address    = b.sql_address
–   and b.status     = ‘ACTIVE’ /* YOU CAN CHOOSE THIS OPTION ONLY TO SEE ONLY ACTIVE TRANSACTIONS ON THAT MOMENT */
   and b.paddr      = c.addr
   and a.hash_value = b.sql_hash_value
 order by c.spid,a.hash_value,a.piece;
         

 

 Comment 

show uga and pga memory usage

on June 17, 2008 at 6:22 am
Posted In: Oracle DB and SQL performance analysis (Cat)

SET LINESIZE 145
SET PAGESIZE 9999

COLUMN sid                     FORMAT 99999          HEADING ‘SID’
COLUMN oracle_username         FORMAT a12            HEADING ‘Oracle User’     JUSTIFY right
COLUMN os_username             FORMAT a9             HEADING ‘O/S User’        JUSTIFY right
COLUMN session_program         FORMAT a35            HEADING ‘Session Program’ TRUNC
COLUMN session_machine         FORMAT a8             HEADING ‘Machine’         JUSTIFY right TRUNC
COLUMN session_pga_memory      FORMAT 9,999,999,999  HEADING ‘PGA Memory’
COLUMN session_pga_memory_max  FORMAT 9,999,999,999  HEADING ‘PGA Memory Max’
COLUMN session_uga_memory      FORMAT 9,999,999,999  HEADING ‘UGA Memory’
COLUMN session_uga_memory_max  FORMAT 9,999,999,999  HEADING ‘UGA Memory MAX’

SELECT
    s.sid                sid
  , lpad(s.username,12)  oracle_username
  , lpad(s.osuser,9)     os_username
  , s.program            session_program
  , lpad(s.machine,8)    session_machine
  , (select ss.value from v$sesstat ss, v$statname sn
     where ss.sid = s.sid and
           sn.statistic# = ss.statistic# and
           sn.name = ‘session pga memory’)        session_pga_memory
  , (select ss.value from v$sesstat ss, v$statname sn
     where ss.sid = s.sid and
           sn.statistic# = ss.statistic# and
           sn.name = ‘session pga memory max’)    session_pga_memory_max
  , (select ss.value from v$sesstat ss, v$statname sn
     where ss.sid = s.sid and
           sn.statistic# = ss.statistic# and
           sn.name = ‘session uga memory’)        session_uga_memory
  , (select ss.value from v$sesstat ss, v$statname sn
     where ss.sid = s.sid and
           sn.statistic# = ss.statistic# and
           sn.name = ‘session uga memory max’)    session_uga_memory_max
FROM
    v$session  s
ORDER BY session_pga_memory DESC
/

 Comment 

show user locks

on June 17, 2008 at 6:21 am
Posted In: Oracle DB and SQL performance analysis (Cat)

REM    SELECT ON V$LOCK, V$SESSION
EM PURPOSE:
REM Shows User Lock Information
REM EXAMPLE:
REM    Sess                    Op Sys                   OBJ NAME or
REM     ID    USERNAME User ID  TERMINAL TRANS_ID          TY Lock Mode   Req Mode
REM    —-    ——————- ———–  ————— ———————-
REM       7   SCOTT        usupport  ttyr5        TA           TM Row Excl
REM       7   SCOTT        usupport  ttyr5        Trans-196623 TX Exclusive
REM       8   SCOTT        usupport  ttyr1        TABLE_CONFIG TM Row Excl
REM       8   SCOTT        usupport  ttyr1        Trans-131099 TX Exclusive
REM      10   SYSTEM       usupport  ttyqe        TABLE_CONFIG TM Row Excl
REM      10   SYSTEM       usupport  ttyqe        Trans-131099 TX –Waiting–     Exclusive
REM      11   SYS          usupport  ttyr8        GTEMP        TM Row Excl
REM      11   SYS          usupport  ttyr8        Trans-196622 TX Exclusive
REM      12   SYSTEM       usupport  ttyr6        INDEX_BLOCKS TM Row Excl
REM      12   SYSTEM       usupport  ttyr6        Trans-131080 TX Exclusive
REM
REM ————————————————————————
REM DISCLAIMER:
REM    This script is provided for educational purposes only. It is NOT
REM    supported by Oracle World Wide Technical Support.
REM    The script has been tested and appears to work as intended.
REM    You should always run new scripts on a test instance initially.
REM ————————————————————————
REM Main text of script follows:
set echo off
set pagesize 60
Column SID         FORMAT 999 heading “Sess|ID “
COLUMN OBJECT_NAME FORMAT A17 heading “OBJ NAME or|TRANS_ID” Trunc
COLUMN OSUSER      FORMAT A10 heading “Op Sys|User ID”
COLUMN USERNAME    FORMAT A8
COLUMN TERMINAL    FORMAT A8  trunc
select B.SID,
       C.USERNAME,
       C.OSUSER,
       C.TERMINAL,
       DECODE(B.ID2, 0, A.OBJECT_NAME, ‘Trans-‘||to_char(B.ID1)) OBJECT_NAME,
       B.TYPE,
       DECODE(B.LMODE,0,’–Waiting–‘,
                      1,’Null’,
                      2,’Row Share’,
                      3,’Row Excl’,
                      4,’Share’,
                      5,’Sha Row Exc’,
                      6,’Exclusive’,
                        ‘Other’) “Lock Mode”,
       DECODE(B.REQUEST,0,’ ‘,
                      1,’Null’,
                      2,’Row Share’,
                      3,’Row Excl’,
                      4,’Share’,
                      5,’Sha Row Exc’,
                      6,’Exclusive’,
                     ‘Other’) “Req Mode”
from  DBA_OBJECTS A, V$LOCK B, V$SESSION C
where A.OBJECT_ID(+) = B.ID1
and   B.SID = C.SID
and   C.USERNAME is not null
order by B.SID, B.ID2;

 

 Comment 

temp tablespace usage

on June 17, 2008 at 6:19 am
Posted In: Oracle DB Objects (tables, sql etc) (Cat)

SELECT

  s.sid “SID”,   s.username “User”,   s.program “Program”,   u.tablespace “Tablespace”,
  u.contents “Contents”,   u.extents “Extents”,   u.blocks*8/1024 “Used Space in MB”,   q.sql_text “SQL TEXT”,
  a.object “Object”,   k.bytes/1024/1024 “Temp File Size”
FROM

v$session s, v$sort_usage u, v$access a, dba_temp_files k, v$sql q
WHERE

s.saddr=u.session_addr
and   s.sql_address=q.address
and   s.sid=a.sid
and   u.tablespace=k.tablespace_name
order by u.blocks;

 

 Comment 

using xdb to ftp asm files (10g)

on June 17, 2008 at 6:13 am
Posted In: Oracle odds and ends (Cat)

Some Commands:

SQL>exec dbms_xdb.sethttpport(8080);

SQL>alter system register;

FTP:

ON node_1
SQL> exec xdb.dbms_xdb.setftpport(2100);

ON node_2
SQL> exec xdb.dbms_xdb.setftpport(2101);

ftp commands
============

open node_1 2100
cd /sys/asm/asm_oradata11/dbname

proxy open node_2 2101
proxy cd /sys/asm/asm_oradata11/dbname

bin
proxy bin

 

proxy get cfd_pc01cfd_02inptsk_1_628946836 cfd_pc01cfd_02inptsk_1_628946836
proxy get cfd_pc01cfd_04inptsl_1_628946837 cfd_pc01cfd_04inptsl_1_628946837
proxy get cfd_pc01cfd_05inqdnr_1_628963067 cfd_pc01cfd_05inqdnr_1_628963067
proxy get cfd_pc01cfd_06inqdnr_1_628963067 cfd_pc01cfd_06inqdnr_1_628963067
proxy get cfd_pc01cfd_09inqheb_1_628966859 cfd_pc01cfd_09inqheb_1_628966859
proxy get cfd_pc01cfd_0ainqhed_1_628966861 cfd_pc01cfd_0ainqhed_1_628966861
proxy get cfd_pc01cfd_0binqhjb_1_628967019 cfd_pc01cfd_0binqhjb_1_628967019
proxy get cfd_pc01cfd_0cinqhjb_1_628967019 cfd_pc01cfd_0cinqhjb_1_628967019

proxy get cfd_pc01cfd_07inqdo0_1_628963072 cfd_pc01cfd_07inqdo0_1_628963072
proxy get cfd_pc01cfd_08inqdo1_1_628963073 cfd_pc01cfd_08inqdo1_1_628963073

proxy close node_2 2101
close node_1 2100

 Comment 

Only one edit window! How do I create “Read more…”?

on October 6, 2006 at 7:29 pm
Posted In: Uncategorized

This is now implemented by inserting a Read more… tag (the button is located below the editor area) a dotted line appears in the edited text showing the split location for the Read more…. A new Plugin takes care of the rest.

It is worth mentioning that this does not have a negative effect on migrated data from older sites. The new implementation is fully backward compatible.

 Comment 
  • Page 5 of 5
  • «
  • 1
  • 2
  • 3
  • 4
  • 5

©2006-2017 isitdevops.com/databases | Powered by WordPress with ComicPress | Subscribe: RSS | Back to Top ↑