Db2 Tools for z/OS

Db2 Tools for z/OS

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only

Db2 Query Monitor - Displaying Host Variables

By Tom Glaser posted Mon November 11, 2024 11:20 AM

  
Db2 Query Monitor: Host Variables
 
By Tom Glaser
Date: July 2024
 
IBM Db2 Query Monitor for z/OS (also referred to as Db2 Query Monitor) is a query analysis tool that analyzes SQL statements and provides accounting details about these queries.  
Features
Db2 Query Monitor enables you to:
⦁ Collect, summarize, and display SQL resource consumption down to the level of the individual SQL text statement.
⦁ Collect, summarize, and display Db2 object access statistics down to the individual table and index.
⦁ Access data from multiple Db2 Query Monitor subsystems.
⦁ View data from the perspective of a data sharing group.
⦁ View active SQL statements that are currently being executed by Db2.
⦁ Capture the full text of long SQL statements.
⦁ Disable summary reporting for specific workloads, include or exclude specific -SQLCODES from exception or alert processing, set exception limits and thresholds, and define alert notification thresholds.
⦁ View the expanded text description for an SQLCODE that is supplied by the IBM® utility program DSNTIAR.
⦁ Display Host Variables.
⦁ View information about the Db2 commands that are executed on monitored Db2 subsystems.
⦁ Collect information relating to exceptional SQL-related events.
⦁ Configure proactive notification to alert users of problems.
⦁ Automate curative actions to deal with exceptional events as they occur.
⦁ Access consolidated data and events for Db2 subsystems, whether within a single z/OS image or across multiple Db2 images, independent of the existence of a coupling facility.
⦁ View and configure monitoring across your enterprise from a single console.
⦁ …and more.
The purpose of this blog: One of the many functions of Db2 Query Monitor is to capture host variables. I don’t know how many times I’ve heard someone say they know their Cobol program is passing the correct value to the SQL statement.  When they run their program, no rows are returned….and it becomes Db2’s fault for not retrieving the correct rows.  This is where Db2 Query Monitor shines.  It can display the values being passed to the SQL statement so that you can accurately know what is running in Db2; and it’s in hex, so you can see non-printable characters.  
 
If no input host variables are present for the call or the monitoring profile stated not to collect them, one the following messages is displayed:
 
• CQM104I No host variables. Db2 Query Monitor found no input host variables present for this call or the monitoring profile stated not to collect them.
• CQM103I Host variables not gathered. Db2 Query Monitor does not collect host variables for this call type.
 
 
CQM Parms:
 
Db2 Query Monitor has a large number of installation parameters.  The following two are related to host variables:
 
ALERT_HOSTV_PER_ALERT
Use the ALERT_HOSTV_PER_ALERT parameter in CQMPARMS to control the amount of storage used for alerts.
 
Description
The maximum number of host variables per alert (nnnnn) that are collected. This parameter enables you to control the amount of storage that is used when collecting alerts.
 
Syntax
ALERT_HOSTV_PER_ALERT(nnnnn)
 
Default
16
Note: Under normal circumstances, the default value is appropriate. However, if your workloads average more than 16 host variables per alert, this parameter can be adjusted as needed.
 
HOSTVAR_LIMIT
Use the HOSTVAR_LIMIT parameter in CQMPARMS to control the amount of storage allocated for host variables.
 
Description
The maximum amount of storage (n) to be allocated for host variable collection per event.
Note:
• If you are using Security Guardium S-TAP for Db2 on z/OS and Db2 Query Monitor to simultaneously monitor the same Db2 subsystem, all products must have matching HOSTVAR_LIMIT settings to avoid receiving a mismatch error.
• If error message CQM1203I is encountered, with RC=0008, RSN=003F, increase the HOSTVAR_LIMIT setting to accommodate the collection of host variables for the monitored workload.
 
Syntax
HOSTVAR_LIMIT(n)
 
Default
1500
 
Range
Integers in the range 1 - 99999
 
