Handy tkprof sql creating script using bash shell unix, linux with oracle environment

Posted by Jiltin     10 December, 2008    8,434 views   

Oracle gives you this program called TKProf that reads your trace file and spits out somewhat meaningful output. My favorite option to tkprof is sort=prsela,fchela,exeela. This sorts the statements from longest running to shortest running. I prefer this format because I can concentrate on the top two or three statements for the most impact.

By tracing, I mean capturing all the SQL in a user’s session, or a SQL trace. As you can tell from the Oracle Performance Tuning Guide and Reference, there are many ways to enable tracing. Below are two methods I use as a DBA in my day-to-day routine.

Here is the script I often used to find the sql script using oracle trace utility for oracle applications forms, reports. Change the user id, password and database name to suit your environment.

Download TKprof shell script

#!/bin/sh
#***********************************************
# Script Name: tkp
#
# Developed by Jay
#***********************************************
# This script get the trace file name as argument and creates a tkprof file required for oracle analysis
#
# Usage : tkp "oracle_trace_file"
#
# Assumption: The oracle home environment set properly
#             The trace file suffix is .trc and is not provided as parameter argument
#             tkprof utility – unix – installed and oracle_home and path environment variables set
#             user id = apps, and password = apps
#***********************************************
if [ $@ > 0 ]
then
tkprof $1.trc $1.tkprof sort=exeela,fchela,prsela explain=apps/apps@PRODUCTION
else
echo ‘Usage : tkp "oracle_trace_file"’
fi

Sometimes, a session is already underway and you need to start a trace midway through it’s execution. Here, you need to be a DBA and enable the 10046 event in the user’s session. This is a little more tricky since you have to know the sid and serial# from v$session in order to enable the tracing. For example,

SQL> SELECT sid, serial#, username
2  FROM v$session
3  WHERE username = ‘JEFFH’;

     SID    SERIAL# USERNAME
———- ———- ——————————
      25          5 JEFFH

SQL> exec sys.dbms_system.set_ev(25, 5, 10046,8,);

PL/SQL procedure successfully completed.

Statements get written to the trace file when they are first encountered after the trace is started. The statement that is executing may not be in the final trace file.

Trace with TKProf
PARAMETERS
You need 2 database parameters to trace sessions: TIMED_STATISTICS and USER_DUMP_DEST.

TIMED_STATISTICS should be TRUE to use statistics.
Also possible so set this in a session:
SQL> ALTER SESSION SET TIMED_STATISTICS=TRUE;

USER_DUMP_DEST points to the directory on the server where the tracefiles are being written.

Enable trace
You can enable tracing in the following ways:
SQL*Plus:
SQL> alter session set sql_trace true;

PL/SQL:
dbms_session.set_sql_trace(TRUE);

