Upload
viorel-panaite
View
256
Download
0
Embed Size (px)
Citation preview
Using SQLTRACE to Optimize and Test your Systems
Hyun-Ju VegaIBM
Wednesday, April 29, 2009 • 03:30 p.m. – 04:30 p.m.
Session: D17
- 2 -
2009 IIUG Informix Conference
International Informix Users Group 2
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
- 3 -
2009 IIUG Informix Conference
International Informix Users Group 3
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
- 4 -
2009 IIUG Informix Conference
International Informix Users Group 4
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.
- 5 -
2009 IIUG Informix Conference
International Informix Users Group 5
Memory Usage• SQLTRACE level=high,ntraces=4000,size=2,mode=global
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.
** Data only exists in memory !
Trace buffer 4000
Trace buffer 3Trace buffer 2Trace buffer 1
- 6 -
2009 IIUG Informix Conference
International Informix Users Group 6
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 ModeScenario: 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);
- 7 -
2009 IIUG Informix Conference
International Informix Users Group 7
Can check sysmaster:sysscblst
#define SCB_SQLTRACE_ON 0x00010000L /* SQLTRACING on */
#define SCB_SQLTRACE_OFF 0x00020000L /* SQLTRACING off */
> select sid, hex(flags) from sysmaster:sysscblst ;
sid (expression)
20 0x0000000119 0x0000000318 0x0002000317 0x0002000316 0x000200033 0x000000012 0x00000001
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.
- 8 -
2009 IIUG Informix Conference
International Informix Users Group 8
My Favorite Way to Trace
1. Select specific databases to trace – for example, prod_db2. Select specific users to trace – for example, prod_user3. 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");
- 9 -
2009 IIUG Informix Conference
International Informix Users Group 9
Additional Usage TipsScenario: 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");
- 10 -
2009 IIUG Informix Conference
International Informix Users Group 10
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
- 11 -
2009 IIUG Informix Conference
International Informix Users Group 11
sysmaster:syssqltrace_info
select * from syssqltrace_info;
flags 5649 hex is 1611ntraces 4000tracesize 2024duration 778sqlseen 1785starttime 1233479590memoryused 8209744
flags 5649ntraces 4000tracesize 1.98 KBduration 778sqlseen 1786starttime 2009-02-01 01:13:10sqlpersec 2.29562mem 7.83 MBstarttrace 2009-02-01 01:13:10
SELECT flags, ntraces, format_units(tracesize/1024,'kb') as tracesize,duration , sqlseen, dbinfo('UTC_TO_DATETIME',starttime) as starttime,CASE WHEN sqlseen >= ntracesTHEN 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 starttraceFROM syssqltrace_info WHERE ntraces > 0 ;
- 12 -
2009 IIUG Informix Conference
International Informix Users Group 12
sysmaster:syssqltrace_info flags
#define STMT_TRACING_ON 0x0001#define STMT_TRACING_OFF 0x0002#define STMT_TRACING_SUSPEND 0x0004
#define STMT_GLOBAL_TRACING 0x0010#define STMT_USER_TRACING 0x0020
#define STMT_TRC_MASK 0x7F00#define STMT_TRC_DBSNAME 0x0100#define STMT_TRC_STATEMENT 0x0200#define STMT_TRC_RSAM_STATS 0x0400#define STMT_TRC_PROCEDURES 0x0800#define STMT_TRC_ITERATORS 0x1000#define STMT_TRC_HOST_VARS 0x2000#define STMT_TRC_TABNAMES 0x4000
ON, OFF, SUSPEND
GLOBAL or USER MODE
LOW, MED, or HIGH
LEVEL Attributes
- 13 -
2009 IIUG Informix Conference
International Informix Users Group 13
Difference between Low, Med, High• LOW
Statement text section Iterator/Explain section Statement Info section Statement Statistics section
• MED Everything in LOW + database name in the statement text section + table names in the iterator/explain section + procedure stacks
• HIGH Everything in MED + host variables
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).
- 14 -
2009 IIUG Informix Conference
International Informix Users Group 14
Statement # 18: @ 115c1818
Database: 0x10016AStatement text:select tabid from systables where tabid = ?
Iterator/Explain================
ID Left Right Est Cost Est Rows Num Rows Partnum Type1 0 0 1 1 1 1048938 Index Scan
Statement information:Sess_id User_id Stmt Type Finish Time Run Time TX Stamp PDQ27 200 SELECT 19:10:09 0.0027 2e50c 0
Statement Statistics:Page Buffer Read Buffer Page Buffer WriteRead Read % Cache IDX Read Write Write % Cache0 4 100.00 0 0 0 0.00
Lock Lock LK Wait Log Num Disk MemoryRequests Waits Time (S) Space Sorts Sorts Sorts4 0 0.0000 0.000 B 0 0 0
Total Total Avg Max Avg I/O Wait Avg RowsExecutions Time (S) Time (S) Time (S) IO Wait Time (S) Per Sec1 0.0033 0.0033 0.0027 0.000000 0.000000 372.6609
Estimated Estimated Actual SQL ISAM Isolation SQLCost Rows Rows Error Error Level Memory1 1 1 0 0 LC 10368
Example onstat –g his output: LOW
- 15 -
2009 IIUG Informix Conference
International Informix Users Group 15
Statement # 18: @ 115c1818
Database: db_logStatement text:select tabid from systables where tabid = ?
SELECT using table [ systables ]
Iterator/Explain================
ID Left Right Est Cost Est Rows Num Rows Partnum Type1 0 0 1 1 1 1048938 Index Scan
Statement information:Sess_id User_id Stmt Type Finish Time Run Time TX Stamp PDQ27 200 SELECT 19:10:09 0.0031 2e50c 0
Statement Statistics:Page Buffer Read Buffer Page Buffer WriteRead Read % Cache IDX Read Write Write % Cache0 4 100.00 0 0 0 0.00
Lock Lock LK Wait Log Num Disk MemoryRequests Waits Time (S) Space Sorts Sorts Sorts4 0 0.0000 0.000 B 0 0 0
Total Total Avg Max Avg I/O Wait Avg RowsExecutions Time (S) Time (S) Time (S) IO Wait Time (S) Per Sec1 0.0037 0.0037 0.0031 0.000000 0.000000 325.4637
Estimated Estimated Actual SQL ISAM Isolation SQLCost Rows Rows Error Error Level Memory1 1 1 0 0 LC 10368
Example output: MED
- 16 -
2009 IIUG Informix Conference
International Informix Users Group 16
Statement # 18: @ 115c1818
Database: db_logStatement text:select tabid from systables where tabid = ?
SELECT using table [ systables ]
Iterator/Explain================
ID Left Right Est Cost Est Rows Num Rows Partnum Type1 0 0 1 1 1 1048938 Index Scan
Host Variables==============0 integer 10
Statement information:Sess_id User_id Stmt Type Finish Time Run Time TX Stamp PDQ27 200 SELECT 19:10:09 0.0034 2e50c 0
Statement Statistics:Page Buffer Read Buffer Page Buffer WriteRead Read % Cache IDX Read Write Write % Cache0 4 100.00 0 0 0 0.00
Lock Lock LK Wait Log Num Disk MemoryRequests Waits Time (S) Space Sorts Sorts Sorts4 0 0.0000 0.000 B 0 0 0
...
Example output: HIGH
- 17 -
2009 IIUG Informix Conference
International Informix Users Group 17
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
- 18 -
2009 IIUG Informix Conference
International Informix Users Group 18
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)
- 19 -
2009 IIUG Informix Conference
International Informix Users Group 19
OAT• Can use OAT to Enable/Disable/Modify SQLTRACE options
Turns off, then turns on SQLTRACE.
- 20 -
2009 IIUG Informix Conference
International Informix Users Group 20
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
- 21 -
2009 IIUG Informix Conference
International Informix Users Group 21
Query Drill-down and External DirectivesStatement 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 Est Rows Num Rows Partnum Type2 0 0 3 3 2 2097264 Seq Scan3 0 0 1 23 1 2097266 Index Scan1 2 3 6 2 1 0 Nested Join...
Total Total Avg Max Avg I/O Wait Avg RowsExecutions Time (S) Time (S) Time (S) IO Wait Time (S) Per Sec1 0.0050 0.0050 0.0038 0.000000 0.000000 264.0452
Estimated Estimated Actual SQL ISAM Isolation SQLCost Rows Rows Error Error Level Memory6 2 1 0 0 CR 19152
customer
orders
- 22 -
2009 IIUG Informix Conference
International Informix Users Group 22
Query Drill-down (cont’d)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 Est Rows Num Rows Partnum Type2 0 0 3 3 16384 2097264 Seq Scan3 0 0 1 23 1 2097266 Index Scan1 2 3 6 2 1 0 Nested Join...
Total Total Avg Max Avg I/O Wait Avg RowsExecutions Time (S) Time (S) Time (S) IO Wait Time (S) Per Sec1 6.8766 6.8766 4.5851 0.000000 0.000000 0.2181
Estimated Estimated Actual SQL ISAM Isolation SQLCost Rows Rows Error Error Level Memory6 2 1 0 0 CR 19152
customer
orders
- 23 -
2009 IIUG Informix Conference
International Informix Users Group 23
Query Drill-down (cont’d)
- 24 -
2009 IIUG Informix Conference
International Informix Users Group 24
Query Drill-down (cont’d)
- 25 -
2009 IIUG Informix Conference
International Informix Users Group 25
Query Drill-down (cont’d)
- 26 -
2009 IIUG Informix Conference
International Informix Users Group 26
Query Drill-down (cont’d)
Seq Scan is on the customertable – rows processed is 16384.
Index Scan is on the orderstable – rows processed is 23.
What is this telling you ?
- 27 -
2009 IIUG Informix Conference
International Informix Users Group 27
Query Drill-down: Add External Directive
Until you can run update statistics, you decide to use external directives to improve query performance.
** Check that the directive has been added to stores_demo: sysdirectives .
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 = ?;
- 28 -
2009 IIUG Informix Conference
International Informix Users Group 28
Query Drill-down (cont’d)
Response time is much better after the external directive has been applied.
- 29 -
2009 IIUG Informix Conference
International Informix Users Group 29
Query Drill-down (cont’d)
After the External Directive:
Seq Scan is now on the orders table – rows processed is 23.
Index Scan is now on the customer table.
- 30 -
2009 IIUG Informix Conference
International Informix Users Group 30
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 Est Rows Num Rows Partnum Type2 0 0 2 23 23 2097266 Seq Scan3 0 0 1 3 1 2097264 Index Scan1 2 3 9 2 1 0 Nested Join...
Total Total Avg Max Avg I/O Wait Avg RowsExecutions Time (S) Time (S) Time (S) IO Wait Time (S) Per Sec1 0.0119 0.0119 0.0084 0.000000 0.000000 118.7306
Estimated Estimated Actual SQL ISAM Isolation SQLCost Rows Rows Error Error Level Memory9 2 1 0 0 CR 20328
orders
customer
- 31 -
2009 IIUG Informix Conference
International Informix Users Group 31
Query Drill-down (final OAT View)
- 32 -
2009 IIUG Informix Conference
International Informix Users Group 32
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’ set environment extdirectives ‘0’ ‘1’ or ‘ON’ set environment extdirectives ‘1’ DEFAULT set environment extdirectives default
No quotes!
- 33 -
2009 IIUG Informix Conference
International Informix Users Group 33
Checking sysdirectives
dbaccess stores_demo –
> select * from sysdirectives;
id 2queryselect c.city, c.state, o.ship_date from customer c, orders o where c.customer_num = o.customer_num and c.state = ?directiveFULL(orders), INDEX(customer 100_1)directivecode <BYTE value>active 1hashcode -1903458431
- 34 -
2009 IIUG Informix Conference
International Informix Users Group 34
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 251cf_name DS_NONPDQ_QUERY_MEMcf_flags 0cf_original 128cf_effective 1024cf_default 128
- 35 -
2009 IIUG Informix Conference
International Informix Users Group 35
Improving Create Index Time
Drill-down to Check Create Index Performance
- 36 -
2009 IIUG Informix Conference
International Informix Users Group 36
Query Drill-down Example 2
128, default
2048
4096
8192
DS_NON_PDQ_QUERY_MEMvalues
- 37 -
2009 IIUG Informix Conference
International Informix Users Group 37
sql_id 3: 128 (3.17 response time)
- 38 -
2009 IIUG Informix Conference
International Informix Users Group 38
sqlid 5: 2048 (2.30 response)
- 39 -
2009 IIUG Informix Conference
International Informix Users Group 39
sqlid 7: 4096 (1.93 response)
- 40 -
2009 IIUG Informix Conference
International Informix Users Group 40
sqlid 9: 8192 (1.89 response)
- 41 -
2009 IIUG Informix Conference
International Informix Users Group 41
Transactions• In a single session, ran 3 transactions• Info from “onstat –g his” output
TX Stamp: 10bcd4aStatement #: 1Statement #: 0
select col1 from tab1 where col2=?insert into tab1 values (0,100, ?)
TX Stamp: 10bcd51Statement #: 2 select col2 from tab1 where col3 matches ?TX Stamp: 10bcd53Statement #: 3 delete from tab1 where col2 = ?
** Transaction was rolled back, but you cannot tell from the SQLTRACE info.
Which one of these statements ran first in the transaction?
- 42 -
2009 IIUG Informix Conference
International Informix Users Group 42
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_begintxtimeselect a.sql_id, a.sql_statement, b.sql_hvar_datafrom sysmaster:syssqltrace a, sysmaster:syssqltrace_hvar bwhere a.sql_begintxtime = 17554506 and a.sql_sid = 47 and a.sql_id = b.sql_idorder by sql_id desc;
sql_id 1sql_statement select col1 from tab1 where col2=?sql_hvar_data 10
sql_id 0sql_statement insert into tab1 values (0,100, ?)sql_hvar_data smile
- 43 -
2009 IIUG Informix Conference
International Informix Users Group 43
Transactions (OAT View)
10bcd5310bcd5110bcd4a
- 44 -
2009 IIUG Informix Conference
International Informix Users Group 44
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.
- 45 -
2009 IIUG Informix Conference
International Informix Users Group 45
One Transaction View
This transaction has statement numbers 0 and 1.
- 46 -
2009 IIUG Informix Conference
International Informix Users Group 46
Different Transaction View
This transaction has statement number 2.
- 47 -
2009 IIUG Informix Conference
International Informix Users Group 47
onstat –g his viewStatement # 1: @ 10d06b828Database: testdbStatement text:select col1 from tab1 where col2=?
SELECT using tables [ tab1 ]
Iterator/Explain================
ID Left Right Est Cost Est Rows Num Rows Partnum Type1 0 0 2 3 1 1049476 Seq Scan
Host Variables==============0 integer 10
Statement information:Sess_id User_id Stmt Type Finish Time Run Time TX Stamp PDQ47 37108 SELECT 21:37:31 0.0430 10bdc4a 0
Statement Statistics:Page Buffer Read Buffer Page Buffer WriteRead Read % Cache IDX Read Write Write % Cache3 7 57.14 0 0 2 100.00
- 48 -
2009 IIUG Informix Conference
International Informix Users Group 48
onstat –g his viewStatement # 0: @ 10d06b028
Database: testdbStatement text:insert into tab1 values (0,100, ?)
INSERT using tables [ tab1 ]
Iterator/Explain================
ID Left Right Est Cost Est Rows Num Rows Partnum Type1 0 0 1 1 1 1049476 Insert
Host Variables==============0 char smile
Statement information:Sess_id User_id Stmt Type Finish Time Run Time TX Stamp PDQ47 37108 INSERT 21:37:31 0.0005 10bdc4a 0
Statement Statistics:Page Buffer Read Buffer Page Buffer WriteRead Read % Cache IDX Read Write Write % Cache1 3 66.67 0 0 2 100.00
- 49 -
2009 IIUG Informix Conference
International Informix Users Group 49
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
- 50 -
2009 IIUG Informix Conference
International Informix Users Group 50
Procedure Trace from onstat –g hissql_id 6 Statement Text: execute procedure check_order(?)
sql_id 5 Procedure Call Stack: testdb:check_order()
sql_id 4 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 ]
- 51 -
2009 IIUG Informix Conference
International Informix Users Group 51
Procedure Trace from onstat –g hissql_id 2 Procedure Call Stack:
testdb:notify_shipping()<-- testdb:check_order()
sql_id 1 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 ]
- 52 -
2009 IIUG Informix Conference
International Informix Users Group 52
syssqltrace (No Procedure Call Stack Label)
sql_id 6sql_statement execute procedure check_order(?)sql_stmtname EXEC PROCEDUREsql_tablelist None
sql_id 5sql_statement testdb:check_order()sql_stmtname EXEC PROCEDUREsql_tablelist None
sql_id 4sql_statement testdb:notify_shipping()
<-- testdb:check_order()sql_stmtname INSERTsql_tablelist need_ship_date
> select sql_id, sql_statement, sql_stmtname, sql_tablelist from sysmaster:syssqltracewhere sql_begintxtime = 17555740and sql_sid = 93;
- 53 -
2009 IIUG Informix Conference
International Informix Users Group 53
syssqltrace (cont’d)
sql_id 3sql_statement testdb:notify_shipping()
<-- testdb:check_order()sql_stmtname UPDATEsql_tablelist orders
sql_id 2sql_statement testdb:notify_shipping()
<-- testdb:check_order()sql_stmtname EXEC PROCEDUREsql_tablelist None
sql_id 1sql_statement testdb:log_updates()
<-- testdb:notify_shipping()<-- testdb:check_order()
sql_stmtname UPDATEsql_tablelist need_ship_date
sql_id 0sql_statement testdb:check_order()sql_stmtname SELECTsql_tablelist orders
- 54 -
2009 IIUG Informix Conference
International Informix Users Group 54
OAT (No Procedure Call Stack Label)
- 55 -
2009 IIUG Informix Conference
International Informix Users Group 55
OAT Transaction SQL List
- 56 -
2009 IIUG Informix Conference
International Informix Users Group 56
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
- 57 -
2009 IIUG Informix Conference
International Informix Users Group 57
OAT automatically creates a task
- 58 -
2009 IIUG Informix Conference
International Informix Users Group 58
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 sysadmin’s 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
- 59 -
2009 IIUG Informix Conference
International Informix Users Group 59
sql_showsnap
• 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)
CREATE FUNCTIONsql_showsnap(task_id INTEGER, seq_id INTEGER)
RETURNING INTEGER
- 60 -
2009 IIUG Informix Conference
International Informix Users Group 60
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 ;
- 61 -
2009 IIUG Informix Conference
International Informix Users Group 61
Toggle Between Saved and Live Data
Can view SQLTRACE information collected previously.
- 62 -
2009 IIUG Informix Conference
International Informix Users Group 62
OAT Displaying Saved Data
Previously collected SQLTRACE info being shown from the data saved by “Save SQL Trace” task.
- 63 -
2009 IIUG Informix Conference
International Informix Users Group 63
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”)
- 64 -
2009 IIUG Informix Conference
International Informix Users Group 64
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”)
** (“Set SQL Tracing user CLEAR”)Be careful ! Clears the default option NOT to trace dbcron sessions.
- 65 -
2009 IIUG Informix Conference
International Informix Users Group 65
My Favorite Way to Trace
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 ON SQLTRACE
• Turn OFF SQLTRACE
execute function sysadmin:task(“set sql tracing off”);
- 66 -
2009 IIUG Informix Conference
International Informix Users Group 66
Hyun-Ju VegaIBM
Session: D17Using SQLTRACE to Optimize and Test your Systems