473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Make DB2 administrative APIs available through SQL

Hello all,

there are two procedures to get the reorgchk statistics for tables and
indexes.

I would like to have the result of those stored in a table.
Has one of you a hint for me how I could get this?
Is there a global temporary table I could read after calling the
procedure?
(Knut, is it possible?)

Many thanks
Stefan
Make DB2 administrative APIs available through SQL
http://www-128.ibm.com/developerwork...lze/index.html

db2 => call sysproc.reorgchk_ix_stats('t','sapr3.t000')

Result set 1
--------------
TABLE_SCHEMA
TABLE_NAME
INDEX_SCHEMA INDEX_NAME
CARD NLEAF NUM_EMPTY_LEAFS NLEVEL
S ISIZE NUMRIDS_DELETED FULLKEYCARD F4
F5 F6 F7 F8
REORG

----------------------------------------------------------------------------------------------------------------------
----------
-------------------------------------------------------------------------------------------------------------
------------------- --------------------------------
-------------------- ----------- ----------- --------------- ------
----- -------------------- -------------------- --------------------
----------- ----------- ----------- ----------- ---
-------- -----
SAPR3
T000
SAPR3 T000~0
3 1 0
1 3 0 3
100 -1 -1 0
0 -----

1 record(s) selected.

Return Status = 0

db2 => call sysproc.reorgchk_tb_stats('t','sapr3.t000')
Result set 1
--------------

TABLE_SCHEMA
TABLE_NAME
CARD OVERFLOW NPAGES FPAGES
ACTIVE_BLOCKS TSIZE F1
F2 F3 REORG

----------------------------------------------------------------------------------------------------------------------
----------
-------------------------------------------------------------------------------------------------------------
------------------- ----------- ----------- ----------- -----------
-------------------- -------------------- ----------
- ----------- ----------- -----
SAPR3
T000
3 0 1 1
-1 270
0 -1 100 ---

1 record(s) selected.

db2 => describe call sysproc.reorgchk_tb_stats('t','sapr3.t000')

SQLDA Information

sqldaid : SQLDA sqldabc: 1136 sqln: 20 sqld: 0

Column Information

sqltype sqllen sqlname.data
sqlname.length
-------------------- ------ ------------------------------
--------------
(empty ???)

Nov 12 '05 #1
1 3110
Stefan wrote:
Hello all,

there are two procedures to get the reorgchk statistics for tables and
indexes.

I would like to have the result of those stored in a table.
Has one of you a hint for me how I could get this?
Is there a global temporary table I could read after calling the
procedure?
(Knut, is it possible?)


You can wrap the calls to reorgchk_??_stats into your own procedure and have
that procedure write the results into a table of yours. The following
procedure shows that. Please note that it only works on the tables and
indexes in the SYSIBM schema. You might want to parameterize that.

----------- snip ------------
DROP TABLE session.reorgchk_results@
DROP PROCEDURE reorgchk()@
CREATE PROCEDURE reorgchk()
LANGUAGE SQL
RESULT SETS 0
BEGIN
DECLARE table_check RESULT_SET_LOCATOR VARYING;
DECLARE index_check RESULT_SET_LOCATOR VARYING;

DECLARE table_schema, table_name VARCHAR(128);
DECLARE index_schema, index_name VARCHAR(128);
DECLARE nleaf, num_empty_leafs, nlevels, isize,
numrids_deleted, fullkeycard INTEGER;
DECLARE cardinality, overflow, npages, fpages,
active_blocks, tsize INTEGER;
DECLARE f1, f2, f3, f4, f5, f6, f7, f8 DOUBLE;
DECLARE reorg VARCHAR(5);
DECLARE got_all INTEGER DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET got_all = 1;

DECLARE GLOBAL TEMPORARY TABLE session.reorgchk_results (
table_schema VARCHAR(128),
table_name VARCHAR(128),
index_schema VARCHAR(128),
index_name VARCHAR(128),
cardinality INTEGER,
overflow INTEGER,
npages INTEGER,
fpages INTEGER,
active_blocks INTEGER,
tsize INTEGER,
nleaf INTEGER,
num_empty_leafs INTEGER,
nlevels INTEGER,
isize INTEGER,
numrids_deleted INTEGER,
fullkeycard INTEGER,
f1 DOUBLE,
f2 DOUBLE,
f3 DOUBLE,
f4 DOUBLE,
f5 DOUBLE,
f6 DOUBLE,
f7 DOUBLE,
f8 DOUBLE,
summary VARCHAR(5),
reorg_recommended CHAR(1)
) ON COMMIT PRESERVE ROWS NOT LOGGED ON ROLLBACK PRESERVE ROWS;

