473,513 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get snapshot for dynamic sql

Hello,

I would like to get the logical and physical reads for every sql statement
executed.
Thatfore, I used the command "db2 get snapshot for dynamic sql on
<mydatabase>". There, I could see the logical and physical reads from
bufferpool for every statement monitored. Am I right?
But now, I would like to read these results out of a table so that I could
process them automatically. In which table(s) are the results of snapshot
for dynamic sql stored? The values, I am interested in are statement text,
logical and physical reads, cpu time and total execution time.

Would be really great if you had any ideas for me!

Cheers,
Ina
Nov 12 '05 #1
14 14775
Ina Schmitz wrote:
Hello,

I would like to get the logical and physical reads for every sql statement
executed.
Thatfore, I used the command "db2 get snapshot for dynamic sql on
<mydatabase>". There, I could see the logical and physical reads from
bufferpool for every statement monitored. Am I right?
But now, I would like to read these results out of a table so that I could
process them automatically. In which table(s) are the results of snapshot
for dynamic sql stored? The values, I am interested in are statement text,
logical and physical reads, cpu time and total execution time.

Would be really great if you had any ideas for me!

Cheers,
Ina


The best idea would be to search online documentation intalled with DB2
or available online at:

http://publib.boulder.ibm.com/infoce...help/index.jsp

Please tell us what search arguments you used if you cannot find answer
you are looking for.
Jan M. Nelken
Nov 12 '05 #2
[...]
Thatfore, I used the command "db2 get snapshot for dynamic sql on
<mydatabase>". There, I could see the logical and physical reads from
bufferpool for every statement monitored. Am I right?
But now, I would like to read these results out of a table so that I
could process them automatically. In which table(s) are the results of
snapshot for dynamic sql stored? The values, I am interested in are
statement text, logical and physical reads, cpu time and total execution
time.
Please tell us what search arguments you used if you cannot find answer
you are looking for.

This was already the first thing I did - looking in the online help.
I used the search arguments: "snapshot dynamic sql table"
I just found out that the SNAPSHOT_DYN_SQL doesn't give me what I
need.Perhaps the pool_index_p_reads element could help me, but I didn't
found out how to access it in a sql statement.
Would be great if you could help me in finding better search arguments...

Cheers,
Ina
Nov 12 '05 #3
Ina Schmitz wrote:
Would be great if you could help me in finding better search arguments...


Ina,

Your original question was:

"...In which table(s) are the results of snapshot for dynamic sql stored?
The values, I am interested in are statement text, logical and physical
reads, cpu time and total execution time..."

I would start with searching online documentation available at:

http://publib.boulder.ibm.com/infoce...help/index.jsp

with SNAPSHOT BUFFER POOL TABLE FUNCTION words. You will find -
approximately within first 10 hits - a table function which closely
answers some of your requirements.

You may also try SNAPSHOT DYNAMIC SQL TABLE FUNCTION in order to find
out another candidate.

From your own words - you were looking for table function providing
snapshot for dynamic sql.

So why not search for TABLE FUNCTION providing SNAPSHOT for DYNAMIC SQL?
Jan M. Nelken
Nov 12 '05 #4
RdR
Hi,

We are currently doing some designs for Sarbanes-Oxley compliant auditing
applications that needs to capture SQL statements, I know it is not exactly
the same but similar, hopefully these ideas will prompt you to get more
ideas, these are two ways we have tried so far:
1) Use Data Propagator to capture from the logs, inserts, updates, and
deletes but modify the apply job to turn everything to inserts instead of
the normal updates which mimicks the original statement. The drawback of
this solution is that we wil not detect selects from the database. One big
advantage on this is we can get the row information (what changed before and
after images) plus other journal information like who made the change, when
the change was made and what type of change it was (UP/UB, DL, PT).
2) To write an application that will stage the results of the db2 get
snapshot command and have a reader (an ETL tool) convert them to inserts to
a table. Once the above is done, have something like Crystal Reports to read
them and format it to a report.

Hope this helps.

RdR

"Ina Schmitz" <we*@inalein.net> wrote in message
news:d5*************@news.t-online.com...
Hello,

