You are on page 1of 66

Using SQLTRACE to Optimize and Test your Systems

Hyun-Ju Vega IBM


Session: D17 Wednesday, April 29, 2009 03:30 p.m. 04:30 p.m.

2009 IIUG Informix Conference

Overview
What is SQLTRACE ?
Feature description Ways to view info onstat g his sysmaster tables OAT

What can I do with SQLTRACE ?


Query Drill-down Transaction information

Saving SQLTRACE info Latest SQLTRACE features in 11.50.UC3


International Informix Users Group 2

-2-

2009 IIUG Informix Conference

What is SQLTRACE?
SQLTRACE is a new feature in IDS 11 that allows you to collect SQL statement history information, including statistics and resource usage at the statement level. Each trace information includes
Optimizer statistics (like SET Explain and EXPLAIN_STAT) Iterator database and table names are available in MED mode Buffer and read/write statistics (like in onstat p) SQL info like onstat g sql (database name, session id, database isolation level, statement host variables) Host variables are only available in HIGH mode Procedure stacks are available in HIGH mode

International Informix Users Group

-3-

2009 IIUG Informix Conference

Enabling SQLTRACE
Use SQLTRACE in ONCONFIG
SQLTRACE level=high,ntraces=4000,size=2,mode=global
SQLTRACE level=(low|med|high),ntraces=<#>,size=<# (# is in kbytes)>,mode=(global|user)

Use SQL Admin API


> execute function sysadmin:task("set sql tracing on", 4000, "2k", "high", "global"); (expression) Global Tracing ON Number of Traces 4000 Trace Size 2048 Mode High

> execute function sysadmin:task("set sql tracing off"); (expression) SQL tracing off.
International Informix Users Group

-4-

2009 IIUG Informix Conference

Memory Usage
SQLTRACE level=high,ntraces=4000,size=2,mode=global

Trace buffer 1 Trace buffer 2 Trace buffer 3

Each trace buffer size has been set to ~ 2 kbytes (~ 2048 bytes). Memory allocated for SQLTRACE is 2048 * 4000 = 7.8 Mb Statement text, table names, database name, or iterator information may be truncated if the SQL statement is too large to fit in the trace buffer.

Trace buffer 4000

** Data only exists in memory !


International Informix Users Group

-5-

2009 IIUG Informix Conference

Global and User Modes


Global Mode
Traces all sql statements By default, tracing of dbcron sessions are turned off (11.50.xC3) To trace dbcron sessions, use SQLTRACE in user mode and turn on tracing for dbcron sessions

User Mode
Scenario: You want to trace a single session. Turn on SQLTRACE in USER mode, then execute function sysamin:task for the session you are interested in. > execute function sysadmin:task(set sql tracing on, 4000, 2k, high, user); > execute function sysadmin:task("set sql user tracing on ", 16);
International Informix Users Group 6

-6-

2009 IIUG Informix Conference

Can check sysmaster:sysscblst


> select sid, hex(flags) from sysmaster:sysscblst ; sid 20 19 18 17 16 3 2 (expression) 0x00000001 0x00000003 0x00020003 0x00020003 0x00020003 0x00000001 0x00000001 #define SCB_SQLTRACE_ON 0x00010000L /* SQLTRACING on */ #define SCB_SQLTRACE_OFF 0x00020000L /* SQLTRACING off */

Sessions 16, 17, and 18 are dbcron sessions by default, SQLTRACE is turned off. If the OFF flag is not set, then tracing for the session depends on the SQLTRACE mode, and in user mode, the options set for that mode.
International Informix Users Group

-7-

2009 IIUG Informix Conference

My Favorite Way to Trace


1. Select specific databases to trace for example, prod_db 2. Select specific users to trace for example, prod_user 3. Turn on SQLTRACE in user mode
execute function sysadmin:task("set sql tracing database add", prod_db"); execute function sysadmin:task("set sql tracing user add", prod_user"); execute function sysadmin:task("set sql tracing on", 4000, "2k", "high", "user");

International Informix Users Group

-8-

2009 IIUG Informix Conference

Additional Usage Tips