DBA
SQL> execute sys.dbms_system.set_sql_trace_in_session(sid,serial#,TRUE);
with: sid en serial# from the query:
Select username, sid, serial#, machine from v$session;

Oracle forms:
start forms with f45run32.exe statistics=yes
or make a PRE-FORM trigger with the statement:
forms_ddl(’alter session set sql_trace true’);

Oracle reports:
BEFORE-REPORT trigger with statement:
srw.do_sql(’alter session set sql_trace true’);

PRO*C
EXEC SQL ALTER SESSION SET SQL_TRACE TRUE;

Use TKPROF
To make a tracefile readable, you need TKProf. Use the following command on the server:
TKPROF tracefile exportfile [explain=username/password] [table= …] [print= ] [insert= ] [sys= ] [record=..] [sort= ]

The statements between brackets are optional. Their meaning is:
explain=username/password: show an executionplan.
table= schema.tabelnaam : use this table for explain plan
print=integer restrict the number of shown SQL-statements.
insert=bestandsnaam Show SQL-statements and data within SQL statements
sys = NO Don’t show statements that are executed under the SYS-schema. Most of the times these are recursive SQL-statements that are less interesting.
Aggregate=NO Don’t aggregate SQL-statments that are executed more than once.
sort= Sort the SQL-statements. The option is made up of 2 parts:
part1:
Prs Sorteer op parse-values
Exe Sorteer op executie-values
fch Sorteer op fetch-values

Part 2:
Cnt Sort on number of calls
Cpu Sort on CPU-usage
Ela Sort on elapsed time
Dsk Sort on disk-reads
Qry Sort on consistent reads
Cu Sort on current reads
Mis Sort on library cache misses
row Sort on number of processed rows

I think Oracle uses tkprof as an acronym for Tom Kyte, Professor!

Following Google Searches Lead To This Post: unix shell sql select
bash sql query
general unix shell sql result read example
tkprof fchela
using mysql in shell script
bash execute Oracle procedure
trace file with sort=exeela,prsela,fchela
capture oracle sql
script “get sql” table oracle
oracle 9i use tkprof to get sql statements from .trc files
tkprof exeela
v$parameter sql table in Unix
oracle tkprof insert
exec pl sql shell bash
mysql bash passing parameter sql
calling multiple sql from shell scripts
top cpu queries using tkprof
select from linux to sql server bash
performance tkprof sort
executing unix script from within mysql trigger
tkprof sort
tkprof sort options
how to create a report in sql USING UNIX
bash script create sql base data
automatic tkprof
examples using shell scripts in pl/sql
oracle trace prs exe fch
creating a sql command file from unix
how to run a oracle sql file with bash script
tkprof syntax how to sort by total elapsed time
bash sql query with variable
pro*c exec sql alter session set oracle 9
trace bash script
execute unix shell from within oracle sql
lancer shell unix dans oracle forms
unix, creating sql script
bash shell script statistics
select rows from oracle using shell
inser shell through SQL query
run sql bash
gernerate stastics of query through tkprof
generate sql trace for particular sid
run tkprof from sh
Oracle unix script sql
how to create sql file using shell
tkprof prsela
bash shell script sql
how to create a simple shell in unix using an exec
create oracle table using unix
oracle passing a sql result to a unix script
script to generate tkprof files
changing userid in a shell script
query reason for consistent high tkprof oracle
tkprof parameters
using bash to make sql oracle query
oracle + linux script
use sys user to generate tkprof
sql in bash
Linux script using true
execute sql from bash
example tkprof sort=
execute a unix shell script from a database trigger
oracle sql trace sid# auto logging
how to call alter statment in forms 10g
linux shell as sql
Sort options: prsela exeela fchela
using tkprof examples
how to run oracle sql shell script variable v$database
linux calling sql with bash
how to print out system date in unix using pl sql
unix tkprof script
Unix script to create a report
bash shell query mysql and insert
EXEC SQL ALTER SESSION SET SQL_TRACE TRUE pro*c
oracle sample tkprof file explain
tkprof+r12
set env variable for sql in shell script
tkprof password
calling a .sql file in unix shell script
how to use v$session table in a shell call
tkprof to capture sql statements
tkprofed (sys=no, sort=exeela,prsela,fchela
invoking multiple sessions through shell script
tkprof tom kyte user_dump_dest
oracle 10g tkprof sort
sql script to track plan changes
oracle +”show.sql” tomkyte
create sql table using shell script
linux variable sql bash
unix script change user ID
oracle tkprof aggregate=no
counting number of updated records in oracle from unix script
before report trigger SQL_TRACE
select a row from last logins bash
How to create pl/sql table in unix
mysql bash script param
linu bash setting for oracle home
oracle sql +bash
bash sql get variable
what is tkprof in oracle apps
bash script to run oracle script
bash pl sql
script shell sql select as
TKPROF script location in Oracle Apps
oracle 10g script CPU CONSUMPTION
sql select from where “bash script”
tkprof prsela,exe
multiple sql script run at a time using shell script
tkprof syntax with TOP Ten queries
explain=apps/apps sort=(exeela,fchela
tkprof script
read file and insert SQL using shell script
create sql script file in unix
oracle sql from bash
tkprof sort total
running sql script oracle in linux
shell script for oracle db trace
UNIX sql script variables
run script in bash to query sql
bash oracle sid
database query script using bash
tkprof examples
executing Oracle procedure from bash script
tkprof with sid
how to create a script with multi SQL statements
Unix select examples create table
sql query report oracle unix script
sql trace shell script
bash oracle sql’s result to file
how do i sort the expensive sql using tkprof
bash script sql select *
running session script in oracle
how can i insert script in linux oracle
Creating simple utility programs using Bash shell scripts on Linux platform
shell sql examples
mysql bash sql
oracle tkprof 10g
tkprof top sql sort options exeela fchela
tkprof for sql
call V$ query from unix script
i don’t need elapsed time getting from sql in shell script
bash shell oracle sql file
shell pass parameter SQL script
how to trace oracle user session using system triggers
how to find tkprof location in linux system
examples of sql bash shell scripts
bash sql запрос
tkprof sort total elapsed
running mysql statements and capturing data in linux shell script
SQL TRACE utility in Pro*c
create bash script that report date/time
sql in bash script
tkprof for the trace file with sort=exeela,prsela,fchela
bash shell script + Mysql + insert a record
enable trace file in pro*c
v$session en scripts linux
pro*C exec sql alter session rules sh
INSERT query sql script
bash oracle
change user’s password in linux using script
generating reports through shell script
unix bash sql select command
bash shell oracle
how to use tkprofed
trigger mysql script bash
“.sql” bash file variables
before report trigger for print in oracle reports
oracle tkprof sql statement
oracle trace tkprof sort
to enable trace for shell script program + Oracle
tkprof sort time=
multiple session in unix script
bash insert sql querry in script
tkprof tuning blog
exeela cpu elapsed
sample triggers using v$session table
bash script sql database query to file

Post to Twitter  Post to Delicious  Post to Digg    Post to StumbleUpon

Categories : 11i DBA Scripts, 11i Scripts, Scripts Oracle, Scripts Unix Tags : , , , ,

Comments

No comments yet.


Leave a comment

(required)

(required)