I would like to get the logical and physical reads for every sql statement
executed.
Thatfore, I used the command "db2 get snapshot for dynamic sql on
<mydatabase>". There, I could see the logical and physical reads from
bufferpool for every statement monitored. Am I right?
But now, I would like to read these results out of a table so that I could
process them automatically. In which table(s) are the results of snapshot
for dynamic sql stored? The values, I am interested in are statement text,
logical and physical reads, cpu time and total execution time.

Would be really great if you had any ideas for me!

Cheers,
Ina

Nov 12 '05 #5
RdR wrote:
Hi,

We are currently doing some designs for Sarbanes-Oxley compliant auditing
applications that needs to capture SQL statements, I know it is not exactly
the same but similar, hopefully these ideas will prompt you to get more
ideas, these are two ways we have tried so far:
1) Use Data Propagator to capture from the logs, inserts, updates, and
deletes but modify the apply job to turn everything to inserts instead of
the normal updates which mimicks the original statement. The drawback of
this solution is that we wil not detect selects from the database. One big
advantage on this is we can get the row information (what changed before and
after images) plus other journal information like who made the change, when
the change was made and what type of change it was (UP/UB, DL, PT).
2) To write an application that will stage the results of the db2 get
snapshot command and have a reader (an ETL tool) convert them to inserts to
a table. Once the above is done, have something like Crystal Reports to read
them and format it to a report.

3) Query patroller (?)

Just a thought
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #6
Hello,

thanks for your answer. But unfortunaly, I think that my problem has not
become clear. I try to explain...
"...In which table(s) are the results of snapshot for dynamic sql stored?
The values, I am interested in are statement text, logical and physical
reads, cpu time and total execution time..." [...] From your own words - you were looking for table function providing
snapshot for dynamic sql.

So why not search for TABLE FUNCTION providing SNAPSHOT for DYNAMIC SQL?

Yes, I executed:
"select * from table(snapshot_dyn_sql('mydatabase',-1)) as myDYNSQL"
Here I got the statement text, the cpu time etc.
BUT: I also need the logical and physical reads for my statement.
With "select * from table(snapshot_bp('mydatabase',-1)) as myBP"
I get logical and physical reads.

Do you have any idea HOW TO get the logical and physical reads of a certain
sql statement? Because in the output of "select * from
table(snapshot_bp('mydatabase',-1)) as myBP" the statement text does not
occur. Is there any join attribut with which I could link these two tables?

Hope that my problem came clearer and you could help me there?

Thanks in advance,
cheers
Ina
Nov 12 '05 #7
Keep in mind that the dynamic sql snapshot is an aggrigate of ALL
invocations of a particular statement on the system. Also, it's possible
for statements to be bumped out of the cache if you're running near the
limit of your package cache size (you may not see every sql statement
ever run on the system).

If you want to do analysis for a period of time that ensure you capture
every sql statement, use an event monitor. There are write to table
event monitors that will allow you to have the results written directly
to tables (per node on EEE).

Note that these event monitors are more expensive to run than collection
via snapshot (particularly the statement event monitors, which is what
you want)...so you'd want to have these gather your stats for a period
of time, and then turn off the monitors...

Ina Schmitz wrote:
Hello,

I would like to get the logical and physical reads for every sql statement
executed.
Thatfore, I used the command "db2 get snapshot for dynamic sql on
<mydatabase>". There, I could see the logical and physical reads from
bufferpool for every statement monitored. Am I right?
But now, I would like to read these results out of a table so that I could
process them automatically. In which table(s) are the results of snapshot
for dynamic sql stored? The values, I am interested in are statement text,
logical and physical reads, cpu time and total execution time.

Would be really great if you had any ideas for me!

Cheers,
Ina

Nov 12 '05 #8
Note that these event monitors are more expensive to run than collection
via snapshot (particularly the statement event monitors, which is what you
want)...so you'd want to have these gather your stats for a period of
time, and then turn off the monitors...

Hm... I studied the statement event monitors once again. But I still didn't
find out how to get the LOGICAL AND PHYSICAL READS for a statement with
these event monitors. I don't know where to look for them anymore. Do you
have an idea?

Cheers,
Ina
Nov 12 '05 #9
Ina Schmitz wrote:
Note that these event monitors are more expensive to run than collection
via snapshot (particularly the statement event monitors, which is what you
want)...so you'd want to have these gather your stats for a period of
time, and then turn off the monitors...