Scenario: You want to turn on SQLTRACE in global mode, but, you would like to turn off SQLTRACE for currently running informix sessions: > execute function > sysadmin:task(set sql tracing on, 4000, 2k, high, global); > select sysadmin:task("set sql user tracing off ", sid) from > sysmaster:syssessions where username = "informix"; Scenario: You have SQLTRACE turned on in global mode -- you want to start a session, but you do not want that session traced. Once you connect, you can execute this statement to turn off SQL tracing just for this session: > execute function sysadmin:task("set sql user tracing off");
International Informix Users Group

-9-

2009 IIUG Informix Conference

How many Trace Buffers do I need?


Depends on how many statements your system is generating (if you are tracing globally) Depends on how often you want to collect the SQLTRACE info to save to permanent storage

To view how quickly your trace buffers are filling


Can monitor sqlseen value in sysmaster:syssqltrace_info table Can check max(sql_id) in sysmaster:syssqltrace table

International Informix Users Group

- 10 -

10

2009 IIUG Informix Conference

sysmaster:syssqltrace_info
SELECT flags, ntraces, format_units(tracesize/1024,'kb') as tracesize, duration , sqlseen, dbinfo('UTC_TO_DATETIME',starttime) as starttime, CASE WHEN sqlseen >= ntraces THEN TRUNC(ntraces/decode(duration,0,1,duration),5) ELSE TRUNC(sqlseen/decode(duration,0,1,duration),5) END as sqlpersec, format_units(memoryused,'b') as mem, (CURRENT - duration UNITS second)::DATETIME YEAR TO SECOND as starttrace FROM syssqltrace_info WHERE ntraces > 0 ; select * from syssqltrace_info; flags 5649 hex is 1611 ntraces 4000 tracesize 2024 duration 778 sqlseen 1785 starttime 1233479590 memoryused 8209744
International Informix Users Group

flags 5649 ntraces 4000 tracesize 1.98 KB duration 778 sqlseen 1786 starttime 2009-02-01 01:13:10 sqlpersec 2.29562 mem 7.83 MB starttrace 2009-02-01 01:13:10

- 11 -

11

2009 IIUG Informix Conference

sysmaster:syssqltrace_info flags
#define STMT_TRACING_ON #define STMT_TRACING_OFF #define STMT_TRACING_SUSPEND #define STMT_GLOBAL_TRACING #define STMT_USER_TRACING #define #define #define #define #define #define #define #define STMT_TRC_MASK STMT_TRC_DBSNAME STMT_TRC_STATEMENT STMT_TRC_RSAM_STATS STMT_TRC_PROCEDURES STMT_TRC_ITERATORS STMT_TRC_HOST_VARS STMT_TRC_TABNAMES 0x0001 0x0002 0x0004 0x0010 0x0020 0x7F00 0x0100 0x0200 0x0400 0x0800 0x1000 0x2000 0x4000

ON, OFF, SUSPEND GLOBAL or USER MODE LOW, MED, or HIGH LEVEL Attributes

International Informix Users Group

- 12 -

12

2009 IIUG Informix Conference

Difference between Low, Med, High


LOW
Statement text section Iterator/Explain section Statement Info section Statement Statistics section Everything in LOW + database name in the statement text section + table names in the iterator/explain section + procedure stacks
Plus slight additional performance costs for MED and HIGH. Performance impact for tracing host variables info is higher on 11.10 than on 11.50. Overall, SQLTRACE LOW adds less than 2% to performance (vs no SQLTRACE).
13

MED

HIGH
Everything in MED + host variables
International Informix Users Group

- 13 -

2009 IIUG Informix Conference


Statement # 18: @ 115c1818 Database: 0x10016A Statement text: select tabid from systables where tabid = ? Iterator/Explain ================ ID Left Right 1 0 0

Example onstat g his output: LOW


Num Rows 1 Partnum Type 1048938 Index Scan

Est Cost 1

Est Rows 1

Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 Lock Waits 0

Finish Time 19:10:09

Run Time 0.0027

TX Stamp 2e50c

PDQ 0

Read % Cache 100.00 LK Wait Time (S) 0.0000 Avg Time (S) 0.0033 Actual Rows 1

Buffer IDX Read 0 Log Space 0.000 B Max Time (S) 0.0027 SQL Error 0

Page Write 0 Num Sorts 0 Avg IO Wait 0.000000 ISAM Error 0

Buffer Write 0 Disk Sorts 0 I/O Wait Time (S) 0.000000 Isolation Level LC

Write % Cache 0.00 Memory Sorts 0 Avg Rows Per Sec 372.6609 SQL Memory 10368

