Top Banner
/***********************************************************************/ /* Document : Oracle 8i,9i,10g queries, information, and tips */ /* Doc. Versie : 58 */ /* File : oracle9i10g.txt */ /* Date : 23-05-2008 */ /* Content : Just a series of handy DBA queries. */ /* Compiled by : Albert */ /***********************************************************************/ CONTENTS: 0. Common data dictionary queries for sessions, locks, perfoRMANce etc.. 1. DATA DICTIONARY QUERIES m.b.t. files, tablespaces, logs: 2. NOTES ON PERFORMANCE: 3. Data dictonary queries m.b.t perfoRMANce: 4. IMP and EXP, 10g IMPDB and EXPDB, and SQL*Loader Examples 5. Add, Move AND Size Datafiles,logfiles, create objects etc..: 6. Install Oracle 92 on Solaris: 7. install Oracle 9i on Linux: 8. Install Oracle 9.2.0.2 on OpenVMS: 9. Install Oracle 9.2.0.1 on AIX 9. Installation Oracle 8i - 9i: 10. CONSTRAINTS: 11. DBMS_JOB and scheduled Jobs: 12. Net8,9,10 / SQLNet: 13. Datadictionary queries Rollback segments: 14. Data dictionary queries m.b.t. security, permissions: 15. INIT.ORA parameters: 16. Snapshots: 17. Triggers: 19. BACKUP RECOVERY, TROUBLESHOOTING: 20. TRACING: 21. Overig: 22. DBA% and v$ views 23 TUNING: 24 RMAN: 25. UPGRADE AND MIGRATION 26. Some info on Rdb: 27. Some info on IFS 28. Some info on 9iAS rel. 2 29 - 35 9iAS configurations and troubleshooting 30. BLOBS 31. BLOCK CORRUPTION 32. iSQL*Plus and EM 10g 33. ADDM 34. ASM and 10g RAC 35. CDC and Streams 36. X$ Tables ================================================================================== ==========
977
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

/***********************************************************************/ /* Document : Oracle 8i,9i,10g queries, information, and tips */ /* Doc. Versie : 58 */ /* File : oracle9i10g.txt */ /* Date : 23-05-2008 */ /* Content : Just a series of handy DBA queries. */ /* Compiled by : Albert */ /***********************************************************************/

CONTENTS: 0. Common data dictionary queries for sessions, locks, perfoRMANce etc.. 1. DATA DICTIONARY QUERIES m.b.t. files, tablespaces, logs: 2. NOTES ON PERFORMANCE: 3. Data dictonary queries m.b.t perfoRMANce: 4. IMP and EXP, 10g IMPDB and EXPDB, and SQL*Loader Examples 5. Add, Move AND Size Datafiles,logfiles, create objects etc..: 6. Install Oracle 92 on Solaris: 7. install Oracle 9i on Linux: 8. Install Oracle 9.2.0.2 on OpenVMS: 9. Install Oracle 9.2.0.1 on AIX 9. Installation Oracle 8i - 9i: 10. CONSTRAINTS: 11. DBMS_JOB and scheduled Jobs: 12. Net8,9,10 / SQLNet: 13. Datadictionary queries Rollback segments: 14. Data dictionary queries m.b.t. security, permissions: 15. INIT.ORA parameters: 16. Snapshots: 17. Triggers: 19. BACKUP RECOVERY, TROUBLESHOOTING: 20. TRACING: 21. Overig: 22. DBA% and v$ views 23 TUNING: 24 RMAN: 25. UPGRADE AND MIGRATION 26. Some info on Rdb: 27. Some info on IFS 28. Some info on 9iAS rel. 2 29 - 35 9iAS configurations and troubleshooting 30. BLOBS 31. BLOCK CORRUPTION 32. iSQL*Plus and EM 10g 33. ADDM 34. ASM and 10g RAC 35. CDC and Streams 36. X$ Tables

================================================================================== ==========

0. QUICK INFO/VIEWS ON SESSIONS, LOCKS, AND UNDO/ROLLBACK INFORMATION IN A SINGLE INSTANCE: ================================================================================== =========

SINGLE INSTANCE QUERIES: ======================== -- ---------------------------- 0.1 QUICK VIEW ON SESSIONS: -- --------------------------SELECT substr(username, 1, 10), osuser, sql_address, to_char(logon_time, 'DD-MMYYYY;HH24:MI'), sid, serial#, command, substr(program, 1, 30), substr(machine, 1, 30), substr(terminal, 1, 30) FROM v$session; SELECT sql_text, rows_processed from v$sqlarea where address='' -- ------------------------- 0.2 QUICK VIEW ON LOCKS: (use the sys.obj$ to find ID1:) -- -----------------------First, lets take a look at some important dictionary views with respect to locks: SQL> desc v$lock; Name Null? ----------------------------- -------ADDR KADDR SID TYPE ID1 ID2 LMODE REQUEST CTIME BLOCK Type -------------------RAW(8) RAW(8) NUMBER VARCHAR2(2) NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER

This view stores all information relating to locks in the database. The interesting columns in this view are sid (identifying the session holding or aquiring the lock), type, and the lmode/request pair. Important possible values of type are TM (DML or Table Lock), TX (Transaction), MR (Media Recovery), ST (Disk Space Transaction). Exactly one of the lmode, request pair is either 0 or 1 while the other indicates the lock mode. If lmode is not 0 or 1, then the session has aquired the lock, while it waits to aquire the lock if request is other than 0 or 1. The possible values for lmode and request are: 1: 2: 3: 4: null, Row Share (SS), Row Exclusive (SX), Share (S),