Hm... I studied the statement event monitors once again. But I still didn't
find out how to get the LOGICAL AND PHYSICAL READS for a statement with
these event monitors. I don't know where to look for them anymore. Do you
have an idea?

Cheers,
Ina

Ina are you looking at this table?
http://publib.boulder.ibm.com/infoce...n/r0007595.htm
There is an element ROWS_READ and there are in V8.2 a boatfull of
bufferpool counters disecting whether you got a hit or not for indexes,
data, ...

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #10
Hello Ina,

you can't find logical and physical reads at dynamic statement level,
just the number of rows read from the table, no matter if they were
comming from disk or cache. (my knowledge is prior to 8.2.2, so this
may have changed). Further more there is no relationship between
dynamic sql from the package cache and the application which fired this
sql. The cache is just doing it's job to store prepared and already
parsed statements and plans etc., so there is no need to know which
application triggered the SQL.

If you are looking for logical and physical reads for a statement with
snapshots you need to look at application level:

db2 get snapshot for application agentid xxx
....
Buffer pool data logical reads =
Buffer pool data physical reads =
.....

The disadvantage with snapshots at application level is that you see
the dynamic statement only if it is running while you take the
snapshot. However most of the numbers are cumulated, so if it is in
your hand to start the SQL statement manually you could do a snapshot
for the application before and after the statement is executed and
calculate the delta afterwards.

I will check if event monitors or db2pd could help and let you know,
but I don't think so

cheers
Florian

Nov 12 '05 #11
We do have pool_data_l_reads and pool_data_p_reads at the statement level...

All the documentation is in the system monitor guide and
reference...there's an appending of 'logical data groupings' that'll
show you what info you get for a statement event.

Ina Schmitz wrote:
Note that these event monitors are more expensive to run than collection
via snapshot (particularly the statement event monitors, which is what you
want)...so you'd want to have these gather your stats for a period of
time, and then turn off the monitors...


Hm... I studied the statement event monitors once again. But I still didn't
find out how to get the LOGICAL AND PHYSICAL READS for a statement with
these event monitors. I don't know where to look for them anymore. Do you
have an idea?

Cheers,
Ina

Nov 12 '05 #12
Ian
Serge Rielau wrote:
RdR wrote:
Hi,

We are currently doing some designs for Sarbanes-Oxley compliant auditing
applications that needs to capture SQL statements, I know it is not
exactly
the same but similar, hopefully these ideas will prompt you to get more
ideas, these are two ways we have tried so far:
1) Use Data Propagator to capture from the logs, inserts, updates, and
deletes but modify the apply job to turn everything to inserts instead of
the normal updates which mimicks the original statement. The drawback of
this solution is that we wil not detect selects from the database. One
big advantage on this is we can get the row information (what changed
before and after images) plus other journal information like who made
the change, when the change was made and what type of change it was
(UP/UB, DL, PT).
2) To write an application that will stage the results of the db2 get
snapshot command and have a reader (an ETL tool) convert them to
inserts to a table. Once the above is done, have something like Crystal
Reports to read them and format it to a report.


3) Query patroller (?)


4) db2audit (?)

Nov 12 '05 #13
Hello Florian,

thanks a lot for your help.
db2 get snapshot for application agentid xxx

I was developping a similar solution - being confused now, which logical
read value is the correct one...

For getting the physical and logical reads for a sql statement, I sent my
sql statement to the database via JDBC and then the following statement:
SELECT pool_data_l_reads, pool_data_p_reads from
table(snapshot_bp('mydatabase',-1)) as test;"
With this, I hope to get the sum of all logical and physical reads after the
execution of my sql statement.
Now, I execute the sql statement again, and again I execute the statement to
select the pool_data_l_reads and ..._r_reads.
Now I build the difference between these values and have the logical and
physical reads for the last execution of my sql statement.
Am I right till now?

Not having thought that this could also cause a problem, I now tried to get
the total execution time for the statement ("db2 get snapshot for dynamic
sql on mydatabase" unfortunately doesn't help me, because I do a series of
executions of the same sql statement and have to do some calculations on the
result).
Thatfore, I created the following event monitor:
"create event monitor test_monitor

for statements

write to table

STMT (table db2admin.test_monitor)