Total Total Executions Time (S) 1 0.0033 Estimated Cost 1 Estimated Rows 1

International Informix Users Group

- 14 -

14

2009 IIUG Informix Conference


Statement # 18: @ 115c1818 Database: db_log Statement text: select tabid from systables where tabid = ? SELECT using table [ systables ] Iterator/Explain ================ ID Left Right 1 0 0

Example output: MED

Est Cost 1

Est Rows 1

Num Rows 1

Partnum Type 1048938 Index Scan

Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 Lock Waits 0

Finish Time 19:10:09

Run Time 0.0031

TX Stamp 2e50c

PDQ 0

Read % Cache 100.00 LK Wait Time (S) 0.0000 Avg Time (S) 0.0037

Buffer IDX Read 0 Log Space 0.000 B Max Time (S) 0.0031

Page Write 0 Num Sorts 0 Avg IO Wait 0.000000 ISAM Error 0

Buffer Write 0 Disk Sorts 0 I/O Wait Time (S) 0.000000 Isolation Level LC

Write % Cache 0.00 Memory Sorts 0 Avg Rows Per Sec 325.4637 SQL Memory 10368

Total Total Executions Time (S) 1 0.0037

Estimated Estimated Actual SQL Cost Rows Rows Error 1 1 Informix Users Group 0 1 International

- 15 -

15

2009 IIUG Informix Conference


Statement # 18: @ 115c1818 Database: db_log Statement text: select tabid from systables where tabid = ? SELECT using table [ systables ] Iterator/Explain ================ ID Left Right 1 0 0 Host Variables ============== 0 integer

Example output: HIGH

Est Cost 1

Est Rows 1

Num Rows 1

Partnum Type 1048938 Index Scan

10

Statement information: Sess_id User_id Stmt Type 27 200 SELECT Statement Statistics: Page Buffer Read Read 0 4 Lock Requests 4 ... Lock Waits 0

Finish Time 19:10:09

Run Time 0.0034

TX Stamp 2e50c

PDQ 0

Read % Cache 100.00 LK Wait Time (S) 0.0000

Buffer IDX Read 0 Log Space 0.000 B

Page Write 0 Num Sorts 0

Buffer Write 0 Disk Sorts 0

Write % Cache 0.00 Memory Sorts 0

International Informix Users Group

- 16 -

16

2009 IIUG Informix Conference

Ways to view SQLTRACE info


onstat g his
Dumps out all trace buffers that have data

sysmaster tables
On 11.10, host variables info are not available through the sysmaster tables Schema for the sysmaster tables are in $INFORMIXDIR/etc/sysmaster.sql Use sql_id column to tie syssqltrace, syssqltrace_iter, syssqltrace_hvar info

OAT
sysmaster tables in 11.10 : syssqltrace sysqltrace_info sysqltrace_iter sysmaster tables in 11.50 : syssqltrace sysqltrace_info sysqltrace_iter syssqltrace_hvar
International Informix Users Group

- 17 -

17

2009 IIUG Informix Conference

OAT
Statement Types
Select, Insert, Update, Delete, Execute,

Statements that are part of the same transaction (transaction summary)


session_id, tx_stamp (sql_sid, sql_begintxtime)

International Informix Users Group

- 18 -

18

2009 IIUG Informix Conference

OAT
Can use OAT to Enable/Disable/Modify SQLTRACE options

Turns off, then turns on SQLTRACE.


International Informix Users Group

- 19 -

19

2009 IIUG Informix Conference

What can I do with the info?


Query Drill-down
Find out which queries are running slow Compare results with different settings or from different systems Keep SQL performance history

Transaction information
Can use session id and TX stamp to group statements into transactions Begin, Commit, or Rollback are not traced See what the application is doing

When using an Insert cursor or Load Statement


Will only see a trace of a single insert statement and no host variable info Number of rows inserted (sql_actualrows in syssqltrace table) will always show 1

International Informix Users Group

- 20 -

20

2009 IIUG Informix Conference

Query Drill-down and External Directives


Statement text: select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ?

Iterator/Explain ================ ID Left Right Est Cost 2 0 0 3 3 0 0 1 1 2 3 6 ... Total Total Executions Time (S) 1 0.0050 Estimated Cost 6 Estimated Rows 2

customer
Est Rows 3 23 2 Num Rows 2 1 1 Partnum 2097264 2097266 0 Type Seq Scan Index Scan Nested Join