Example
HOSTVAR_LIMIT(1000)
 
 
Performance History Files:
 
Db2 Query Monitor uses a set of VSAM data sets, collectively referred to as Performance History Files, to store information about the Db2 subsystems it monitors.  Here are two VSAM files that store host variable information:
 
EXCPDATA -
Stores information related to exception SQL calls, text, SQLCA, and host variables. You can modify the parameters that control the EXCPDATA Performance History File by tailoring the EXCPDATA_* parameters in CQMPARMS
 
EXCPHSTV -
Stores information about exception host variable information collected during the course of an interval. You can modify the parameters that control the EXCPHSTV Performance History File by tailoring the EXCPHSTV_* parameters in CQMPARMS.
 
Security: 
 
If you want to secure data in current activity, summaries, exceptions, or SQLCODES, you must configure a RACF facility class profile for the appropriate function (for example, a RACF facility class profile might be CQM.HOSTV.qmid which protects host variable information in current activity).
 
 
For host variable viewing and collection, Db2 Query Monitor checks a user's access when it sees a new workload.  Db2 Query Monitor administrators should be careful when granting users who are granted READ access to CQM.EO.HOSTV.qmid and CQM.HOSTV.qmid and should consider the security of the tables that will hold host variable information. To view host variables in the Activity Browser, the user must have READ access to CQM.HOSTV.qmid.  With auditing requirements around Db2, you want to protect who has access to host variables.  For example, you could be displaying someone’s social security number or credit card information.  
 
Profile Setup:
 
The option to monitor host variables must be turned on in the Db2 Query Monitor subsystem “profile.”  
 
Here’s an example: 
 
 
In the example above, “Gather Host Variables” is turned to Y.   If Y, the unit of SQL activity that is collected will be turned on.  Notice only packages that start with ADB will be monitored with this workload (profile line).  Other packages could be monitored with different workloads.
 
To capture host variables, you need to define an exception.  Exceptions are SQL events that a database administrator might be requested to research. These thresholds are defined in the monitoring profile.  For example, if you want to know about queries that run longer than 1 second, this will become an exception….and this information will be displayed in the exception panels.
 
Displayed Host Variables:
 
Host variables can be displayed either by the ISPF interface and the Web Client (CAE=Consolidated Analysis Engine).  We’ll look at both.  You can view host variables under current activity and exceptions.   
 
Let’s run a couple of tests.  I’m going to call a stored procedure using the Db2 Admin Tool, I’ll pass it parameters and then we’ll take a look at them in Query Monitor. 
 
Admin Tool: I’m going to call a Db2 Stored Procedure that allows me to execute a Db2 command:
 
 
We are going to enter the Db2 Command -DIS GROUP with a length of 20 characters:
 
 
Here’s our result:
 
Let’s look at Db2 Query Monitor and select option 5 for “Exceptions.”  Enter the letter H
 
Notice the -DIS GROUP command and the length of 20…as well as a display in hex?
 
 
Web Client:
 
In this example, we set Perspective to Exceptions.  When you select the command for a specific row, you have 3 options, but one of them is not H for Host Variables.
 
 
 
If you have many host variables, say 100 or more, you will need to manually line up the host variables to the SQL statement.  Here’s an example:
 
 
Here’s another example:
 
 
 
Overhead
 
There is overhead associated with capturing hosts variables. Capturing host variables can quickly resolve SQL statement issues.  You don’t want to turn this on for everything, as Db2 Query Monitor must extract the variable information and write them to VSAM files.  Imagine the overhead of your Db2 subsystem executing millions of transactions per hour and capturing all that data.  Just turn on what you need. 
 
