The DB2 trace facility (db2trc command) lets you trace events, dump the trace data to a file, and format the data into a readable form. You may be requested by DB2 Customer Service to take a trace if the db2diag.log file is not enough to diagnose a problem.
DB2 trace information is stored either in memory or on disk. When it is being collected, the information is recorded in chronological order.
The amount of information gathered by a trace grows rapidly. Thus, you want to capture only the error situation and avoid any other activities (for example, starting the database manager instance with db2start or connecting to a database with db2 CONNECT). When taking a trace, reproduce the smallest scenario that can be re-created and capture it for further analysis.
The process of performing a trace has a global effect on the behavior of a DB2 instance. The degree of performance degradation is dependent on the type of problem and on how many resources are being used to gather the trace information.
Depending on your platform, there are various ways to perform a trace. For example, on UNIX-based systems, you must use the db2trc command.
Before you Begin
Before attempting to use the DB2 trace facility, consider the following:
Using Trace Facility (db2trc) Commands
The DB2 trace facility tracing is activated by the db2trc on command. This command has various parameters you can use to control the amount and type of data collected.
The syntax for the db2trc command is shown below. Explanations of the parameters follow.
>>- db2trc--+--------------------------------------------------------+-> | .-----------------------------------------------. | | V | | +- on-----+-----------------------------------------+--+-+ | | .-.------------------------------. | | | | V | | | | +- -m----+- *------------------------+--+-+ | | | | .-,--------------------. | | | | | | V | | | | | | '------ num--+-------+----+-' | | | | '- -num-' | | | +- -e-- max_sys_errors--------------------+ | | +- -r-- max_record_size-------------------+ | | +- -f-- filename--------------------------+ | | +-+- -l--+---------------+-+--------------+ | | | | '- buffer_size--' | | | | | '- -i--+---------------+-' | | | | '- buffer_size--' | | | '- -t-------------------------------------' | +- off---------------------------------------------------+ +- dump-- filename---------------------------------------+ +- flw-- dump_file-- output_file-------------------------+ '- fmt-- dump_file-- output_file-------------------------' >--------------------------------------------------------------><
Parameters
You must issue the db2trc command several times to turn tracing on, produce a dump file, format the dump file, and turn tracing off. The following list represents the order in which you use the parameters:
db2trc dump db2trc.dmp
You must specify a file name with this parameter. The file is saved in the current directory unless you explicitly specify a path.
db2trc off
db2trc flw db2trc.dmp db2trc.flw db2trc fmt db2trc.dmp db2trc.fmt
These options are provided for you to verify the trace. In most cases, only the dump file should be sent to DB2 Customer Service.
To start the trace facility, type db2trc on. The default trace option values are:
Occasionally, you may be instructed to specify options to tailor the trace. Use the following options only as directed by DB2 Customer Service:
If DB2 Customer Service requires mask values different from the default values, you will be instructed on which values to use.
Use either of these options to specify the buffer size.
Trace information may or may not be helpful in diagnosing an error. For example, it may not capture the error condition in the following situations:
To verify that a trace file can be read, format the binary trace file to show the flow control and send the formatted output to a null device. The following example shows the command to perform this task:
db2trc flw example.trc nul
The output for this command will explicitly tell you if there is a problem reading the file, and whether or not the trace was wrapped.
The following examples provide several scenarios to show you how to use db2trc.
Tracing to memory is the preferred method of tracing. The size of the trace buffer is specified as 4 MB in this example.
db2trc on -l 4000000 -e -1
db2trc dump db2trc.dmp
(Dump the trace immediately after the problem occurs. Otherwise an SQL error that occurs after the error is captured may cause important information to be lost.)
db2trc off
Tracing to a file is useful when the problem being re-created suspends the workstation, preventing you from dumping the trace to a file. When you trace to a file, each trace entry is written to disk when it happens. The information in the file captures those events leading up to (but not including) the suspension.
In this example, the size of the file is specified as 4 MB and the name of the file is db2trc.dmp:
db2trc on -l 4000000 -e -1 -f db2trc.dmp
The db2trc.dmp file will be present when you reboot your workstation. It will contain the events leading up to the event that caused the system to crash.
Problem: The SQL1042C error message is received when trying to connect to a database from a client. Access to the database is not possible.
Approach: To find the solution to the problem, first find the location of the error. Because the error occurs on the client, start by looking for the error on the client. To do this, look at the db2diag.log file on the client machine. For more information, see Interpreting the db2diag.log file.
Assume that the db2diag.log file on the client machine contains no entries. Look at the db2diag.log file on the DB2 server machine to see if an error has occurred on the server.
Assume that the db2diag.log file on the server contains the
following entries:
1997-03-16-08:54:37.001160 Instance:payroll Node:000 PID:74467(db2syscs (SAMPLE)) Appid:*LOCAL.payroll.970317140834 buffer_pool_services sqlbStartPools Probe:0 Database:SAMPLE Starting the database. (1) 1997-03-16-08:54:38.001160 Instance:payroll Node:000 PID:74467(db2syscs (SAMPLE)) Appid:*LOCAL.payroll.970317140834 data_protection sqlpresr Probe:0 Database:SAMPLE Crash Recovery has been initiated. (2) 1997-03-16-08:54:38.001160 Instance:payroll Node:000 PID:74467(db2syscs (SAMPLE)) Appid:*LOCAL.payroll.970317140834 data_protection sqlpresr Probe:0 Database:SAMPLE Low transaction lsn: 0000 005d c00c 1997-03-16-08:54:38.001160 Instance:payroll Node:000 PID:74467(db2syscs (SAMPLE)) Appid:*LOCAL.payroll.970317140834 data_protection sqlpresr Probe:0 Database:SAMPLE Minimum buffer lsn: 0000 005d c00c 1997-03-16-08:54:38.001160 Instance:payroll Node:000 PID:74467(db2syscs (SAMPLE)) Appid:*LOCAL.payroll.970317140834 data_management (5) sqldmund Probe:375 Database:SAMPLE Error during undo. (3) 0ae6 ffff 0ae6 ffff 0000 005e efa2 6363 (4) |
Interpretation:
Approach: Unfortunately, the db2diag.log file does not contain information to help us determine which file is missing. We must proceed by taking a trace of the error condition and scanning for the E60A error code in the trace file.
Assume that the trace file looks like the following:
3478 DB2 non-fatal_err oper_system_services sqloopenp (1.4.15.140) pid 55; tid 38; cpid 112; time 365535; trace_point 6 433a 5c44 4232 5c53 514c 3030 3030 315c /DB2/SQL00001/ 5351 4c54 3030 3032 2e30 5c53 514c 3030 SQLT0002.0/SQL00 3031 302e 4441 54 010.DAT (2) 3479 DB2 cei_data oper_system_services sqloopenp (1.25.15.140) pid 55; tid 38; cpid 112; time 365535; trace_point 7 ffff ffff 3480 DB2 cei_errcode oper_system_services sqloopenp (1.6.15.140) pid 55; tid 38; cpid 112; time 365535; trace_point 254 return_code = 0xffffe60a (1) = -6646 = SQLO_FNEX |
Interpretation:
Solution: Restore from a backup known to be good, and roll forward to the end of the logs to ensure that no data is lost.