orders

Avg Time (S) 0.0050 Actual Rows 1

Max Time (S) 0.0038 SQL Error 0

Avg IO Wait 0.000000 ISAM Error 0

I/O Wait Time (S) 0.000000 Isolation Level CR

Avg Rows Per Sec 264.0452 SQL Memory 19152

International Informix Users Group

- 21 -

21

2009 IIUG Informix Conference

Query Drill-down (contd)


Statement text: select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ?
Iterator/Explain ================ ID Left Right Est Cost 2 0 0 3 3 0 0 1 1 2 3 6 ... Total Total Executions Time (S) 1 6.8766 Estimated Cost 6 Estimated Rows 2

customer
Est Rows 3 23 2 Num Rows 16384 1 1 Partnum 2097264 2097266 0 Type Seq Scan Index Scan Nested Join

orders

Avg Time (S) 6.8766 Actual Rows 1

Max Time (S) 4.5851 SQL Error 0

Avg IO Wait 0.000000 ISAM Error 0

I/O Wait Time (S) 0.000000 Isolation Level CR

Avg Rows Per Sec 0.2181 SQL Memory 19152

International Informix Users Group

- 22 -

22

2009 IIUG Informix Conference

Query Drill-down (contd)

International Informix Users Group

- 23 -

23

2009 IIUG Informix Conference

Query Drill-down (contd)

International Informix Users Group

- 24 -

24

2009 IIUG Informix Conference

Query Drill-down (contd)

International Informix Users Group

- 25 -

25

2009 IIUG Informix Conference

Query Drill-down (contd)

Seq Scan is on the customer table rows processed is 16384. Index Scan is on the orders table rows processed is 23. What is this telling you ?

International Informix Users Group

- 26 -

26

2009 IIUG Informix Conference

Query Drill-down: Add External Directive


Until you can run update statistics, you decide to use external directives to improve query performance.

Adding and applying directives here is same executing following in stores_demo:


save external directives {+FULL(orders), INDEX(customer 100_1)} active for select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num =o.customer_num and c.state = ?;

** Check that the directive has been added to stores_demo: sysdirectives .

International Informix Users Group

- 27 -

27

2009 IIUG Informix Conference

Query Drill-down (contd)

Response time is much better after the external directive has been applied.

International Informix Users Group

- 28 -

28

2009 IIUG Informix Conference

Query Drill-down (contd)

After the External Directive: Seq Scan is now on the orders table rows processed is 23. Index Scan is now on the customer table.

International Informix Users Group

- 29 -

29

2009 IIUG Informix Conference

Query Drill-down (final onstat g his)


Statement text: select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ?

Iterator/Explain ================ ID Left Right Est Cost 2 0 0 2 3 0 0 1 1 2 3 9 ... Total Total Executions Time (S) 1 0.0119 Estimated Cost 9 Estimated Rows 2

orders
Est Rows 23 3 2 Num Rows 23 1 1 Partnum 2097266 2097264 0 Type Seq Scan Index Scan Nested Join

customer

Avg Time (S) 0.0119 Actual Rows 1

Max Time (S) 0.0084 SQL Error 0

Avg IO Wait 0.000000 ISAM Error 0

I/O Wait Time (S) 0.000000 Isolation Level CR

Avg Rows Per Sec 118.7306 SQL Memory 20328

International Informix Users Group

- 30 -

30

2009 IIUG Informix Conference

Query Drill-down (final OAT View)

International Informix Users Group

- 31 -

31

2009 IIUG Informix Conference

EXT_DIRECTIVES (ONCONFIG parameter)


EXT_DIRECTIVES 2 EXT_DIRECTIVES
0 Disabled 1 Enabled if the IFX_EXTDIRECTIVES environment variable is set. 2 Enabled even if the IFX_EXTDIRECTIVES environment is not set.

Can also use SET ENVIRONMENT EXTDIRECTIVES in a session with options


0 or OFF 1 or ON DEFAULT set environment extdirectives 0 set environment extdirectives 1 set environment extdirectives default
- 32 No quotes!
32

International Informix Users Group

2009 IIUG Informix Conference

Checking sysdirectives
dbaccess stores_demo > select * from sysdirectives;
id 2 query select c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ? directive FULL(orders), INDEX(customer 100_1) directivecode <BYTE value> active 1 hashcode -1903458431