CALL sysproc.reorgchk_tb_stats('S', 'SYSIBM');
ASSOCIATE RESULT SET LOCATOR ( table_check )
WITH PROCEDURE sysproc.reorgchk_tb_stats;
ALLOCATE table_cursor CURSOR FOR RESULT SET table_check;
SET got_all = 0;

fetch_table: LOOP
FETCH table_cursor
INTO table_schema, table_name, cardinality, overflow,
npages, fpages, active_blocks, tsize, f1, f2, f3, reorg;
IF got_all = 1 THEN
LEAVE fetch_table;
END IF;

INSERT
INTO session.reorgchk_results(table_schema, table_name,
cardinality, overflow, npages, fpages, active_blocks,
tsize, f1, f2, f3, summary, reorg_recommended)
VALUES ( table_schema, table_name, cardinality, overflow,
npages, fpages, active_blocks, tsize, f1, f2, f3, reorg,
CASE WHEN reorg LIKE '%*%' THEN 'Y' ELSE 'N' END );
END LOOP fetch_table;
CLOSE table_cursor;
CALL sysproc.reorgchk_ix_stats('S', 'SYSIBM');
ASSOCIATE RESULT SET LOCATOR ( index_check )
WITH PROCEDURE sysproc.reorgchk_ix_stats;
ALLOCATE index_cursor CURSOR FOR RESULT SET index_check;
SET got_all = 0;

fetch_index: LOOP
FETCH index_cursor
INTO table_schema, table_name, index_schema, index_name,
cardinality, nleaf, num_empty_leafs, nlevels,
isize, numrids_deleted, fullkeycard, f4, f5, f6, f7, f8,
reorg;
IF got_all = 1 THEN
LEAVE fetch_index;
END IF;

INSERT
INTO session.reorgchk_results(table_schema, table_name,
index_schema, index_name, cardinality, nleaf,
num_empty_leafs, nlevels, isize, numrids_deleted,
fullkeycard,
f4, f5, f6, f7, f8, summary, reorg_recommended)
VALUES ( table_schema, table_name, index_schema, index_name,
cardinality, nleaf, num_empty_leafs, nlevels,
isize, numrids_deleted, fullkeycard,
f4, f5, f6, f7, f8, reorg,
CASE WHEN reorg LIKE '%*%' THEN 'Y' ELSE 'N' END );
END LOOP fetch_index;
CLOSE index_cursor;
END
@
----------- snip ------------

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2

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

Similar topics

1
by: Siegfried Heintze | last post by:
How do I call APIs written in C like CMC? Will PInvoke do the job? I hope I don't have to write a COM wrapper! Sieg
82
by: Peter Diedrich | last post by:
The site design is pretty simple: ============================================ | Head | ============================================ | | ...
0
by: Typing4Less Services | last post by:
Are you overworked? Do you need a paper typed? Do you need transcription services? Do you need a professional resume? Is your secretary always sick or on vacation?
3
by: Big Dave | last post by:
Hello All, I was wondering wether anyone could help me solve what is probably a very easy issue. I keep getting this damn "The administrative limit for this request was exceeded" whenever I try to...
1
by: Vikas | last post by:
Hello, I am consuming a C++ COM dll exposed by a 3rd party from a C# application but I do not have a documentation of the APIs exposed by it. Is there a command or tool available that will tell...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi all, The following are my need: 1. When a PC starts, my software should come up directly without any user interaction. 2. Only my software will be accessible to the user and they will not be...
6
by: jonefer | last post by:
It seems that the following code should work - (if not why is the event there?) (Do I need some sort of client side script to awaken it?) Private Sub chkRefresh_CheckedChanged(ByVal sender As...
0
by: Brian Schwartz | last post by:
Is there a way to make a control a child of the desktop, using the .NET framework? I know how to do this with APIs, but would like to avoid APIs if possible. So far I haven't found any way to get a...
10
by: AA Arens | last post by:
I do have a database with customer info in it. To avoid it will be taken out of our office, is it possible to make it not-readable after a certain period? then every let say seven days, I needs to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.