What Db2 Query Monitor does not capture: 
⦁ Db2 Query Monitor does not collect host variables in native stored procedures.
⦁ Host variables cannot be collected on exceptions alone.  The problem is that say the host variables are collected on the OPEN, and the threshold is set for total CPU which isn't known till statement closes, by the time the CLOSE call comes around the host variables are long gone and can't be collected.
⦁ Db2 Query Monitor does not collect the values of host variable data for FETCH statements.
⦁ You must set a threshold in order to collect the host variables, such as GETPAGE, CPU, ELAPSED TIME,  etc.  Monitoring the SQL return code by itself will not collect host variables, unless you set up the profile to  enable SQL codes as exception.  In this screen shot,  I have GENERATE SQLCODE EXCEPTIONS set to Y.  In “INCLUDE EXCEPTION SQLCODES,” you can include what SQLCODE you want to monitor.  When found, it will include those host variables.
 
 
In Summary:   
 
In this blog, I’ve shown you how to view host variable data in either the ISPF interface or the Web Client.  If you have any suggestions on how to enhance batch reporting for Db2 Query Monitor or any other function within this tool, please submit an Aha on IBM’s web page.

#IBMChampion
6 comments
63 views

Permalink

Comments

Tue December 03, 2024 03:56 PM

Hello Tom,

Perfect, reaĺly interesting, now I know why/when I saw the unicode. 

Thank you very much for the explanation!

Tue December 03, 2024 01:54 PM

Soledad, it does make sense.  I did talk to a colleague of mine, Joern.

An application could be running UTF-8, e.g., Java. 

The application will be using host variables in UTF-8, but Db2 will of course convert when the query is executed on a Db2 system with 273/1143 (German EBCDIC). QM saves the host variable in the original code page, but we convert when we show in ISPF or CAE.

Local packages from COBOL or PL/I will of course be bound with 273 or 1143 thus show up in EBCDIC.

Great question, Soledad!

Tom

Tue December 03, 2024 03:09 AM

Hello Tom,

it's the SYSLH200 and it's with Encoding 1141, the German one.

I am also checking another system where we have the same with 273, and it also shows the values in UTF-8.

For the rest of the packages at my Exceptions, with a collection other than NULLID it shows Hex.

Does this make sense? 

Thanks!

SELECT ENCODING_CCSID, CONTOKEN, LASTUSED 
FROM SYSIBM.SYSPACKAGE                    
WHERE NAME = 'SYSLH200'                   
AND CONTOKEN = X'5359534C564C3031'        
ORDER BY LASTUSED DESC                    
;;                                        
---------+---------+---------+---------+--
ENCODING_CCSID  CONTOKEN  LASTUSED        
---------+---------+---------+---------+--
          1141  LRL<O<..  03.12.2024      

Mon December 02, 2024 03:24 PM

Great question, Soledad.  I think this is something I should add to the host variable blog.  I believe what is happening is that Query Monitor is displaying what was captured based on how the Db2 package was bound.  For example, try running this query:

SELECT ENCODING_CSSID 

FROM SYSIBM.SYSPACKAGE

WHERE NAME = 'xxxx'

AND CONTOKEN = 'yyyy';

If ENCODING_CSSID is 37, as an example, EBCDIC is used and hex is displayed.

If ENCODING_CCSID is 1208, as an example, the Unicode format is displayed.

Can you verify this on your ssid?

Thanks, Tom

Sat November 30, 2024 04:41 PM

Hello Tom,

I have just realized that it is in Unicode, ' 3GA' is 20334741 in unicode.

Do you know why sometimes it is shown in HEX and sometimes in Unicode?

What does mark this difference at Query Monitor?

Thanks

Fri November 29, 2024 09:26 AM

Hello Tom, 

very interesting, thanks for sharing.

I have a case at this "Input Host Variables' screen.  Mainly as at your screenshot, I see the value in CHAR and below the Hex value.

But for one of my threads, always the ones coming from the same application, the CHAR value doesn't correspond when the HEX value at Query Monitor.

So when it makes no sense, it's like this:

Number  Type                Null  Length  Data
     1           VARCHAR              N         4   3GA
                                                                     2344
                                                                     0371

I am asking this because we are having issues with the ones that have an incorrect Hex translation. 

Does this make any sense to you? I am starting to think about any incompatibility of ENCODING_CCSID between the application and the Host, but ... just guessing.

Thanks.