International Informix Users Group

- 33 -

33

2009 IIUG Informix Conference

Query Drill-down and DS_NONPDQ_QUERY_MEM


Using SQLTRACE info to help determine a setting for DS_NONPDQ_QUERY_MEM Example of command to change DS_NONPDQ_QUERY_MEM value dynamically onmode -wm DS_NONPDQ_QUERY_MEM=1024
select * from sysmaster:sysconfig where cf_name = "DS_NONPDQ_QUERY_MEM";
cf_id cf_name cf_flags cf_original cf_effective cf_default 251 DS_NONPDQ_QUERY_MEM 0 128 1024 128

International Informix Users Group

- 34 -

34

2009 IIUG Informix Conference

Improving Create Index Time


Drill-down to Check Create Index Performance

International Informix Users Group

- 35 -

35

2009 IIUG Informix Conference

Query Drill-down Example 2


DS_NON_PDQ_QUERY_MEM values

8192 4096 2048 128, default

International Informix Users Group

- 36 -

36

2009 IIUG Informix Conference

sql_id 3: 128 (3.17 response time)

International Informix Users Group

- 37 -

37

2009 IIUG Informix Conference

sqlid 5: 2048 (2.30 response)

International Informix Users Group

- 38 -

38

2009 IIUG Informix Conference

sqlid 7: 4096 (1.93 response)

International Informix Users Group

- 39 -

39

2009 IIUG Informix Conference

sqlid 9: 8192 (1.89 response)

International Informix Users Group

- 40 -

40

2009 IIUG Informix Conference

Transactions
In a single session, ran 3 transactions Info from onstat g his output TX Stamp: 10bcd4a Statement #: 1 Statement #: 0 TX Stamp: 10bcd51 Statement #: 2 TX Stamp: 10bcd53 Statement #: 3

Which one of these statements ran first in the transaction?

select col1 from tab1 where col2=? insert into tab1 values (0,100, ?) select col2 from tab1 where col3 matches ? delete from tab1 where col2 = ? ** Transaction was rolled back, but you cannot tell from the SQLTRACE info.
- 41 41

International Informix Users Group

2009 IIUG Informix Conference

Transactions (syssqltrace table)


Transactions can only be grouped within a session Within a session, statements that belong to the same transaction have the same sql_begintxtime
select a.sql_id, a.sql_statement, b.sql_hvar_data from sysmaster:syssqltrace a, sysmaster:syssqltrace_hvar b where a.sql_begintxtime = 17554506 and a.sql_sid = 47 and a.sql_id = b.sql_id order by sql_id desc; sql_id 1 sql_statement select col1 from tab1 where col2=? sql_hvar_data 10 sql_id 0 sql_statement insert into tab1 values (0,100, ?) sql_hvar_data smile
International Informix Users Group

- 42 -

42

2009 IIUG Informix Conference

Transactions (OAT View)

10bcd53 10bcd51 10bcd4a

International Informix Users Group

- 43 -

43

2009 IIUG Informix Conference

Quiz
TRUE or FALSE?
Statements in different sessions that have the same sql_begintxtime are part of the same transaction.

TRUE or FALSE?
Transaction stamp in OAT and TX Stamp in onstat g his output are the same.

TRUE or FALSE?
sql_begintxtime and transaction stamp in OAT are the same.

International Informix Users Group

- 44 -

44

2009 IIUG Informix Conference

One Transaction View

This transaction has statement numbers 0 and 1.


International Informix Users Group

- 45 -

45

2009 IIUG Informix Conference

Different Transaction View

This transaction has statement number 2.


International Informix Users Group

- 46 -

46

2009 IIUG Informix Conference

onstat g his view


Statement # 1: @ 10d06b828 Database: testdb Statement text: select col1 from tab1 where col2=? SELECT using tables [ tab1 ] Iterator/Explain ================ ID Left Right 1 0 0 Host Variables ============== 0 integer

Est Cost 2

Est Rows 3

Num Rows 1

Partnum Type 1049476 Seq Scan

10

Statement information: Sess_id User_id Stmt Type 47 37108 SELECT Statement Statistics: Page Buffer Read Read 3 7

Finish Time 21:37:31

Run Time 0.0430

TX Stamp 10bdc4a

PDQ 0

Read % Cache 57.14

Buffer IDX Read 0

Page Write 0

Buffer Write 2

Write % Cache 100.00