manualstart"
I then started this monitor, executed my queries and then executed "select *
from test_monitor".
BUT: Now I get 3 rows for each of my sql statements. In two of these three
rows, system_cpu_time and user_cpu_time are 0. So for calculating the
total_cpu_time, I just need the third row generated. But for getting the
total execution time of the statement, I have the following problem: the
start_time and stop_time differ also in these rows with system_ and
user_cpu_time=0. So I have do calculate the sum of all these three
differences to get the total execution time?
Am I right with this idea? Or is there a more simple idea to get the results
I need?

Would be great if you could help me there!

Cheers,
Ina

Nov 12 '05 #14
See below in the note.

--
Pierre Saint-Jacques
SES Consultants Inc.
514-737-4515
<fl***********@itgain.de> a écrit dans le message de news:
11*********************@o13g2000cwo.googlegroups.c om...
Hello Ina,

you can't find logical and physical reads at dynamic statement level,
just the number of rows read from the table, no matter if they were
comming from disk or cache. (my knowledge is prior to 8.2.2, so this
may have changed). Further more there is no relationship between
dynamic sql from the package cache and the application which fired this
sql. The cache is just doing it's job to store prepared and already
parsed statements and plans etc., so there is no need to know which
application triggered the SQL.

If you are looking for logical and physical reads for a statement with
snapshots you need to look at application level:

db2 get snapshot for application agentid xxx
...
Buffer pool data logical reads =
Buffer pool data physical reads =
....

The disadvantage with snapshots at application level is that you see
the dynamic statement only if it is running while you take the
snapshot. However most of the numbers are cumulated, so if it is in
your hand to start the SQL statement manually you could do a snapshot
for the application before and after the statement is executed and
calculate the delta afterwards. ####### It would be easier to issue a:
RESET MONITOR ALL FOR DATABASE database-alias
This brings the counters to zero.
Then start the app and then get snapshot after end of app.

If you absolutely neeed to see the stmts. then run this on your test system
without anybody else on the box. Sizr the package cache large enough to
hold the stmts.
and get your snapshots at the end.é I still also think you will not be able
to correlate the values to each stements.
HTH, Pierre.


I will check if event monitors or db2pd could help and let you know,
but I don't think so

cheers
Florian


Nov 12 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1531
by: deepakjgupta | last post by:
Hello all, We are using SQL Server 2000 (Enterprise Edition) Merge Replication to synchronize databases between a main server database and about 200 local MSDE databases. Recently, we upgraded...
2
3050
by: hype | last post by:
Hi, 1) If I need to monitor a resource eg, bufferpools at the database level across all users, how can I do this ? If snapshot monitoring needs to be done wouldn't enabling the switch at the DBM...
4
3953
by: Jennie | last post by:
I need to collect dynamic SQL execution times for a production database. However, the totals are not being updated, despite setting the DFT_MON_TIMESTAMP on. The DFT_MON_TIMESTAMP is listed in...
3
3879
by: sethwai | last post by:
Hi, I find the "snapshot for dynamic sql" a great tool for identifying the most frequently executed dynamic sql statements, most cpu used, etc. It is a great help for system tuning. My...
0
1571
by: mike | last post by:
Problem: the snapshot output for dynamic SQL shows some SELECT statements executed many times but all three CPU counters (total/system/user) in the dynamic-sql-snapshot are zero, but most other...
4
4417
by: MPD | last post by:
Hi How can I create a job in sql agent to create a new snapshot every hour? I have, for eg a T-SQL that does it manually. create database Snapshotter_snap_20070418_1821 on ( name =...
3
5689
by: aj | last post by:
DB2 LUW 8.1 fixpak 14 Red Hat EL AS 4.4 I'm trying to diagnose some nocturnal CPU pressure, and am trying to understand the dynamic statement cache as it applies to LUW. The only doc/redbooks...
1
5666
by: aj | last post by:
DB2 LUW 8.1 FP14 RedHat AS In "db2 get snapshot for dynamic sql" output I see (amongst other things): Number of executions = 235 Number of compilations = 1 Worst...
2
8926
by: Damir | last post by:
Hello! I have noticed that after (sucessfully) executing the command: FLUSH PACKAGE CACHE DYNAMIC the dynamic SQL statement cache is not completely cleared (some of the dynamic SQL statement...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.