You are on page 1of 3

USING SQL*TRACE AND TKPROF IN ORACLE APPLICATIONS

SQL*TRACE SQL*Trace is a database tool that analysts or customers can use to debug certain problems in Oracle Applications. SQL*Trace creates a file containing all SQL statements, and statistics for each statement executed during a users session. This file can later be reviewed to determine: what SQL statements were executed how long and how much CPU time each script took, and how the database was accessed by each statement

SQL*Trace is especially useful for performance issues. Oracle developers normally ask for a 'trace output' in order to determine what the process is doing at the database level. SQL*Trace can also be helpful in identifying the SQL scripts that are causing problems. For example: a process suddenly terminates with an ORA error Quick Pick does not return an expected value a query in a form does not return an expected value

SQL*Trace can be activated from the menu for Form level problems, but it must be turned on at the database level for processes run by the Concurrent Manager (such as executables and Oracle Reports).

TKPROF TKPROF is a tool (bundled with Oracle RDBMS V6 or later) that can be used to format the SQL*Trace file which can be cryptic. It can provide timed statistics on various parameters such as SQL parse times, execute and fetch times.

RUNNING SQL*TRACE AT THE DATABASE LEVEL You can follow the steps listed below to turn SQL*Trace on at the database level and to produce an output. NOTE: This process should be performed by your database administrator. 1. Save a copy of your INIT.ORA or CONFIG.ORA file (see Server Administration Guide, Appendix A) 2. Edit your INIT.ORA or CONFIG.ORA - This file resides under $ORACLE_HOME/dbs - The INIT.ORA is read when the database is started. - The following INIT.ORA parameters must be set: SQL_TRACE = TRUE

USER_DUMP_DEST = <preferred directory for the trace output> TIMED_STATISTICS = TRUE MAX_DUMP_FILE_SIZE = <optional, determines trace output file size> 3. Shutdown the Concurrent Manager first, then shut down the Database. Make sure there are no users on the system. 4. Then Restart the Database and Concurrent Manager. 5. Run the process. SUGGESTION: You should not have other users on the system while SQL*Trace is on, and you should only run the process in question. This will make troubleshooting a much easier task. 6. Check the USER_DUMP_DEST directory for the trace output. Use the following script to determine the directory the trace file is located: Select value from v$parameter where name = 'user_dump_dest'; 7. Locate the trace file for your process. The file(s) are suffix with a .trc. - If there are multiple trace files, check the creation date to determine the file that is yours. In UNIX, use 'ls -lrt'. - If there are multiple files for the same session, they may all be relevant. 8. After running the process with SQL*Trace on, shutdown and restart the database with the original INIT.ORA.

RUNNING SQL TRACE ON A FORM 1. Get to the point in the Form where you want to turn Tracing on. For example, if the problem occurs on the commit, wait until you are ready to commit, then turn Trace on. 2. To turn Tracing on, select Help ---> Tools ----> Trace from the menu 3. Execute the steps you wish to trace. 4. Then select Help ---> Tools ---> Trace again, to stop tracing. 5. The trace file is written to the file specified in the 'user_dump_dest' parameter in the INIT.ORA file.

USING TKPROF TO FORMAT THE TRACE FILE The trace file contains statistics on the amount of time it takes to run a SQL script. TKPROF formats the file so that it is easier to read the statistics. Before you run TKPROF on your trace file, verify that the table, PLAN_TABLE exists. If it does not, read page B-11 of the Server Application Developer's Guide to find the command.

TKPROF format: tkprof tracefile outputfile [explain= ] [table= ] [print= ] [insert= ] [sys= ] [sort= ] Examples: 1. tkprof ora_11598.trc 2. tkprof ora_11598.trc 3. tkprof ora_11598.trc 4. tkprof ora_23532.trc

myfilename /tmp/myfilename /tmp/myfilename explain=ap/ap myfilename explain=po/po sort=execpu

In order to create the tkprof file you must have write access to the directory that you are creating the file. You can use the /tmp directory as it is directory that general users have write access. (See example 2 above). You can type <tkprof> at the operating system prompt to display more information on the usage of tkprof, and its optional parameters. EXPLAIN You should use the parameter, Explain if the issue is a performance problem. Explain should be followed by the userid/passwd of the product that SQL*Trace was executed from. SORT Use the Sort parameter to sort the SQL scripts by CPU execution time. The SQL scripts that use the most CPU time will be listed at the top of the file. This is helpful for identifying performance problems in a large trace file.

REFERENCE PRE:1008743.6 TUNING QUERY AND APPLICATION USING EXPLAIN & TKPROF Server Application Developer's Guide, Appendix B Topic: SQL*Trace

You might also like