International Informix Users Group

- 47 -

47

2009 IIUG Informix Conference

onstat g his view


Statement # 0: @ 10d06b028 Database: testdb Statement text: insert into tab1 values (0,100, ?) INSERT using tables [ tab1 ] Iterator/Explain ================ ID Left Right 1 0 0 Host Variables ============== 0 char

Est Cost 1

Est Rows 1

Num Rows 1

Partnum Type 1049476 Insert

smile

Statement information: Sess_id User_id Stmt Type 47 37108 INSERT Statement Statistics: Page Buffer Read Read 1 3

Finish Time 21:37:31

Run Time 0.0005

TX Stamp 10bdc4a

PDQ 0

Read % Cache 66.67

Buffer IDX Read 0

Page Write 0

Buffer Write 2

Write % Cache 100.00

International Informix Users Group

- 48 -

48

2009 IIUG Informix Conference

Procedure Stack Example


Session executing a stored procedure with a host variable. onstat -g his output shows which statements are being traced from inside a procedure statements have the label Procedure Call Stack: instead of Statement Text: syssqltrace output does not have the Procedure Call Stack information
create procedure check_order(p_order_num int) define p_ship_date like orders.ship_date; select ship_date into p_ship_date from orders where order_num = p_order_num; if p_ship_date is null then execute procedure notify_shipping(p_order_num); -- notify_shipping inserts into table need_ship_date -- table need_ship_date has an insert trigger which updates table orders -- table orders has an update trigger which calls procedure log_updates -- log_updates updates a column in need_ship_date table
International Informix Users Group

- 49 -

49

2009 IIUG Informix Conference

Procedure Trace from onstat g his


sql_id 6 sql_id 5 sql_id 4 Statement Text: execute procedure check_order(?) Procedure Call Stack: testdb:check_order() Procedure Call Stack: testdb:notify_shipping() <-- testdb:check_order() INSERT using table [ need_ship_date ] sql_id 3 Procedure Call Stack: testdb:notify_shipping() <-- testdb:check_order() UPDATE using tables [ orders ]
International Informix Users Group

- 50 -

50

2009 IIUG Informix Conference

Procedure Trace from onstat g his


sql_id 2 Procedure Call Stack: testdb:notify_shipping() <-- testdb:check_order() Procedure Call Stack: testdb:log_updates() <-- testdb:notify_shipping() <-- testdb:check_order() UPDATE using table [ need_ship_date ] sql_id 0 Procedure Call Stack: testdb:check_order() SELECT using tables [ orders ]
International Informix Users Group

sql_id 1

- 51 -

51

2009 IIUG Informix Conference

syssqltrace (No Procedure Call Stack Label)


sql_id 6 sql_statement execute procedure check_order(?) sql_stmtname EXEC PROCEDURE sql_tablelist None sql_id 5 sql_statement testdb:check_order() sql_stmtname EXEC PROCEDURE sql_tablelist None sql_id 4 sql_statement testdb:notify_shipping() <-- testdb:check_order() sql_stmtname INSERT sql_tablelist need_ship_date

> select sql_id, sql_statement, sql_stmtname, sql_tablelist from sysmaster:syssqltrace where sql_begintxtime = 17555740 and sql_sid = 93;
52

International Informix Users Group

- 52 -

2009 IIUG Informix Conference

syssqltrace (contd)
sql_id 3 sql_statement testdb:notify_shipping() <-- testdb:check_order() sql_stmtname UPDATE sql_tablelist orders sql_id 1 sql_statement testdb:log_updates() <-- testdb:notify_shipping() <-- testdb:check_order() sql_stmtname UPDATE sql_tablelist need_ship_date

sql_id 2 sql_statement testdb:notify_shipping() <-- testdb:check_order() sql_stmtname EXEC PROCEDURE sql_tablelist None

sql_id 0 sql_statement testdb:check_order() sql_stmtname SELECT sql_tablelist orders

International Informix Users Group

- 53 -

53

2009 IIUG Informix Conference

OAT (No Procedure Call Stack Label)

International Informix Users Group

- 54 -

54

2009 IIUG Informix Conference

OAT Transaction SQL List

International Informix Users Group

- 55 -

55

2009 IIUG Informix Conference

Saving SQLTRACE info


onstat g his
Can only grab snapshots of the trace buffers Always dumps all the trace buffers

