Tkprof


From Oracle FAQ
TKProf is an Oracle database utility used to format SQL Trace output into human readable format. The TKProf executable is located in the ORACLE HOME/bin directory.
Start TKProf
Syntax is:
tkprof input.trc output.prf [options]
Example:
$ tkprof orcl102_ora_3064.trc output.prf EXPLAIN=scott/tiger SYS=NO
Sample output
For the above example, the output would be in file output.prf:
Tkprof: Release 9.2.0.1.0 - Production on Tue Dec 24 15:32:43 2002
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Trace file: ORCL102_ora_3064.trc

Sort options: default

********************************************************************************
count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
********************************************************************************

select *
from
 employee where emp_id = 3737

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse       10      0.00       0.03          0          0          0           0
Execute     10      0.00       0.00          0          0          0           0
Fetch       20      0.34       0.35         72       4730          0          10
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total       40      0.34       0.39         72       4730          0          10

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 59

Rows     Row Source Operation
-------  ---------------------------------------------------
      1  TABLE ACCESS FULL EMPLOYEE
Links

Tracing a SQL session


Start session trace
To start a SQL trace for the current session, execute:
ALTER SESSION SET sql_trace = true;
You can also add an identifier to the trace file name for later identification:
ALTER SESSION SET sql_trace = true;
ALTER SESSION SET tracefile_identifier = mysqltrace;
Stop session trace
To stop SQL tracing for the current session, execute:
ALTER SESSION SET sql_trace = false;
Tracing other user's sessions
DBA's can use DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION to trace problematic database sessions. Steps:
  • Get the SID and SERIAL# for the process you want to trace.
SQL> select sid, serial# from sys.v_$session where ...
       SID    SERIAL#
---------- ----------
         8      13607
  • Enable tracing for your selected process:
SQL> ALTER SYSTEM SET timed_statistics = true;
SQL> execute dbms_system.set_sql_trace_in_session(8, 13607, true);
  • Ask user to run just the necessary to demonstrate his problem.
  • Disable tracing for your selected process:
SQL> execute dbms_system.set_sql_trace_in_session(8,13607, false);
  • Look for trace file in USER_DUMP_DEST:
$ cd /app/oracle/admin/oradba/udump
$ ls -ltr
total 8
-rw-r-----    1 oracle   dba         2764 Mar 30 12:37 ora_9294.trc
Tracing an entire database
To enable SQL tracing for the entire database, execute:
ALTER SYSTEM SET sql_trace = true SCOPE=MEMORY;
To stop, execute:
ALTER SYSTEM SET sql_trace = false SCOPE=MEMORY;
Identifying trace files
Trace output is written to the database's UDUMP directory.
The default name for a trace files is INSTANCE_PID_ora_TRACEID.trc where:
  • INSTANCE is the name of the Oracle instance,
  • PID is the operating system process ID (V$PROCESS.OSPID); and
  • TRACEID is a character string of your choosing.
 Formatting output
Trace output is quite unreadable. However, Oracle provides a utility, called TKProf, that can be used to format trace output.
 Also see
  • TKProf, Oracle's utility for formatting SQL_TRACE output.
External links
  • itrprof SQL Analyzer, web based tool which analysing SQL_TRACE and Event 10046 trace files.
  • FlexTracer, commercial client-side SQL tracer for Oracle.
  • QueryAdvisor, commercial GUI based client-side SQL tracefile analyzer for Oracle single instance and RAC.

Alter system in oracle


Alter system in Oracle
Alter system archive log [start|stop|all|...]
alter system archive log all;
alter system archive log next;
alter system archive log sequence 104;
alter system archive log current;
alter system archive log current noswitch;
The following command can be used to stop arch.
alter system archive log stop
Similarly, arch is started with
alter system archive log start
However, changing the archiver this way doesn't last when the database is restarted. When the database is started, it consults log_archive_start in the initialization file to determine if arch is started.
Alter system archive log all
This command is used to manually archive redo logs.
alter system disconnect session
alter system kill session
alter system kill session 'session-id,session-serial'
This command kills a session. The session-id and session-serial parameters are found in the v$session view (columns sid and serial#.
alter system checkpoint
Performs a checkpoint
alter system checkpoint
alter system dump datafile
This command can be used in order to dump one ore more blocks of a datafile. The following command dumps blocks 50 through 55 of file 5. Which file 5 is can be found out with v$datafile
alter system dump datafile 5 block min 50 block max 55;
Note: trace files are only readable by the Oracle account. If you want to change this, set the undocumented initialization parameter _trace_files_public to true. Doing so will, however, cause a big security risk.
alter system flush buffer_cache
alter system flush buffer_cache;
This command is not available prior to 10g. It flushes the buffer cache in the SGA.
9i had an undocumented command to flush the buffer cache:
alter session set events = 'immediate trace name flush_cache';
alter system flush shared_pool
alter system flush shared_pool;
This command flushed the shared pool.
alter system quiesce restricted
alter system suspend|resume
alter system switch logfile
Causes a redo log switch.
alter system switch logfile;
If the database is in archive log mode, but the ARCH process hasn't been startedm, the command might hang, because it waits for the archiving of the 'next' online redo log.
alter system register
Forces the registration of database information with the listener.
alter system register
Alter system set timed_statistics
Setting timed_statistics=true might be usefule when using tk prof.
Alter system set sql_trace
Setting sql_trace=true is a prerequisite when using tk prof.
Alter system set .... deferred
Alter system can be used to change initialization parameters on system level. However, some parameters, when changed with alter system don't affect sessions that are already opened at the time when the statement is executet; it only affects sessions started later. These parameters must be changed with alter system set <initialization parameter> DEFERRED, otherwise a ORA-02096: specified initialization parameter is not modifiable with this option error is returned.
These parameters can be identified as they have a DEFERRED in the isses_modifiable column of v$parameter.
Alter system reset <parameter_name>
Resets a parameter.
alter system reset some_param scope=both sid='*';
scope
scope=memory
Changes the parameter's value for the running instance only. As soon as the instance is stopped and started, this change will be lost.
scope=spfile
scope=both
Alters an initialization parameter in the spfile as well as in the running instance.