5: Share Row Exclusive (SSX) and 6: Exclusive(X) If the lock type is TM, the column id1 is the object's id and the name of the object can then be queried like so: select name from sys.obj$ where obj# = id1 A lock type of JI indicates that a materialized view is being SQL> desc v$locked_object; Name Null? ----------------------------- -------XIDUSN XIDSLOT XIDSQN OBJECT_ID SESSION_ID ORACLE_USERNAME OS_USER_NAME PROCESS LOCKED_MODE SQL> desc dba_waiters; Name Null? ----------------------------- -------WAITING_SESSION HOLDING_SESSION LOCK_TYPE MODE_HELD MODE_REQUESTED LOCK_ID1 LOCK_ID2 SQL> desc v$transaction; Name Null? ----------------------------- -------ADDR XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK UBASQN UBAREC STATUS START_TIME START_SCNB START_SCNW START_UEXT START_UBAFIL START_UBABLK START_UBASQN START_UBAREC SES_ADDR FLAG SPACE

Type -------------------NUMBER NUMBER NUMBER NUMBER NUMBER VARCHAR2(30) VARCHAR2(30) VARCHAR2(12) NUMBER

Type -------------------NUMBER NUMBER VARCHAR2(26) VARCHAR2(40) VARCHAR2(40) NUMBER NUMBER

Type -------------------RAW(8) NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VARCHAR2(16) VARCHAR2(20) NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RAW(8) NUMBER VARCHAR2(3)

RECURSIVE NOUNDO PTX NAME PRV_XIDUSN PRV_XIDSLT PRV_XIDSQN PTX_XIDUSN PTX_XIDSLT PTX_XIDSQN DSCN-B DSCN-W USED_UBLK USED_UREC LOG_IO PHY_IO CR_GET CR_CHANGE START_DATE DSCN_BASE DSCN_WRAP START_SCN DEPENDENT_SCN XID PRV_XID PTX_XID

VARCHAR2(3) VARCHAR2(3) VARCHAR2(3) VARCHAR2(256) NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER DATE NUMBER NUMBER NUMBER NUMBER RAW(8) RAW(8) RAW(8)

Queries you can use in investigating locks: =========================================== SELECT XIDUSN,OBJECT_ID,SESSION_ID,ORACLE_USERNAME,OS_USER_NAME,PROCESS from v$locked_object; SELECT d.OBJECT_ID, substr(OBJECT_NAME,1,20), l.SESSION_ID, l.ORACLE_USERNAME, l.LOCKED_MODE from v$locked_object l, dba_objects d where d.OBJECT_ID=l.OBJECT_ID; SELECT ADDR, KADDR, SID, TYPE, ID1, ID2, LMODE, BLOCK from v$lock; SELECT a.sid, a.saddr, b.ses_addr, a.username, b.xidusn, b.used_urec, b.used_ublk FROM v$session a, v$transaction b WHERE a.saddr = b.ses_addr; SELECT s.sid, l.lmode, l.block, substr(s.username, 1, 10), substr(s.schemaname, 1, 10), substr(s.osuser, 1, 10), substr(s.program, 1, 30), s.command FROM v$session s, v$lock l WHERE s.sid=l.sid;

SELECT p.spid, s.sid, p.addr,s.paddr,substr(s.username, 1, 10), substr(s.schemaname, 1, 10), s.command,substr(s.osuser, 1, 10), substr(s.machine, 1, 10) FROM v$session s, v$process p WHERE s.paddr=p.addr SELECT sid, serial#, command,substr(username, 1, 10), osuser, sql_address,LOCKWAIT, to_char(logon_time, 'DD-MM-YYYY;HH24:MI'), substr(program, 1, 30) FROM v$session; SELECT sid, serial#, username, LOCKWAIT from v$session;

SELECT v.SID, v.BLOCK_GETS, v.BLOCK_CHANGES, w.USERNAME, w.OSUSER, w.TERMINAL FROM v$sess_io v, V$session w WHERE v.SID=w.SID ORDER BY v.SID; SELECT * from dba_waiters; SELECT waiting_session, holding_session, lock_type, mode_held FROM dba_waiters; SELECT p.spid s.sid p.addr, s.paddr, substr(s.username, 1, 10) substr(s.schemaname, 1, 10) s.command substr(s.osuser, 1, 10) substr(s.machine, 1, 25) FROM v$session s, v$process WHERE s.paddr=p.addr ORDER BY p.spid;

unix_spid, sid, username, schemaname, command, osuser, machine p

Usage of v$session_longops: =========================== SQL> desc v$session_longops; SID NUMBER Session identifier SERIAL# NUMBER Session serial number OPNAME VARCHAR2(64) Brief description of the operation TARGET VARCHAR2(64) The object on which the operation is carried out TARGET_DESC VARCHAR2(32) Description of the target SOFAR NUMBER The units of work done so far TOTALWORK NUMBER The total units of work UNITS VARCHAR2(32) The units of measurement START_TIME DATE The starting time of operation LAST_UPDATE_TIME DATE Time when statistics last updated