sysmaster tables
Write your own SQL to select from syssqltrace* tables into your own permanent tables

Using Dbcron and sysmaster tables


Write an SPL to be executed by Dbcron

Use the new OAT feature that will allows you to save sysmaster:syssqltrace* tables info into permanent tables
International Informix Users Group 56

- 56 -

2009 IIUG Informix Conference

OAT automatically creates a task

International Informix Users Group

- 57 -

57

2009 IIUG Informix Conference

How OAT Saves SQLTRACE Info


When you first hit the Switch to Saved Data button
OAT creates the following tables in sysadmin database mon_syssqltrace, mon_syssqltrace_iter, mon_syssqltrace_hvar, mon_syssqltrace_info OAT creates an SPL procedure called sql_showsnap in sysadmin OAT inserts a task into sysadmins ph_task table to schedule the execution of sql_showsnap (by default, runs every 15 minutes between 6 am and 6 pm) select * from ph_task where tk_name = Save SQL Trace;

sql_showsnap procedure selects new traces in SQL buffer and inserts into mon_syssqltrace* tables Use dbschema -d sysadmin -f sql_showsnap to view the text of the sql_showsnap procedure
International Informix Users Group 58

- 58 -

2009 IIUG Informix Conference

sql_showsnap
CREATE FUNCTION sql_showsnap(task_id INTEGER, seq_id INTEGER) RETURNING INTEGER The task_id and the seq_id are inserted by the DB Scheduler from the tk_id and tk_sequence from the ph_task table The values also correspond to the run_task_id and run_task_seq in the ph_run table sql_showsnap returns the number of rows inserted into mon_syssqltrace table (stored in run_retcode column of ph_run table) Data in mon_syssqltrace* tables are deleted after 1 day (specified by tk_delete interval value in ph_task table)
International Informix Users Group

- 59 -

59

2009 IIUG Informix Conference

View Save Trace Runs


select * from ph_run where run_task_id = ( select tk_id from ph_task where tk_name = Save SQL Trace ) order by run_task_seq ;

International Informix Users Group

- 60 -

60

2009 IIUG Informix Conference

Toggle Between Saved and Live Data

Can view SQLTRACE information collected previously.

International Informix Users Group

- 61 -

61

2009 IIUG Informix Conference

OAT Displaying Saved Data

Previously collected SQLTRACE info being shown from the data saved by Save SQL Trace task.
International Informix Users Group

- 62 -

62

2009 IIUG Informix Conference

New options in 11.50.xC3


SQLTRACE SUSPEND and RESUME SQLTRACE off (by default) for Dbcron threads

Execute sysadmin:task (...) (Set SQL Tracing INFO) (Set SQL Tracing RESIZE, number, size, mode) (Set SQL Tracing RESUME) (Set SQL Tracing SESSION) (Set SQL Tracing SUSPEND)

International Informix Users Group

- 63 -

63

2009 IIUG Informix Conference

New options in 11.50.xC3


SQLTRACE database level filter SQLTRACE user name filter
Execute sysadmin:task (...) (Set SQL Tracing database ADD, database_name) (Set SQL Tracing database REMOVE, database_name) (Set SQL Tracing database LIST) (Set SQL Tracing database CLEAR) Execute sysadmin:task (...) (Set SQL Tracing user ADD, user_name) (Set SQL Tracing user REMOVE, user_name) (Set SQL Tracing user LIST) Be careful ! Clears the ** (Set SQL Tracing user CLEAR) default option NOT to trace dbcron sessions.
International Informix Users Group

- 64 -

64

2009 IIUG Informix Conference

My Favorite Way to Trace


Turn ON SQLTRACE
execute function sysadmin:task(set sql tracing database CLEAR); execute function sysadmin:task(set sql tracing database ADD, prod_db); execute function sysadmin:task(set sql tracing user ADD, prod_user); execute function sysadmin:task(set sql tracing database LIST); execute function sysadmin:task(set sql tracing user LIST); execute function sysadmin:task(set sql tracing on, 4000, 2k, high, user);

Turn OFF SQLTRACE


execute function sysadmin:task(set sql tracing off);

International Informix Users Group

- 65 -

65

2009 IIUG Informix Conference


Session: D17
Using SQLTRACE to Optimize and Test your Systems

Hyun-Ju Vega
IBM vegah@us.ibm.com

International Informix Users Group

- 66 -

66

You might also like