Script Sharepool
Script Sharepool
7.3.3.5, 8.0.4.1, 8.1.5, 8.1.7, 9.0.1, 10.2.0.3, 11.1.0.6 REM PLATFORM: non-specific REM REQUIRES: v$db_object_cache, v$sqlarea, v$sesstat, v$statname, REM v$sgastat, v$parameter REM REM This is a part of the Knowledge Xpert for Oracle Administration library. REM Copyright (C) 2008 Quest Software REM All rights reserved. REM REM******************** Knowledge Xpert for Oracle Administration ************** ****** REM REM NOTES: Based on current database usage. This should be REM run during peak operation, after all stored REM objects i.e. packages, views have been loaded. REM REM 08/02/08 Robert Freeman - Modified to use v$sgastat instead v$parameter for REM shared pool size. REM***************************************************************************** ****** REM REM If running Shared Server uncomment the mts calculation and output commands. SET serveroutput on; DECLARE object_mem NUMBER; shared_sql NUMBER; cursor_mem NUMBER; mts_mem NUMBER; used_pool_size NUMBER; free_mem NUMBER; pool_size VARCHAR2 (512); BEGIN -- Stored objects (packages, views) SELECT SUM (sharable_mem) INTO object_mem FROM v$db_object_cache;
-- Shared SQL -- need to have additional memory if dynamic SQL used SELECT SUM (sharable_mem) INTO shared_sql FROM v$sqlarea; -- User Cursor Usage -- run this during peak usage. -- assumes 250 bytes per open cursor, for each concurrent user. SELECT SUM (250 * users_opening) INTO cursor_mem FROM v$sqlarea; --------For a test system -- get usage for one user, multiply by # users select (250 * value) bytes_per_user from v$sesstat s, v$statname n where s.statistic# = n.statistic# and n.name = 'opened cursors current' and s.sid = 25; -- where 25 is the sid of the process MTS memory needed to hold session information for shared server users This query computes a total for all currently logged on users (run
-- multiply by # users. SELECT SUM (VALUE) INTO mts_mem FROM v$sesstat s, v$statname n WHERE s.statistic# = n.statistic# AND n.NAME = 'session uga memory max'; -- Free (unused) memory in the SGA: gives an indication of how much memory -- is being wasted out of the total allocated. SELECT BYTES INTO free_mem FROM v$sgastat WHERE NAME = 'free memory' AND pool = 'shared pool'; -- For non-MTS add up object, shared sql, cursors and 20% overhead. used_pool_size := ROUND (1.2 * (object_mem + shared_sql + cursor_mem)); -- For MTS mts contribution needs to be included (comment out previous line) -- used_pool_size := round(1.2*(object_mem+shared_sql+cursor_mem+mts_mem)); SELECT SUM (BYTES) INTO pool_size FROM v$sgastat WHERE pool = 'shared pool'; -- Display results DBMS_OUTPUT.put_line ('Shared Pool Memory Utilization Report'); DBMS_OUTPUT.put_line ('Obj mem: ' TO_CHAR (object_mem) ' bytes'); DBMS_OUTPUT.put_line ('Shared sql: ' TO_CHAR (shared_sql) ' bytes'); DBMS_OUTPUT.put_line ('Cursors: ' TO_CHAR (cursor_mem) ' bytes'); -- dbms_output.put_line ('MTS session: ' to_char (mts_mem) ' bytes'); DBMS_OUTPUT.put_line ( 'Free memory: ' TO_CHAR (free_mem) ' bytes ' '(' TO_CHAR (ROUND (free_mem / 1024 / 1024, 2)) 'MB)' ); DBMS_OUTPUT.put_line ( 'Shared pool utilization (total): ' TO_CHAR (used_pool_size) ' bytes ' '(' TO_CHAR (ROUND (used_pool_size / 1024 / 1024, 2)) 'MB)' ); DBMS_OUTPUT.put_line ( 'Shared pool allocation (actual): ' pool_size ' bytes ' '(' TO_CHAR (ROUND (pool_size / 1024 / 1024, 2)) 'MB)' ); DBMS_OUTPUT.put_line ( 'Percentage Utilized: ' TO_CHAR (ROUND (used_pool_size / pool_size * 100)) ); END; / output ==========
Shared Pool Memory Utilization Report Obj mem: 64949920 bytes Shared sql: 21737236 bytes Cursors: 14250 bytes Free memory: 54037748 bytes (51.53MB) Shared pool utilization (total): 104041687 bytes (99.22MB) Shared pool allocation (actual): 180359768 bytes (172MB) Percentage Utilized: 58
REM LOCATION: Database Tuning\Shared Pool Reports REM FUNCTION: Generate a library cache report REM TESTED ON: 7.3.3.5, 8.0.4.1, 8.1.5, 8.1.7, 9.0.1, 10.2.0.3, 11.1.0.6 REM PLATFORM: non-specific REM REQUIRES: v$librarycache REM REM This is a part of the Knowledge Xpert for Oracle Administration library. REM Copyright (C) 2008 Quest Software REM All rights reserved. REM REM******************** Knowledge Xpert for Oracle Administration ************** ****** COLUMN namespace heading "Library Object" COLUMN gets format 999999 heading " Gets" COLUMN gethitratio format 999.99 heading " Get Hit%" COLUMN pins format 999999 heading " Pins" COLUMN pinhitratio format 999.99 heading " Pin Hit%" COLUMN reloads format 999999 heading " Reloads" COLUMN invalidations format 999999 heading " Invalidations" COLUMN db format a10 SET pages 58 lines 80 TTITLE left _date center 'Data Dictionary Library Cache Statistics' skip 2 SELECT namespace, gets, gethitratio * 100 gethitratio, pins, pinhitratio * 100 pinhitratio, reloads, invalidations FROM v$librarycache / SET pages 22 lines 80 TTITLE off UNDEF output
Library Object Gets Get Hit% Pins Pin Hit% Reloads Invalidations --------------- ------- --------- ------- --------- -------- -------------SQL AREA 26375 98.95 61661 99.21 19 13 TABLE/PROCEDURE 1401 86.01 2106 83.81 2 0 BODY 12 50.00 8 25.00 0 0 TRIGGER 0 100.00 0 100.00 0 0 INDEX 29 .00 29 .00 0 0 CLUSTER 421 98.57 377 98.14 0 0 OBJECT 0 100.00 0 100.00 0 0 PIPE 0 100.00 0 100.00 0 0
8 rows selected. REM LOCATION: Database Tuning\Shared Pool Reports REM FUNCTION: Generate report to show Data Dictionary cache condition REM TESTED ON: 7.3.3.5, 8.0.4.1, 8.1.5, 8.1.7, 9.0.1, 10.2.0.3, 11.1.0.6 REM PLATFORM: non-specific REM REQUIRES: v$rowcache REM REM This is a part of the Knowledge Xpert for Oracle Administration library. REM Copyright (C) 2008 Quest Software REM All rights reserved. REM REM******************** Knowledge Xpert for Oracle Administration ************** ****** REM REM SET FLUSH OFF REM SET TERM OFF SET PAGESIZE 59 SET LINESIZE 79 echo off COLUMN parameter FORMAT A20 COLUMN type FORMAT a10 COLUMN percent FORMAT 999.99 HEADING "%"; TTITLE left _date center 'Data Dictionary Cache Statistics' skip 2 SELECT parameter, TYPE, gets, getmisses, (getmisses / gets * 100) PERCENT, COUNT, usage FROM v$rowcache WHERE gets > 100 AND getmisses > 0 ORDER BY parameter; 18-JUL-08 PARAMETER -------------------dc_free_extents dc_object_ids dc_objects dc_rollback_segments dc_segments dc_tablespaces dc_used_extents dc_user_grants dc_usernames dc_users 10 rows selected. REM REM REM REM REM REM LOCATION: FUNCTION: TESTED ON: PLATFORM: REQUIRES: Database Tuning\Shared Pool Reports Estimate impacts of changing shared pool sizing 10.2.0.3 and 11.1.0.6 non-specific v$shared_pool_advice statistics_level >= TYPICAL Data Dictionary Cache Statistics TYPE GETS GETMISSES % COUNT USAGE ---------- --------- --------- ------- --------- --------PARENT 3490 165 4.73 70 63 PARENT 850 80 9.41 122 121 PARENT 1162 156 13.43 202 198 PARENT 4041 26 .64 33 27 PARENT 246 88 35.77 84 72 PARENT 246 2 .81 11 2 PARENT 233 90 38.63 23 12 SUBORDINAT 207 18 8.70 37 18 E PARENT PARENT 436 430 4 22 .92 5.12 21 26 4 22
REM REM This is a part of the Knowledge Xpert for Oracle Administration library. REM Copyright (C) 2008 Quest Software REM All rights reserved. REM REM******************** Knowledge Xpert for Oracle Administration ************** ****** REM REM This script will use the Oracle shared pool adviser to review your current REM shared pool utilization and give you an estimate of the impact of adding or REM removing memory from the shared pool. REM REM If you are using automatic memory management this report may indicate that you REM should increase the size of SGA_TARGET or MEMORY_TARGET depending on the ve rsion REM of Oracle you are running REM REM If the estimated time saved factor is high (say 1.2 or greater) then it may REM make sense to add memory to the shared pool/SGA. REM REM***************************************************************************** ****** REM COLUMN shared_pool_size_for_estimate format 9,999,999 heading "Shared Pool Size" COLUMN shared_pool_size_factor format 99.99 heading "Factor Greater or Less Than Current Size" COLUMN estd_lc_time_saved format 9,999,999,999 heading "Estimated Database Time If Set" COLUMN estd_lc_time_saved_factor format 99.99 heading "Estimated Database Time S aved Factor" TTITLE left _date center 'Shared Pool Sizing Advice Report' skip 2 SELECT shared_pool_size_for_estimate, shared_pool_size_factor, estd_lc_time_saved, estd_lc_time_saved_factor FROM v$shared_pool_advice ORDER BY shared_pool_size_for_estimate; 02-AUG-08 rt Factor Estimated Greater or Estimated Database Less Than Database Time Current Time Saved Size If Set Factor ---------- -------------- --------.53 3,281 1.00 .65 3,281 1.00 .77 3,294 1.00 .88 3,294 1.00 1.00 3,294 1.00 1.12 3,294 1.00 1.23 3,294 1.00 1.35 3,294 1.00 1.47 3,294 1.00 1.58 3,294 1.00 1.70 3,294 1.00 Shared Pool Sizing Advice Repo
Shared Pool Size ---------92 112 132 152 172 192 212 232 252 272 292
/* Shared pool usage */ select 100-round(a.bytes/b.sm*100,2) pctused from (select bytes from v$sgastat where name='free memory' AND pool='shared pool') a, (select sum(bytes) sm from v$sgastat where pool = 'shared pool') b SQL> CONN sys/password AS SYSDBA Connected. SQL> ALTER SYSTEM FLUSH SHARED_POOL; System altered. SQL> CONN sys/password AS SYSDBA Connected. SQL> DECLARE 2 l_dummy dual.dummy%TYPE; 3 BEGIN 4 FOR i IN 1 .. 10 LOOP 5 BEGIN 6 EXECUTE IMMEDIATE 'SELECT dummy FROM dual WHERE dummy = ''' R(i) '''' 7 INTO l_dummy; 8 EXCEPTION 9 WHEN NO_DATA_FOUND THEN 10 NULL; 11 END; 12 END LOOP; 13 END; 14 / PL/SQL procedure successfully completed. SQL> 2 3 4 SELECT FROM WHERE AND sn.name, ms.value v$mystat ms, v$statname sn ms.statistic# = sn.statistic# sn.name = 'parse time cpu';
TO_CHA
NAME VALUE ---------------------------------------------------------------- ---------parse time cpu 63 1 row selected. SQL> SQL> 2 3 4 5 6 7 COLUMN sql_text FORMAT SELECT sql_text, executions FROM v$sql WHERE INSTR(sql_text, AND INSTR(sql_text, AND INSTR(sql_text, ORDER BY sql_text; A60
SQL_TEXT EXECUTIONS ------------------------------------------------------------ ---------SELECT dummy FROM dual WHERE dummy = '1' 1 SELECT dummy FROM dual WHERE dummy = '10' 1
= = = = = = = =
1 1 1 1 1 1 1 1
SQL> CONN sys/password AS SYSDBA Connected. SQL> ALTER SYSTEM FLUSH SHARED_POOL; System altered. SQL> CONN sys/password AS SYSDBA Connected. SQL> SQL> DECLARE 2 l_dummy dual.dummy%TYPE; 3 BEGIN 4 FOR i IN 1 .. 10 LOOP 5 BEGIN 6 EXECUTE IMMEDIATE 'SELECT dummy FROM dual WHERE dummy = TO_CHAR(:dumm y)' 7 INTO l_dummy USING i; 8 EXCEPTION 9 WHEN NO_DATA_FOUND THEN 10 NULL; 11 END; 12 END LOOP; 13 END; 14 / PL/SQL procedure successfully completed. SQL> SQL> 2 3 4 SELECT FROM WHERE AND sn.name, ms.value v$mystat ms, v$statname sn ms.statistic# = sn.statistic# sn.name = 'parse time cpu';
NAME VALUE ---------------------------------------------------------------- ---------parse time cpu 40 1 row selected. SQL> SQL> SQL> 2 3 4 COLUMN sql_text FORMAT A60 SELECT sql_text, executions FROM v$sql WHERE INSTR(sql_text, 'SELECT dummy FROM dual WHERE dummy') > 0
5 AND INSTR(sql_text, 'sql_text') = 0 6 AND INSTR(sql_text, 'DECLARE') = 0 7 ORDER BY sql_text; SQL_TEXT EXECUTIONS ------------------------------------------------------------ ---------SELECT dummy FROM dual WHERE dummy = TO_CHAR(:dummy) 10 1 row selected. SQL>