TIMESTAMP DATE Timestamp TIME_REMAINING NUMBER Estimate (in seconds) of time remaining for the operation to complete ELAPSED_SECONDS NUMBER The number of elapsed seconds from the start of operations CONTEXT NUMBER Context MESSAGE VARCHAR2(512) Statistics summary message USERNAME VARCHAR2(30) User ID of the user performing the operation SQL_ADDRESS RAW(4 | 8) Used with the value of the SQL_HASH_VALUE column to identify the SQL statement associated with the operation SQL_HASH_VALUE NUMBER Used with the value of the SQL_ADDRESS column to identify the SQL statement associated with the operation SQL_ID VARCHAR2(13) SQL identifier of the SQL statement associated with the operation QCSID NUMBER Session identifier of the parallel coordinator This view displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution, and more operations are added for every Oracle release. To monitor query execution progress, you must be using the cost-based optimizer and you must: Set the TIMED_STATISTICS or SQL_TRACE parameter to true Gather statistics for your objects with the ANALYZE statement or the DBMS_STATS package You can add information to this view about application-specific long-running operations by using the DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS procedure. Select 'long', to_char (l.sid), to_char (l.serial#), to_char(l.sofar), to_char(l.totalwork), to_char(l.start_time, 'DD-Mon-YYYY HH24:MI:SS' ), to_char ( l.last_update_time , 'DD-Mon-YYYY HH24:MI:SS'), to_char(l.time_remaining), to_char(l.elapsed_seconds), l.opname,l.target,l.target_desc,l.message,s.username,s.osuser,s.lockwait from v$session_longops l, v$session s where l.sid = s.sid and l.serial# = s.serial#; Select 'long', to_char (l.sid), to_char (l.serial#), to_char(l.sofar), to_char(l.totalwork), to_char(l.start_time, 'DD-Mon-YYYY HH24:MI:SS' ), to_char ( l.last_update_time , 'DD-Mon-YYYY HH24:MI:SS'), s.username,s.osuser,s.lockwait from v$session_longops l, v$session s where l.sid = s.sid and l.serial# = s.serial#; select substr(username,1,15),target,to_char(start_time, 'DD-Mon-YYYY HH24:MI:SS' ), SOFAR,substr(MESSAGE,1,70) from v$session_longops; select USERNAME, to_char(start_time, 'DD-Mon-YYYY HH24:MI:SS' ), substr(message,1,90),to_char(time_remaining) from v$session_longops;

9i and 10G note: ================ Oracle has a view inside the Oracle data buffers. The view is called v$bh, and while v$bh was originally developed for Oracle Parallel Server (OPS), the v$bh view can be used to show the number of data blocks in the data buffer for every object type in the database. The following query is especially exciting because you can now see what objects are consuming the data buffer caches. In Oracle9i, you can use this information to segregate tables to separate RAM buffers with different blocksizes. Here is a sample query that shows data buffer utilization for individual objects in the database. Note that this script uses an Oracle9i scalar sub-query, and will not work in preOracle9i systems unless you comment-out column c3. column column column column c0 c1 c2 c3 heading heading heading heading 'Owner' 'Object|Name' 'Number|of|Buffers' 'Percentage|of Data|Buffer' format format format format a15 a30 999,999 999,999,999

select owner c0, object_name c1, count(1) c2, (count(1)/(select count(*) from v$bh)) *100 c3 from dba_objects o, v$bh bh where o.object_id = bh.objd and o.owner not in ('SYS','SYSTEM','AURORA$JIS$UTILITY$') group by owner, object_name order by count(1) desc ; -- ------------------------------ 0.3 QUICK VIEW ON TEMP USAGE: -- ----------------------------select total_extents, used_extents, total_extents, current_users, tablespace_name from v$sort_segment; select username, user, sqladdr, extents, tablespace from v$sort_usage; SELECT b.tablespace, ROUND(((b.blocks*p.value)/1024/1024),2),

a.sid||','||a.serial# SID_SERIAL, a.username, a.program FROM sys.v_$session a, sys.v_$sort_usage b, sys.v_$parameter p WHERE p.name = 'db_block_size' AND a.saddr = b.session_addr ORDER BY b.tablespace, b.blocks; -- --------------------------------- 0.4 QUICK VIEW ON UNDO/ROLLBACK: -- -------------------------------SELECT FROM WHERE AND substr(username, 1, 10), substr(terminal, 1, 10), substr(osuser, 1, 10), t.start_time, r.name, t.used_ublk "ROLLB BLKS", log_io, phy_io sys.v_$transaction t, sys.v_$rollname r, sys.v_$session s t.xidusn = r.usn t.ses_addr = s.saddr;

SELECT substr(n.name, 1, 10), s.writes, s.gets, s.waits, s.wraps, s.extents, s.status, s.optsize, s.rssize FROM V$ROLLNAME n, V$ROLLSTAT s WHERE n.usn=s.usn; SELECT substr(r.name, 1, 10) "RBS", s.sid, s.serial#, s.taddr, t.addr, substr(s.username, 1, 10) "USER", t.status, t.cr_get, t.phy_io, t.used_ublk, t.noundo, substr(s.program, 1, 15) "COMMAND" FROM sys.v_$session s, sys.v_$transaction t, sys.v_$rollname r WHERE t.addr = s.taddr AND t.xidusn = r.usn ORDER BY t.cr_get, t.phy_io; SELECT substr(segment_name, 1, 20), substr(tablespace_name, 1, 20), status, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE FROM DBA_ROLLBACK_SEGS; select 'FREE',count(*) from sys.fet$ union select 'USED',count(*) from sys.uet$; -- Quick view active transactions SELECT NAME, XACTS "ACTIVE TRANSACTIONS" FROM V$ROLLNAME, V$ROLLSTAT WHERE V$ROLLNAME.USN = V$ROLLSTAT.USN; SELECT to_char(BEGIN_TIME, 'DD-MM-YYYY;HH24:MI'), to_char(END_TIME, 'DD-MMYYYY;HH24:MI'), UNDOTSN, UNDOBLKS, TXNCOUNT, MAXCONCURRENCY AS "MAXCON" FROM V$UNDOSTAT WHERE trunc(BEGIN_TIME)=trunc(SYSDATE); select TO_CHAR(MIN(Begin_Time),'DD-MON-YYYY HH24:MI:SS') "Begin Time", TO_CHAR(MAX(End_Time),'DD-MON-YYYY HH24:MI:SS') "End Time",

SUM(Undoblks) "Total Undo Blocks Used", SUM(Txncount) "Total Num Trans Executed", MAX(Maxquerylen) "Longest Query(in secs)", MAX(Maxconcurrency) "Highest Concurrent TrCount", SUM(Ssolderrcnt), SUM(Nospaceerrcnt) from V$UNDOSTAT; SELECT used_urec FROM v$session s, v$transaction t WHERE s.audsid=sys_context('userenv', 'sessionid') and s.taddr = t.addr; (used_urec = Used Undo records) SELECT a.sid, a.username, b.xidusn, b.used_urec, b.used_ublk FROM v$session a, v$transaction b WHERE a.saddr = b.ses_addr; SELECT v.SID, v.BLOCK_GETS, v.BLOCK_CHANGES, w.USERNAME, w.OSUSER, w.TERMINAL FROM v$sess_io v, V$session w WHERE v.SID=w.SID ORDER BY v.SID;

-- --------------------------------- 0.5 SOME EXPLANATIONS: -- --------------------------------

-- explanation of "COMMAND": 1: CREATE TABLE 2: INSERT 3: SELECT 4: CREATE CLUSTER 5: ALTER CLUSTER 6: UPDATE 7: DELETE 8: DROP CLUSTER 9: CREATE INDEX 10: DROP INDEX 11: ALTER INDEX 12: DROP TABLE 13: CREATE SEQUENCE 14: ALTER SEQUENCE 15: ALTER TABLE 16: DROP SEQUENCE 17: GRANT 18: REVOKE 19: CREATE SYNONYM 20: DROP SYNONYM 21: CREATE VIEW 22: DROP VIEW 23: VALIDATE INDEX 24: CREATE PROCEDURE 25: ALTER PROCEDURE 26: LOCK TABLE 27: NO OPERATION 28: RENAME 29: COMMENT 30: AUDIT 31: NOAUDIT 32: CREATE DATABASE LINK 33: DROP DATABASE LINK 34: CREATE DATABASE 35: ALTER DATABASE 36: CREATE ROLLBACK SEGMENT 37: ALTER ROLLBACK SEGMENT 38: DROP ROLLBACK SEGMENT 39: CREATE TABLESPACE 40: ALTER TABLESPACE 41: DROP TABLESPACE 42: ALTER SESSION 43: ALTER USE 44: COMMIT 45: ROLLBACK 46: SAVEPOINT 47: PL/SQL EXECUTE 48: SET TRANSACTION 49: ALTER SYSTEM SWITCH LOG 50: EXPLAIN 51: CREATE USER 25: CREATE ROLE 53: DROP USER 54: DROP ROLE 55: SET ROLE 56: CREATE SCHEMA 57: CREATE CONTROL FILE 58: ALTER TRACING 59: CREATE TRIGGER 60: ALTER TRIGGER 61: DROP TRIGGER 62: ANALYZE TABLE 63: ANALYZE INDEX 64: ANALYZE CLUSTER 65: CREATE PROFILE 66: DROP PROFILE 67: ALTER PROFILE 68: DROP PROCEDURE 69: DROP PROCEDURE 70: ALTER RESOURCE COST 71: CREATE SNAPSHOT LOG 72: ALTER SNAPSHOT LOG 73: DROP SNAPSHOT LOG 74: CREATE SNAPSHOT 75: ALTER SNAPSHOT 76: DROP SNAPSHOT 79: ALTER ROLE 85: TRUNCATE TABLE 86:

TRUNCATE COUSTER 88: ALTER VIEW 91: CREATE FUNCTION 92: ALTER FUNCTION 93: DROP FUNCTION 94: CREATE PACKAGE 95: ALTER PACKAGE 96: DROP PACKAGE 97: CREATE PACKAGE BODY 98: ALTER PACKAGE BODY 99: DROP PACKAGE BODY -- explanation of locks: Locks: 0, 'None', /* Mon Lock equivalent */ 1, 'Null', /* N */ 2, 'Row-S (SS)', /* L */ 3, 'Row-X (SX)', /* R */ 4, 'Share', /* S */ 5, 'S/Row-X (SRX)', /* C */ 6, 'Exclusive', /* X */ to_char(b.lmode) TX: enqueu, waiting TM: DDL on object MR: Media Recovery A TX lock is acquired when a transaction initiates its first change and is held until the transaction does a COMMIT or ROLLBACK. It is used mainly as a queuing mechanism so that other sessions can wait for the transaction to complete. TM Per table locks are acquired during the execution of a transaction when referencing a table with a DML statement so that the object is not dropped or altered during the execution of the transaction, if and only if the dml_locks parameter is non-zero. LOCKS: locks op user objects, zoals tables en rows LATCH: locks op system objects, zoals shared data structures in memory en data dictionary rows LOCKS - shared of exclusive LATCH - altijd exclusive UL= user locks, geplaats door programmatuur m.b.v. bijvoorbeeld DBMS_LOCK package DML LOCKS: data manipulatie: table lock, row lock DDL LOCKS: preserves de struktuur van object (geen simulane DML, DDL statements) DML locks: row lock (TX): voor rows (insert, update, delete) row lock plus table lock: row lock, maar ook voorkomen DDL statements table lock (TM): automatisch bij insert, update, delete, ter voorkoming DDL op table table lock: S: share lock RS: row share RSX: row share exlusive RX: row exclusive X: exclusive (ANDere tansacties kunnen alleen SELECT..)

in V$LOCK lmode column: 0, 1, 2, 3, 4, 5, 6, None Null (NULL) Row-S (SS) Row-X (SX) Share (S) S/Row-X (SSX) Exclusive (X)

Internal Implementation of Oracle Locks (Enqueue) Oracle server uses locks to provide concurrent access to shared resources whereas it uses latches to provide exclusive and short-term access to memory structures inside the SGA. Latches also prevent more than one process to execute the same piece of code, which other process might be executing. Latch is also a simple lock, which provides serialize and only exclusive access to the memory area in SGA. Oracle doesnt use latches to provide shared access to resources because it will increase CPU usage. Latches are used for big memory structure and allow operations required for locking the sub structures. Shared resources can be tables, transactions, redo threads, etc. Enqueue can be local or global. If it is a single instance then enqueues will be local to that instance. There are global enqueus also like ST enqueue, which is held before any space transaction can be occurred on any tablespace in RAC. ST enqueues are held only for dictionary-managed tablespaces. These oracle locks are generally known as Enqueue, because whenever there is a session request for a lock on any shared resource structure, it's lock data structure is queued to one of the linked list attached to that resource structure (Resource structure is discussed later). Before proceeding further with this topic, here is little brief about Oracle locks. Oracle locks can be applied to compound and simple objects like tables and the cache buffer. Locks can be held in different modes like shared, excusive, null, sub-shared, sub-exclusive and shared sub-exclusive. Depending on the type of object, different modes are applied. Foe example, a compound object like a table with rows, all above mentioned modes could be applicable whereas for simple objects only the first three will be applicable. These lock modes dont have any importance of their own but the importance is how they are being used by the subsystem. These lock modes (compatibility between locks) define how the session will get a lock on that object.

-- Explanation of Waits: SQL> desc v$system_event; Name

-----------------------EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT TIME_WAITED_MICRO v$system_event This view displays the count (total_waits) of all wait events since startup of the instance. If timed_statistics is set to true, the sum of the wait times for all events are also displayed in the column time_waited. The unit of time_waited is one hundreth of a second. Since 10g, an additional column (time_waited_micro) measures wait times in millionth of a second. total_waits where event='buffer busy waits' is equal the sum of count in v$waitstat. v$enqueue_stat can be used to break down waits on the enqueue wait event. While this view totals all events in an instance, v$session select event, total_waits, time_waited from v$system_event where event like '%file%' Order by total_waits desc; column column column column column c1 c2 c3 c4 c5 heading heading heading heading heading 'Event|Name' 'Total|Waits' 'Seconds|Waiting' 'Total|Timeouts' 'Average|Wait|(in secs)' format format format format format a30 999,999,999 999,999 999,999,999 99.999

ttitle 'System-wide Wait Analysis|for current wait events' select event c1, total_waits c2, time_waited / 100 c3, total_timeouts c4, average_wait /100 c5 from sys.v_$system_event where event not in ( 'dispatcher timer', 'lock element cleanup', 'Null event', 'parallel query dequeue wait', 'parallel query idle wait - Slaves', 'pipe get', 'PL/SQL lock timer', 'pmon timer', 'rdbms ipc message', 'slave wait', 'smon timer', 'SQL*Net break/reset to client', 'SQL*Net message from client',

) AND event not like 'DFS%' and event not like '%done%' and event not like '%Idle%' AND event not like 'KXFX%' order by c2 desc ;

'SQL*Net message to client', 'SQL*Net more data to client', 'virtual circuit status', 'WMON goes to sleep'

Create table beg_system_event as select * from v$system_event Run workload through system or user task Create table end_system_event as select * from v$system_event Issue SQL to determine true wait events drop table beg_system_event; drop table end_system_event; SELECT b.event, (e.total_waits - b.total_waits) total_waits, (e.total_timeouts - b.total_timeouts) total_timeouts, (e.time_waited - b.time_waited) time_waited FROM beg_system_event b, end_system_event e WHERE b.event = e.event; Cumulative info, after startup: ------------------------------SELECT * FROM v$system_event WHERE event = 'enqueue';

SELECT * FROM v$sysstat WHERE class=4; select c.name,a.addr,a.gets,a.misses,a.sleeps, a.immediate_gets,a.immediate_misses,a.wait_time, b.pid from v$latch a, v$latchholder b, v$latchname c where a.addr = b.laddr(+) and a.latch# = c.latch# order by a.latch#; -- ---------------------------------------------------------------- 0.6. QUICK INFO ON HIT RATIO, SHARED POOL etc.. -- ---------------------------------------------------------------- Hit ratio: SELECT FROM WHERE (1-(pr.value/(dbg.value+cg.value)))*100 v$sysstat pr, v$sysstat dbg, v$sysstat cg pr.name = 'physical reads'

AND AND

dbg.name = 'db block gets' cg.name = 'consistent gets';

SELECT * FROM V$SGA; -- free memory shared pool: SELECT * FROM v$sgastat WHERE name = 'free memory'; -- hit ratio shared pool: SELECT gethits,gets,gethitratio FROM v$librarycache WHERE namespace = 'SQL AREA'; SELECT SUM(PINS) "EXECUTIONS", SUM(RELOADS) "CACHE MISSES WHILE EXECUTING" FROM V$LIBRARYCACHE; SELECT sum(sharable_mem) FROM v$db_object_cache; -- finding literals in SP: SELECT substr(sql_text,1,50) "SQL", count(*) , sum(executions) "TotExecs" FROM v$sqlarea WHERE executions < 5 GROUP BY substr(sql_text,1,50) HAVING count(*) > 30 ORDER BY 2; -- ---------------------------------------- 0.7 Quick Table and object information -- --------------------------------------SELECT distinct substr(t.owner, 1, 25), substr(t.table_name,1,50), substr(t.tablespace_name,1,20), t.chain_cnt, t.logging, s.relative_fno FROM dba_tables t, dba_segments s WHERE t.owner not in ('SYS','SYSTEM', 'OUTLN','DBSNMP','WMSYS','ORDSYS','ORDPLUGINS','MDSYS','CTXSYS','XDB') AND t.table_name=s.segment_name AND s.segment_type='TABLE' AND s.segment_name like 'CI_PAY%'; SELECT substr(segment_name, 1, 30), segment_type, substr(owner, 1, 10), extents, initial_extent, next_extent, max_extents FROM dba_segments WHERE extents > max_extents - 100 AND owner not in ('SYS','SYSTEM'); SELECT FROM WHERE and segment_name, owner, tablespace_name, extents dba_segments owner='SALES' -- you use the correct schema here extents > 700;

SELECT owner, substr(object_name, 1, 30), object_type, created, last_ddl_time, status FROM dba_objects where OWNER='RM_LIVE'; WHERE created > SYSDATE-1; SELECT owner, substr(object_name, 1, 30), object_type, created, last_ddl_time, status FROM dba_objects WHERE status='INVALID'; Compare 2 owners: ----------------select table_name from dba_tables where owner='MIS_OWNER' and table_name not in (SELECT table_name from dba_tables where OWNER='MARPAT'); Table and column information: ----------------------------select substr(table_name, 1, 3) schema , table_name , column_name , substr(data_type,1 ,1) data_type from user_tab_columns where COLUMN_NAME='ENV_ID' where table_name like 'ALG%' or table_name like 'STG%' or table_name like 'ODS%' or table_name like 'DWH%' or table_name like 'MKM%' order by decode(substr(table_name, 1, 3), 'ALG', 10, 'STG', 20, 'ODS', 30, 'DWH', 40, 'MKM', 50, 60) , table_name , column_id Check on existence of JServer: -----------------------------select count(*) from all_objects where object_name = 'DBMS_JAVA'; should return a count of 3 -- --------------------------------------- 0.8 QUICK INFO ON PRODUCT INFORMATION: -- -------------------------------------ersa SELECT * FROM PRODUCT_COMPONENT_VERSION; SELECT * FROM NLS_DATABASE_PARAMETERS; SELECT * FROM NLS_SESSION_PARAMETERS; SELECT * FROM NLS_INSTANCE_PARAMETERS; SELECT * FROM V$OPTION; SELECT * FROM V$LICENSE;

SELECT * FROM V$VERSION; Oracle RDBMS releases: ---------------------9.2.0.1 is the terminal release for Oracle 9i. Rel 2. Normally it's patched to 9.2.0.4. As from october patches 9.2.0.5 and little later 9.2.0.6 were available 9.2.0.4 is patch ID 3095277. 9.0.1.4 8.1.7 8.0.6 7.3.4 is is is is the the the the terminal terminal terminal terminal release release release release for for for for Oracle 9i Oracle8i. Oracle8. Oracle7. Rel. 1. Additional patchsets exists. Additional patchsets exists. Additional patchsets exists.

IS ORACLE 32BIT or 64BIT? ------------------------Starting with version 8, Oracle began shipping 64bit versions of it's RDBMS product on UNIX platforms that support 64bit software. IMPORTANT: 64bit Oracle can only be installed on Operating Systems that are 64bit enabled. In general, if Oracle is 64bit, '64bit' will be displayed on the opening banners of Oracle executables such as 'svrmgrl', 'exp' and 'imp'. It will also be displayed in the headers of Oracle trace files. Otherwise if '64bit' is not display at these locations, it can be assumed that Oracle is 32bit. or From the OS level: will be indicated. % cd $ORACLE_HOME/bin % file oracle ...if 64bit, '64bit'

To verify the wordsize of a downloaded patchset: -----------------------------------------------The filename of the downloaded patchset usually dictates which version and wordsize of Oracle it should be applied against. For instance: p1882450_8172_SOLARIS64.zip is the 8.1.7.2 patchset for 64bit Oracle on Solaris. Also refer to the README that is included with the patch or patch set and this Note: Win2k Server Certifications: ---------------------------OS Product Certified With Version Status Addtl. Info. Components Other Install Issue 2000 10g N/A N/A Certified Yes None None None 2000 9.2 32-bit -Opteron N/A N/A Certified Yes None None None 2000 9.2 N/A N/A Certified Yes None None None 2000 9.0.1 N/A N/A Desupported Yes None N/A N/A 2000 8.1.7 (8i) N/A N/A Desupported Yes None N/A N/A 2000 8.1.6 (8i) N/A N/A Desupported Yes None N/A N/A 2000, Beta 3 8.1.5 (8i) N/A N/A Withdrawn Yes N/A N/A N/A

Solaris Server certifications: -----------------------------Server Certifications OS Product Certified With Version Status Addtl. Info. Components Other Install Issue 9 10g 64-bit N/A N/A Certified Yes None None None 8 10g 64-bit N/A N/A Certified Yes None None None 10 10g 64-bit N/A N/A Projected None N/A N/A N/A 9 9.2 64-bit N/A N/A Certified Yes None None None 8 9.2 64-bit N/A N/A Certified Yes None None None 10 9.2 64-bit N/A N/A Projected None N/A N/A N/A 2.6 9.2 N/A N/A Certified Yes None None None 9 9.2 N/A N/A Certified Yes None None None 8 9.2 N/A N/A Certified Yes None None None 7 9.2 N/A N/A Certified Yes None None None 10 9.2 N/A N/A Projected None N/A N/A N/A 9 9.0.1 64-bit N/A N/A Desupported Yes None N/A N/A 8 9.0.1 64-bit N/A N/A Desupported Yes None N/A N/A 2.6 9.0.1 N/A N/A Desupported Yes None N/A N/A 9 9.0.1 N/A N/A Desupported Yes None N/A N/A 8 9.0.1 N/A N/A Desupported Yes None N/A N/A 7 9.0.1 N/A N/A Desupported Yes None N/A N/A 9 8.1.7 (8i) 64-bit N/A N/A Desupported Yes None N/A N/A 8 8.1.7 (8i) 64-bit N/A N/A Desupported Yes None N/A N/A 2.6 8.1.7 (8i) N/A N/A Desupported Yes None N/A N/A 9 8.1.7 (8i) N/A N/A Desupported Yes None N/A N/A 8 8.1.7 (8i) N/A N/A Desupported Yes None N/A N/A 7 8.1.7 (8i) N/A N/A Desupported Yes None N/A N/A everything below: desupported Oracle clients: --------------Server Version Client Version 10.1.0 10.1.0 Yes Yes 9.2.0 Yes Yes Was 9.0.1 Was Was Was 8.1.7 Yes Yes Was 8.1.6 No No Was 8.1.5 No No No 8.0.6 No Was Was 8.0.5 No No No 7.3.4 No Was Was 9.2.0 Was Yes Was Yes Was Was Was Was Was 9.0.1 8.1.7 Yes #2 No No Was No Was Was Was Was Was Was Was Was Was Was Was Was 8.1.6 No Was Was Was Was Was Was Was Was 8.1.5 No No No Was Was Was Was Was Was 8.0.6 8.0.5 7.3.4 No No No No #1 Was Was Was Was Was Was Was

-- ------------------------------------------------------ 0.9 QUICK INFO WITH REGARDS LOGS AND BACKUP RECOVERY: -- ----------------------------------------------------SELECT * from V$BACKUP; SELECT file#, substr(name, 1, 30), status, checkpoint_change# controlfile -- uit

FROM V$DATAFILE; SELECT d.file#, d.status, d.checkpoint_change#, b.status, b.CHANGE#, to_char(b.TIME,'DD-MM-YYYY;HH24:MI'), substr(d.name, 1, 40) FROM V$DATAFILE d, V$BACKUP b WHERE d.file#=b.file#; SELECT file#, substr(name, 1, 30), status, fuzzy, checkpoint_change# file header FROM V$DATAFILE_HEADER; -- uit

SELECT first_change#, next_change#, sequence#, archived, substr(name, 1, 40), COMPLETION_TIME, FIRST_CHANGE#, FIRST_TIME FROM V$ARCHIVED_LOG WHERE COMPLETION_TIME > SYSDATE -2; SELECT recid, first_change#, sequence#, next_change# FROM V$LOG_HISTORY; SELECT resetlogs_change#, checkpoint_change#, controlfile_change#, open_resetlogs FROM V$DATABASE; SELECT * FROM V$RECOVER_FILE -- Which file needs recovery

-- ----------------------------------------------------------------------------- 0.10 QUICK INFO WITH REGARDS TO TABLESPACES, DATAFILES, REDO LOGFILES etc..: -- ------------------------------------------------------------------------------ online redo log informatie: V$LOG, V$LOGFILE: SELECT l.group#, l.members, l.status, l.bytes, substr(lf.member, 1, 50) FROM V$LOG l, V$LOGFILE lf WHERE l.group#=lf.group#; SELECT THREAD#, SEQUENCE#, FIRST_CHANGE#, FIRST_TIME, to_char(FIRST_TIME, 'DD-MM-YYYY;HH24:MI') FROM V$LOG_HISTORY; -- WHERE SEQUENCE# SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG; -- tablespace free-used: SELECT Total.name "Tablespace Name", Free_space, (total_space-Free_space) Used_space, total_space FROM (SELECT tablespace_name, sum(bytes/1024/1024) Free_Space FROM sys.dba_free_space GROUP BY tablespace_name ) Free, (SELECT b.name, sum(bytes/1024/1024) TOTAL_SPACE FROM sys.v_$datafile a, sys.v_$tablespace B WHERE a.ts# = b.ts# GROUP BY b.name ) Total WHERE Free.Tablespace_name = Total.name;

SELECT substr(file_name, 1, 70), tablespace_name FROM dba_data_files; ----------------------------------------------- 0.11 AUDIT Statements: ---------------------------------------------select v.sql_text, v.FIRST_LOAD_TIME, v.PARSING_SCHEMA_ID, v.DISK_READS, v.ROWS_PROCESSED, v.CPU_TIME, b.username from v$sqlarea v, dba_users b where v.FIRST_LOAD_TIME > '2008-05-12' and v.PARSING_SCHEMA_ID=b.user_id order by v.FIRST_LOAD_TIME ; ------------------------------------------------ 0.12 EXAMPLE OF DYNAMIC SQL: ----------------------------------------------select 'UPDATE '||t.table_name||' SET '||c.column_name||'=REPLACE('|| c.column_name||','''',CHR(7));' from user_tab_columns c, user_tables t where c.table_name=t.table_name and t.num_rows>0 and c.DATA_LENGTH>10 and data_type like '%CHAR%' ORDER BY t.table_name desc; create public synonym EMPLOYEE for HARRY.EMPLOYEE; select 'create public synonym '||table_name||' for CISADM.'||table_name||';' from dba_tables where owner='CISADM'; select 'GRANT SELECT, INSERT, UPDATE, DELETE ON '||table_name||' TO CISUSER;' from dba_tables where owner='CISADM'; select 'GRANT SELECT ON '||table_name||' TO CISREAD;' from dba_tables where owner='CISADM';

------------------------------------------------ 0.13 ORACLE MOST COMMON DATATYPES: -----------------------------------------------

Example: number as integer in comparison to smallint ----------------------------------------------------

SQL> create table a 2 (id number(3)); Table created. SQL> create table b 2 (id smallint); Table created. SQL> create table c 2 (id integer); Table created. SQL> insert into a 2 values 3 (5); 1 row created. SQL> insert into a 2 values 3 (999); 1 row created. SQL> insert into a 2 values 3 (1001); (1001) * ERROR at line 3: ORA-01438: value larger than specified precision allowed for this column

SQL> insert into b 2 values 3 (5); 1 row created. SQL> insert into b 2 values 3 (99); 1 row created. SQL> insert into b 2 values 3 (999); 1 row created. SQL> insert into b

2 3

values (1001);

1 row created. SQL> insert into b 2 values 3 (65536); 1 row created. SQL> insert into b 2 values 3 (1048576); 1 row created. SQL> insert into b 2 values 3 (1099511627776); 1 row created. SQL> insert into b 2 values 3 (9.5); 1 row created. SQL> insert into b 2 values 3 (100.23); 1 row created. SQL> select * from b; ID ---------5 99 999 1001 65536 1048576 1.0995E+12 10 100 9 rows selected.

smallint is really not that "small". Actually its float(38).

SQL> insert into c 2 values 3 (5); 1 row created. SQL> insert into c 2 values 3 (9999); 1 row created. SQL> insert into c 2 values 3 (92.7); 1 row created. SQL> insert into c 2 values 3 (1099511627776); 1 row created. SQL> select * from c; ID ---------5 9999 93 1.0995E+12

======================== 1. NOTES ON PERFORMANCE: ========================= 1.1 POOLS: ========== -- SHARED POOL: -- -----------A literal SQL statement is considered as one which uses literals in the predicate/s rather than bind variables where the value of the literal is likely to differ between various executions of the statement. Eg 1: SELECT * FROM emp WHERE ename='CLARK'; is used by the application instead of

SELECT * FROM emp WHERE ename=:bind1; SQL statement for this article as it can be shared. -- Hard Parse If a new SQL statement is issued which does not exist in the shared pool then this has to be parsed fully. Eg: Oracle has to allocate memory for the statement from the shared pool, check the statement syntactically and semantically etc... This is referred to as a hard parse and is very expensive in both terms of CPU used and in the number of latch gets performed. --Soft Parse If a session issues a SQL statement which is already in the shared pool AND it can use an existing version of that statement then this is known as a 'soft parse'. As far as the application is concerned it has asked to parse the statement. if two statements are textually identical but cannot be shared then these are called 'versions' of the same statement. If Oracle matches to a statement with many versions it has to check each version in turn to see if it is truely identical to the statement currently being parsed. Hence high version counts are best avoided. The best approach to take is that all SQL should be sharable unless it is adhoc or infrequently used SQL where it is important to give CBO as much information as possible in order for it to produce a good execution plan. --Eliminating Literal SQL If you have an existing application it is unlikely that you could eliminate all literal SQL but you should be prepared to eliminate some if it is causing problems. By looking at the V$SQLAREA view it is possible to see which literal statements are good candidates for converting to use bind variables. The following query shows SQL in the SGA where there are a large number of similar statements: SELECT substr(sql_text,1,40) "SQL", count(*) , sum(executions) "TotExecs" FROM v$sqlarea WHERE executions < 5 GROUP BY substr(sql_text,1,40) HAVING count(*) > 30 ORDER BY 2; The values 40,5 and 30 are example values so this query is looking for different statements whose first 40 characters are the same which have only been executed a few times each and there are at least 30 different occurrances in the shared pool. This query uses the idea it is common for literal statements to begin "SELECT col1,col2,col3 FROM table WHERE ..." with the leading portion of each statement being the same. --Avoid Invalidations

Some specific orders will change the state of cursors to INVALIDATE. These orders modify directly the context of related objects associated with cursors. That's orders are TRUNCATE, ANALYZE or DBMS_STATS.GATHER_XXX on tables or indexes, grants changes on underlying objects. The associated cursors will stay in the SQLAREA but when it will be reference next time, it should be reloaded and reparsed fully, so the global performance will be impacted. The following query could help us to better identify the concerned cursors: SELECT substr(sql_text, 1, 40) "SQL", invalidations from v$sqlarea order by invalidations DESC; -- CURSOR_SHARING parameter (8.1.6 onwards) is a new parameter introduced in Oracle8.1.6. It should be used with caution in this release. If this parameter is set to FORCE then literals will be replaced by system generated bind variables where possible. For multiple similar statements which differ only in the literals used this allows the cursors to be shared even though the application supplied SQL uses literals. The parameter can be set dynamically at the system or session level thus: ALTER SESSION SET cursor_sharing = FORCE; or ALTER SYSTEM SET cursor_sharing = FORCE; or it can be set in the init.ora file. Note: As the FORCE setting causes system generated bind variables to be used in place of literals, a different execution plan may be chosen by the cost based optimizer (CBO) as it no longer has the literal values available to it when costing the best execution plan. In Oracle9i, it is possible to set CURSOR_SHARING=SIMILAR. SIMILAR causes statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect either the meaning of the statement or the degree to which the plan is optimized. This enhancement improves the usability of the parameter for situations where FORCE would normally cause a different, undesired execution plan. With CURSOR_SHARING=SIMILAR, Oracle determines which literals are "safe" for substitution with bind variables. This will result in some SQL not being shared in an attempt to provide a more efficient execution plan. -- SESSION_CACHED_CURSORS parameter is a numeric parameter which can be set at instance level or at session level using the command: ALTER SESSION SET session_cached_cursors = NNN; The value NNN determines how many 'cached' cursors there can be in your session. Whenever a statement is parsed Oracle first looks at the statements pointed to by your private session cache if a sharable version of the statement exists it can be used. This provides a shortcut access to frequently parsed statements that uses less CPU and uses far fewer latch gets than a soft or hard parse.

To get placed in the session cache the same statement has to be parsed 3 times within the same cursor - a pointer to the shared cursor is then added to your session cache. If all session cache cursors are in use then the least recently used entry is discarded. If you do not have this parameter set already then it is advisable to set it to a starting value of about 50. The statistics section of the bstat/estat report includes a value for 'session cursor cache hits' which shows if the cursor cache is giving any benefit. The size of the cursor cache can then be increased or decreased as necessary. SESSION_CACHED_CURSORS are particularly useful with Oracle Forms applications when forms are frequently opened and closed. -- SHARED_POOL_RESERVED_SIZE parameter There are quite a few notes explaining already in circulation. The parameter was introduced in Oracle 7.1.5 and provides a means of reserving a portion of the shared pool for large memory allocations. The reserved area comes out of the shared pool itself. From a practical point of view one should set SHARED_POOL_RESERVED_SIZE to about 10% of SHARED_POOL_SIZE unless either the shared pool is very large OR SHARED_POOL_RESERVED_MIN_ALLOC has been set lower than the default value: If the shared pool is very large then 10% may waste a significant amount of memory when a few Mb will suffice. If SHARED_POOL_RESERVED_MIN_ALLOC has been lowered then many space requests may be eligible to be satisfied from this portion of the shared pool and so 10% may be too little. It is easy to monitor the space usage of the reserved area using the which has a column FREE_SPACE. -- SHARED_POOL_RESERVED_MIN_ALLOC parameter In Oracle8i this parameter is hidden. SHARED_POOL_RESERVED_MIN_ALLOC should generally be left at its default value, although in certain cases values of 4100 or 4200 may help relieve some contention on a heavily loaded shared pool. -- SHARED_POOL_SIZE parameter controls the size of the shared pool itself. The size of the shared pool can impact performance. If it is too small then it is likely that sharable information will be flushed from the pool and then later need to be reloaded (rebuilt). If there is heavy use of literal SQL and the shared pool is too large then over time a lot of small chunks of memory can build up on the internal memory freelists causing the shared pool latch to be held for longer which in-turn can impact performance. In this situation a smaller shared pool may perform better than a larger one. This problem is greatly reduced in 8.0.6 and in 8.1.6 onwards due to the enhancement in