home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / CATPARR.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  14.9 KB  |  381 lines

  1. rem 
  2. rem $Header: catparr.sql 7020100.1 94/09/23 22:14:25 cli Generic<base> $ 
  3. rem 
  4. Rem Copyright (c) 1990 by Oracle Corporation
  5. Rem NAME
  6. Rem    CATPARR.SQL
  7. Rem  FUNCTION
  8. Rem    Parallel-Server specific views for performance queries, etc.
  9. Rem  NOTES
  10. Rem     This script must be run while connected as SYS or INTERNAL.
  11. Rem  MODIFIED
  12. Rem     thayes     07/08/94 -  Extend vbh view
  13. Rem     svenkate   06/17/94 -  bug 172282 : amendments
  14. Rem     svenkate   06/08/94 -  172288 : add file_lock, file_PING
  15. Rem     wmaimone   05/06/94 -  #184921 run as sys/internal
  16. Rem     jloaiza    03/17/94 -  add false ping view, v$lock_element, etc
  17. Rem     hrizvi     02/09/93 -  apply changes to x$bh 
  18. Rem     jloaiza    11/09/92 -  get rid of quted column 
  19. Rem     jklein     11/04/92 -  fix view definitions 
  20. Rem     jklein     10/28/92 -  merge forward changes from v6 
  21. Rem    Porter    12/03/90 - Added to control system, renamed to psviews.sql
  22. Rem    Laursen   10/01/90 - Creation
  23. Rem
  24. remark  This table maps extents to database objects.  The v$ping and v$cache
  25. remark  views depend on it.  This table must be dropped and recreated to
  26. remark  include any new extents that are added after the last time it was
  27. remark  created.
  28. remark
  29.  
  30. create or replace view ext_to_obj_view as
  31.   select uet$.file#   file# 
  32.        , uet$.block#  lowb
  33.        , uet$.block# + uet$.length - 1 highb
  34.        , obj$.name    name 
  35.        , 'TABLE'      kind
  36.        , owner#
  37.   from tab$, uet$, obj$
  38.   where tab$.clu# is null
  39.     and tab$.file# = uet$.segfile#
  40.     and tab$.block# = uet$.segblock#
  41.     and tab$.obj# = obj$.obj#
  42. union all
  43.   select distinct
  44.          uet$.file# file# 
  45.        , uet$.block# lowb
  46.        , uet$.block# + uet$.length - 1 highb
  47.        , obj$.name name 
  48.        , 'CLUSTER' kind
  49.        , owner#
  50.   from tab$, uet$, obj$
  51.   where tab$.clu# is not null
  52.     and tab$.file# = uet$.segfile#
  53.     and tab$.block# = uet$.segblock#
  54.     and tab$.clu# = obj$.obj#
  55. union all
  56.   select uet$.file# file# 
  57.        , uet$.block# lowb
  58.        , uet$.block# + uet$.length - 1 highb 
  59.        , obj$.name name 
  60.        , 'INDEX' kind
  61.        , owner#
  62.   from ind$, uet$, obj$
  63.   where ind$.file# = uet$.segfile#
  64.     and ind$.block# = uet$.segblock#
  65.     and ind$.obj# = obj$.obj#
  66. union all
  67.   select uet$.file# file#
  68.        , uet$.block# lowb
  69.        , uet$.block# + uet$.length - 1 highb
  70.        , undo$.name name
  71.        , 'UNDO' kind
  72.        , user# owner#
  73.   from undo$, uet$
  74.   where undo$.file# = uet$.segfile#
  75.     and undo$.block# = uet$.segblock#
  76. union all
  77.   select uet$.file# file#
  78.        , uet$.block# lowb
  79.        , uet$.block# + uet$.length - 1 highb
  80.        , 'TEMP SEGMENT' name
  81.        , 'TEMP SEGMENT' kind
  82.        , 1 owner#
  83.   from uet$, seg$
  84.   where seg$.file# = uet$.segfile#
  85.    and  seg$.block# = uet$.block#
  86.    and  seg$.type = 3
  87. union all
  88.   select file#
  89.        , block#
  90.        , length + block#
  91.        , 'FREE EXTENT'
  92.        , 'FREE EXTENT'
  93.        , 1  owner#
  94.   from fet$;
  95.  
  96.  
  97. remark  Create a table of extents since selecting from the view is too slow.
  98.  
  99. drop table ext_to_obj;
  100. create table ext_to_obj as select * from ext_to_obj_view;
  101.  
  102.  
  103. remark
  104. remark  v$bh gives the status and number of times pinged for every buffer in
  105. remark  the buffer cache.  It gives the file number and block number for each
  106. remark  buffer, but unlike the v$cache and v$ping views, it does not translate
  107. remark  that to a database object.
  108. remark
  109. remark  The x_to_null column counts the number of times the buffer has gone
  110. remark  from exclusive mode to null mode on this instance.  This
  111. remark  happens when the block is pinged out of the instance's cache. A block 
  112. remark  will be pinged out of an instance's cache, when another instance 
  113. remark  requests the lock that protects the block in exclusive mode.
  114. remark  Note that a block can go from being exclusive to being shared in this
  115. remark  instance without incrementing the count, however, if this instance
  116. remark  ever takes the block back to exclusive mode, then the other instance's
  117. remark  ping count will be incremented.  Therefore to get a true picture
  118. remark  of the pings you need to look at v$bh on all instances.
  119. remark
  120. remark  The 'lock_element_addr' column contains the address of the lock element
  121. remark  that contains the PCM lock that is locking this buffer.  If two buffers
  122. remark  have the same lock_element_addr, then they are being protected
  123. remark  by the same PCM lock. Anytime two buffers are covered by the same PCM 
  124. remark  lock, you can have false collisions between the buffers.
  125. remark
  126.  
  127. create or replace view v$bh as          /* view on buffer headers */
  128.   select DBAFIL                    file#,
  129.          DBABLK                    block#,
  130.          decode(state, 0, 'FREE',       /* not currently is use */
  131.                        1, 'XCUR',       /* held exclusive by this instance */
  132.                        2, 'SCUR',       /* held shared by this instance */
  133.                        3, 'CR',         /* only valid for consistent read */
  134.                        4, 'READ',       /* is being read from disk */
  135.                        5, 'MREC',       /* in media recovery mode */
  136.                        6, 'IREC')       /* in instance (crash) recovery mode */
  137.              status,
  138.          x_to_null                 xnc, /* count of ping outs */
  139.          le_addr                   lock_element_addr,
  140.      decode(bitand(flag,1), 0, 'N', 'Y')
  141.         dirty,            /* Dirty bit */
  142.      decode(bitand(flag,16), 0, 'N', 'Y')
  143.         temp,            /* temporary bit */
  144.      decode(bitand(flag,1536), 0, 'N', 'Y')
  145.         ping,            /* ping (to shared or null) bit */
  146.      decode(bitand(flag,16384), 0, 'N', 'Y')
  147.         stale,            /* stale bit */
  148.      decode(bitand(flag,65536), 0, 'N', 'Y')
  149.         direct,            /* direct access bit */
  150.      decode(bitand(flag,1048576), 0, 'N', 'Y')
  151.         new            /* new bit */
  152.          from x$bh; 
  153.  
  154. grant select on v$bh to public;
  155. drop public synonym v$bh;
  156. create public synonym v$bh for v$bh;
  157.  
  158. remark
  159. remark  The v$ping view is like v$bh but it only shows the buffer that
  160. remark  have been pinged out of this instance's cache at least once.
  161. remark  v$ping also translates the file number and block number into the 
  162. remark  corresponding database object (using the ext_to_obj table).
  163. remark  For a descriptions of the columns, see the v$bh view.
  164.  
  165. create or replace view v$ping as
  166. select bh.file#,
  167.        bh.block#,
  168.        bh.status,
  169.        bh.xnc,
  170.        ext_to_obj.name,
  171.        ext_to_obj.kind,
  172.        ext_to_obj.owner#,
  173.        lock_element_addr
  174.        from v$bh bh, ext_to_obj 
  175.        where bh.xnc > 0                        and 
  176.              bh.block# >= ext_to_obj.lowb  (+) and
  177.              bh.block# <= ext_to_obj.highb (+) and
  178.              bh.file#  =  ext_to_obj.file# (+);
  179.  
  180.  
  181. grant select on v$ping to public;
  182. drop public synonym v$ping;
  183. create public synonym v$ping for v$ping;
  184.  
  185. remark
  186. remark  The v$cache view show all blocks in the cache.  It gives the file
  187. remark  number, the block number, and the number of times pinged (if any); it
  188. remark  also translates the file number and block number into the corresponding
  189. remark  database object (using the ext_to_obj table).  The difference between
  190. remark  this view and the v$ping view is that v$cache shows all buffers in the
  191. remark  cache, whether or not they have ever been pinged.
  192. remark
  193.  
  194. create or replace view v$cache as
  195. select bh.file#,
  196.        bh.block#,
  197.        bh.status,
  198.        bh.xnc,
  199.        ext_to_obj.name,
  200.        ext_to_obj.kind,
  201.        ext_to_obj.owner#,
  202.        lock_element_addr
  203.        from v$bh bh, ext_to_obj 
  204.        where 
  205.              bh.block# >=  ext_to_obj.lowb  (+) and
  206.              bh.block# <=  ext_to_obj.highb (+) and
  207.              bh.file#   =  ext_to_obj.file# (+) ;
  208.  
  209. grant select on v$cache to public;
  210. drop public synonym v$cache;
  211. create public synonym v$cache for v$cache;
  212.  
  213.  
  214. remark
  215. remark  There is one entry in v$lock_element for each PCM lock that is used
  216. remark  by the buffer cache (gc_db_locks).  v$lock_element describes the
  217. remark  status of each lock.  The name of the PCM lock that corresponds to
  218. remark  a lock element is  {'BL', indx, class}.  
  219. remark
  220.  
  221. create or replace view v$lock_element as
  222. select addr     lock_element_addr,  /* address of lock, join with v$bh */
  223.        indx,                        /* indx,class are used to identify a */
  224.        le_class class,              /*    lock to the OS lock manager */
  225.        le_mode  mode_held,          /* values are OS dependent, usually */
  226.                                     /*   5=exclusive, 3=share           */
  227.        le_blks  block_count,        /* number of blocks protected by lock */
  228.        le_rls   releasing,          /* non-zero if lock is being downgraded */
  229.        le_acq   acquiring,          /* non-zero if lock is being upgraded */
  230.        le_inv   invalid             /* non-zero if lock is invalid, a lock  */
  231.                                     /*   may become invalid after a crash */
  232.   from x$le;
  233.  
  234.  
  235. grant select on v$lock_element to public;
  236. drop public synonym v$lock_element;
  237. create public synonym v$lock_element for v$lock_element;
  238.  
  239.  
  240. remark
  241. remark  This view is like v$cache, but it also contains the indx and class of
  242. remark  the PCM lock that is protecting the buffer.  This view is useful for 
  243. remark  backmapping remark a PCM lock to a set of buffers.  The name of 
  244. remark  the PCM lock that remark  corresponds to a lock element 
  245. remark  is  {'BL', indx, class}.  This can be useful if the 
  246. remark  OS lock manager provides tools for monitoring the
  247. remark  PCM lock operations that are occuring.  First you identify the 
  248. remark  lock element in question by using the indx and class, then you
  249. remark  find the buffers that are covered by this lock by looking in v$bh
  250. remark  for buffers with the correct lock_element_addr.
  251.  
  252. create or replace view v$cache_lock as
  253. select file#, block#, status, xnc,
  254.        name, kind, owner#, c.lock_element_addr, indx, class
  255.   from v$cache c, v$lock_element l
  256.  where l.lock_element_addr = c.lock_element_addr;
  257.  
  258.  
  259. grant select on v$cache_lock to public;
  260. drop public synonym v$cache_lock;
  261. create public synonym v$cache_lock for v$cache_lock;
  262.  
  263.  
  264.  
  265. remark 
  266. remark  Find the locks that protect multiple buffers each of which has been
  267. remark  pinged out at least one hundred times.  It is very likely that those
  268. remark  buffers are experiencing false pings due to being mapped to the same
  269. remark  lock. 
  270. remark  
  271. remark  Note that a more correct version of this would select the buffers
  272. remark  from all the nodes since it is possible to experience false pinging
  273. remark  in which different nodes are accessing different buffers that happen
  274. remark  to map to the same lock.
  275. remark
  276.  
  277. create or replace view v$locks_with_collisions as
  278. select lock_element_addr
  279.   from v$bh
  280. where xnc > 100
  281. group by lock_element_addr
  282. having count(*) >= 2;
  283.  
  284.  
  285. remark  
  286. remark  This view shows all the buffers that look like they are experiencing
  287. remark  false pings.  It select the buffers that have been pinged more than
  288. remark  100 times that are protected by the same lock as another buffer that
  289. remark  has been pinged more than 100 times.   If you are experiencing false
  290. remark  pinging then you can change your gc_files_to_locks so that the buffers
  291. remark  experiencing false pinging are mapped to different locks.
  292. remark
  293.  
  294. create or replace view v$false_ping as
  295. select file#,
  296.        block#,
  297.        status,
  298.        xnc,
  299.        name,
  300.        kind,
  301.        owner#,
  302.        p.lock_element_addr
  303.     from v$ping p, v$locks_with_collisions c
  304.   where p.xnc > 100 
  305.    and  p.lock_element_addr = c.lock_element_addr;
  306.  
  307.  
  308. grant select on v$false_ping to public;
  309. drop public synonym v$false_ping;
  310. create public synonym v$false_ping for v$false_ping;
  311.  
  312.  
  313. remark
  314. remark  The v$lock_activity view shows the DLM lock operations the instance is
  315. remark  doing.  Each row corresponds to a type of lock operation.
  316. remark
  317.  
  318. create or replace view v$lock_activity as
  319. select decode(indx, 1, 'NULL', 2, 'NULL', 3, 'S',    4, 'S', 
  320.                     5, 'X',    6, 'X',    7, 'X',    8, 'SSX', 
  321.                     9, 'SSX', 10, 'SSX',     '???') from_val,
  322.        decode(indx, 1, 'S',    2, 'X',    3, 'NULL',  4, 'X', 
  323.                     5, 'NULL', 6, 'S',    7, 'SSX',   8, 'NULL', 
  324.                     9, 'S',   10, 'X',       '???') to_val,
  325.        decode(indx, 1, 'Lock buffers for read',
  326.                     2, 'Lock buffers for write',
  327.                     3, 'Make buffers CR (no write)',
  328.                     4, 'Upgrade read lock to write',
  329.                     5, 'Make buffers CR (write dirty buffers)',
  330.                     6, 'Downgrade write lock to read (write dirty buffers)',
  331.                     7, 'Write transaction table/undo blocks',
  332.                     8, 
  333.                'Transaction table/undo blocks (write dirty buffers)',
  334.                     9, 'Make transaction table/undo blocks available share',
  335.                     10,'Rearm transaction table write mechanism', 
  336.                     'should not happen') action_val,
  337.        conv counter
  338.        from x$le_stat where conv > 0;               
  339.  
  340. grant select on v$lock_activity to public;
  341. drop public synonym v$lock_activity;
  342. create public synonym v$lock_activity for v$lock_activity;
  343.  
  344. remark The view file_ping gives the number of blocks pinged per 
  345. remark datafile. This information in turn may be
  346. remark used to determine access patterns to existing
  347. remark datafiles and deciding new mappings from datafile
  348. remark blocks to PCM locks.
  349. remark The FREQUENCY column counts the number of times any buffer
  350. remark corresponding to a block in a file has gone from exclusive 
  351. remark mode to null mode on this instance.  This happens when 
  352. remark the block is pinged out of the instance's cache. A block 
  353. remark will be pinged out of an instance's cache, when another 
  354. remark instance requests the lock that protects the block 
  355. remark in exclusive mode. Note that a block can go from being 
  356. remark exclusive to being shared in this instance without 
  357. remark incrementing the count, however, if this instance
  358. remark ever accesses the block again in exclusive mode, then 
  359. remark the other instance's ping count will be incremented.  
  360.  
  361. drop view file_ping; 
  362. create view file_ping as 
  363. select file_id, file_name, TABLESPACE_NAME ts_name, KCFIOX2N frequency
  364.     from x$kcfio x, dba_data_files d 
  365.     where x.KCFIOFNO = d.FILE_ID; 
  366.  
  367. remark The view file_lock is an aid to understanding the mapping of
  368. remark locks to files as established by the GC_FILES_TO_LOCKS
  369. remark parameter. START_LK shows the first lock corresponding to this datafile.
  370. remark NLOCKS shows the number of locks allocated to this datafile while 
  371. remark BLOCKING    records the number of blocks each lock protects.
  372.  
  373. drop view file_lock; 
  374. create view file_lock as 
  375. select file_id, file_name, TABLESPACE_NAME ts_name, 
  376.     kclfhbas start_lk, kclfhsiz nlocks, kclfhgrp blocking 
  377.     from x$kclfh fh, x$kclfi fi, dba_data_files d 
  378.     where fh.indx = fi.kclfibuk and fi.indx = d.FILE_ID; 
  379.  
  380.  
  381.