• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Surge Of Services In DB2 For i, Part 1

    April 5, 2016 Michael Sansoterra

    The IBM i 7.2 TR3 and 7.1 TR11 technology refreshes come with a glut of new services. If you are responsible for IBM i administration, you are guaranteed to be tickled pink with these great enhancements. My examples are to call general attention to the availability of these services and give ideas on how they may be used. However, I still recommend going to the IBM documentation on the DeveloperWorks site (or the IBM knowledge center) to get full information on the parameters and all columns used by these special views and table functions.

    For clarification, there are actually two types of services supported by DB2 for i: IBM i Services and DB2 for i Services. In my past writing, I wasn’t careful in properly categorizing each service type. The IBM i Services deal mainly with providing OS related information (PTFs, memory, outq content, object lists, etc., which are discussed in this article) and the DB2 for i Services are helper services with DB2 coding and management tasks.

    QSYS2.NETSTAT_INFO

    This view allows administrators to query all active network connections to the IBM i. The following query gets a list of IPv4 connections not originating from a 10.10.x.x network scheme.

    SELECT REMOTE_ADDRESS,REMOTE_PORT,
           LOCAL_ADDRESS,LOCAL_PORT,LOCAL_PORT_NAME,TCP_STATE,
           BYTES_SENT_REMOTELY,BYTES_RECEIVED_LOCALLY,
           IDLE_TIME,NUMBER_OF_ASSOCIATED_JOBS
      FROM NETSTAT_INFO
     WHERE CONNECTION_TYPE='IPV4'
       AND REMOTE_ADDRESS NOT IN ('0','0.0.0.0','127.0.0.1')
       AND REMOTE_ADDRESS NOT LIKE '10.10.%'
    

    The results will look something like this (not all columns shown):

    REMOTE_ADDRESS

    REMOTE_PORT

    LOCAL_ADDRESS

    LOCAL_PORT

    LOCAL_PORT_NAME

    TCP_STATE

    192.168.1.94

    657

    10.153.30.60

    42918

     

    SYN-SENT

    172.29.9.6

    49438

    172.29.4.14

    23

    telnet

    ESTABLISHED

    172.29.9.6

    49466

    172.29.4.14

    23

    telnet

    ESTABLISHED

    172.29.9.6

    49447

    172.29.4.14

    8470

    as-central

    ESTABLISHED

    172.29.9.6

    49499

    172.29.4.14

    8471

    as-database

    ESTABLISHED

    172.29.9.6

    49476

    172.29.4.14

    8474

    as-netprt

    ESTABLISHED

    172.29.9.6

    49401

    172.29.4.14

    8475

    as-rmtcmd

    ESTABLISHED

    172.29.9.6

    49491

    172.29.4.14

    8475

    as-rmtcmd

    ESTABLISHED

    172.29.9.6

    49500

    172.29.4.14

    8475

    as-rmtcmd

    ESTABLISHED

    172.29.9.6

    49518

    172.29.4.14

    8475

    as-rmtcmd

    ESTABLISHED

    QSYS2.NETSTAT_JOB_INFO

    This view, related to NETSTAT_INFO, is a real gem as it discloses what jobs are hosting TCP/IP connections. This is a SQL version of the NETSTAT IBM i command. The following dynamic compound statement uses the NETSTAT_JOB_INFO view to identify the jobs hosting all active connections to the database server jobs (identified by connections on ports 8471 or 9471) and ends them. (I don’t necessarily advocate ending jobs in this manner, but it shows how SQL Services can help automate admin tasks.)

    BEGIN
    
    DECLARE @COMMAND CHAR(128);
    
    FOR vl AS c1 CURSOR FOR
    SELECT JOB_NAME
      FROM QSYS2.NETSTAT_JOB_INFO
     WHERE CONNECTION_TYPE = 'IPV4' 
       AND LOCAL_PORT IN (8471,9471)  -- Database Server Ports
       AND AUTHORIZATION_NAME<>'ODBCUSER'
       AND REMOTE_ADDRESS<>LOCAL_ADDRESS
       AND LOCAL_ADDRESS<>'127.0.0.1'   
       AND JOB_NAME<>QSYS2.JOB_NAME   -- Ignore current job
    DO
        SET @COMMAND='ENDJOB ('||JOB_NAME||') OPTION(*IMMED)';
        CALL QSYS2.QCMDEXC(@COMMAND);
    END FOR;
          
    END
    

    Note that the use of global variable QSYS2.JOB_NAME in this query is restricted to IBM i 7.2 or later.

    If you’re responsible for security, it’s important to know (in theory) what can connect to your IBM i. You can use this services view to review unexpected connections and find out where it originates. To learn about the common TCP/IP utilities (FTP, HTTP, LDAP, etc.) and the ports they use, see this link. For a list of common ports used with IBM i Access features (sign-on server, database server, remote command, data queue server, etc.), review this link.

    QSYS2.NETSTAT_INTERFACE_INFO

    This view provides the same information as shown in the green screen “Work with TCP/IP interfaces” (Option 1 from the CFGTCP menu). The following query shows all active IPV6 interfaces:

    SELECT * 
      FROM QSYS2.NETSTAT_INTERFACE_INFO 
     WHERE LINE_DESCRIPTION<>'*LOOPBACK' 
       AND INTERFACE_STATUS='ACTIVE' 
       AND CONNECTION_TYPE='IPV6';
    

    QSYS2.NETSTAT_ROUTE_INFO

    This view is the SQL equivalent of using the List Network Routes API. The purpose is to reveal all TCP/IP routes (v4 and V6) defined on the system. The following query shows routes defined for a particular Ethernet interface:

    SELECT * 
      FROM QSYS2.NETSTAT_ROUTE_INFO 
     WHERE LOCAL_BINDING_INTERFACE='172.2.168.1';
    

    QSYS2.OBJECT_LOCK_INFO

    This majestic services view, analogous to the Work with Object Locks (WRKOBJLCK) command, can reveal what job(s) are holding a lock on any object (excluding the IFS). The following example lists the jobs holding a lock on the PRODUCT table:

    SELECT SYSTEM_OBJECT_SCHEMA AS SYSOBJ,
           SYSTEM_OBJECT_NAME AS SYSNAM,
           SYSTEM_TABLE_MEMBER AS MBR,
           SQL_OBJECT_TYPE AS SQLT,
           LOCK_STATE AS STATE,
           LOCK_STATUS AS STATUS,
           LOCK_SCOPE AS SCOPE,
           JOB_NAME AS JOB
      FROM QSYS2.OBJECT_LOCK_INFO
     WHERE OBJECT_SCHEMA='ADVWORKS'
       AND OBJECT_NAME='PRODUCT'
       AND OBJECT_TYPE='*FILE'
    

    The results look like the following:

    SYSOBJ

    SYSNAM

    MBR

    SQLT

    STATE

    STATUS

    SCOPE

    JOB

    ADVWORKS

    PRODUCT

     

    TABLE

    *SHRRD

    HELD

    JOB

    051858/MIKE/QPADEV0002

    ADVWORKS

    PRODUCT

    PRODUCT

    TABLE

    *SHRRD

    HELD

    JOB

    051858/MIKE/QPADEV0002

    ADVWORKS

    PRODUCT

    PRODUCT

    TABLE

    *SHRRD

    HELD

    JOB

    051858/MIKE/QPADEV0002

    Be sure to check out all of the columns returned by this view including the PROGRAM_NAME, MODULE_NAME, instruction, etc. (not shown above).

    Use this view with caution as it can take a while to assemble this system wide content. If you generate the source for this view, you will see it relies on table function OBJECT_LOCK_INFO. For performance reasons, I would prefer to use OBJECT_LOCK_INFO to detect locks against a single object:

    SELECT *
      FROM TABLE(QSYS2.OBJECT_LOCK_INFO(
      LIBRARY_NAME=>'QSYS',
      OBJECT_NAME=>'MIKE',
      OBJECT_TYPE=>'*USRPRF',
      IASP_NUMBER=>0)) X
    

    However, this table function is not listed as part of the services in the DeveloperWorks documentation. This may be an oversight on IBM’s part or it may mean that it is not intended for the end user’s use and therefore may be subject to change in a future version. So use with caution!

    QSYS2.RECORD_LOCK_INFO

    Services view RECORD_LOCK_INFO is a fitting companion to the OBJECT_LOCK_INFO view. Akin to the Display Record Lock (DSPRCDLCK) command, this view reveals all jobs that are holding row locks in a table and even returns the relative record number of locked rows:

    SELECT SYSTEM_TABLE_SCHEMA AS SYSSCHEMA,
           SYSTEM_TABLE_NAME AS SYSTABLE,
           SYSTEM_TABLE_MEMBER AS MEMBER,
           RELATIVE_RECORD_NUMBER AS RRN,
           LOCK_STATE AS STATE,
           LOCK_STATUS AS STATUS,
           LOCK_SCOPE AS SCOPE,
           JOB_NAME
      FROM QSYS2.RECORD_LOCK_INFO
     WHERE TABLE_SCHEMA='ADVWORKS12'
       AND TABLE_NAME='PRODUCT';
    

    The results will looks like this:

    SYSSCHEMA

    SYSTABLE

    MEMBER

    RRN

    STATE

    STATUS

    SCOPE

    JOB_NAME

    ADVWORKS12

    PRODUCT

    PRODUCT

    7

    READ

    HELD

    JOB

    051128/MIKE/QPADEV0011

    ADVWORKS12

    PRODUCT

    PRODUCT

    8

    READ

    HELD

    JOB

    051128/MIKE/QPADEV0011

    ADVWORKS12

    PRODUCT

    PRODUCT

    9

    READ

    HELD

    JOB

    051128/MIKE/QPADEV0011

    ADVWORKS12

    PRODUCT

    PRODUCT

    10

    READ

    HELD

    JOB

    051128/MIKE/QPADEV0011

    ADVWORKS12

    PRODUCT

    PRODUCT

    503

    UPDATE

    HELD

    JOB

    051137/JOE/QPADEV0004

    ADVWORKS12

    PRODUCT

    PRODUCT

    504

    UPDATE

    HELD

    JOB

    051137/JOE/QPADEV0004

    This view can help verify that no one is holding row locks in one or more tables before some important processing like month end is about to happen:

    BEGIN    
        SET SCHEMA ADVWORKS;
        IF EXISTS (
        SELECT *
          FROM QSYS2.RECORD_LOCK_INFO
         WHERE TABLE_SCHEMA=CURRENT_SCHEMA
           AND TABLE_NAME='TRANSACTIONHISTORY') THEN
            SIGNAL SQLSTATE '38I01'
                SET MESSAGE_TEXT = 'Users are still processing transactions';
        END IF;
        
        -- Run month end . . .
    END
    

    Since this view generates a system wide report on locked records, it can take a while to process. Here I regress to the same story as shown for OBJECT_LOCK_INFO. Use the companion (yet undocumented) table function with the knowledge that it may change or go away in a future release. Here is an example showing how to use the RECORD_LOCK_INFO table function:

    SELECT *
      FROM TABLE(QSYS2.RECORD_LOCK_INFO(
    LIBRARY_NAME=>'ADVWORKS',
    FILE_NAME=>'TRANHIST',  /* System Name */
    MEMBER_NAME=>'*FIRST',
    IASP_NUMBER=>0)) RL
    ;
    

    The Surge Continues

    As evidenced by these useful new services, SQL is becoming the easiest way to gain quick insight into the state of your IBM i and to automatically do something in response when certain conditions arise. Don’t worry, there are more services to discuss so stay tuned for Part 2 as the surge continues.

    Michael Sansoterra is a DBA for Broadway Systems in Grand Rapids, Michigan. Send your questions or comments for Mike via the IT Jungle Contact page.

    RELATED STORIES

    Gimme, Gimme, Gimme! More Services And Global Variables Available For DB2 for i

    Make Your DB2 For i Apps Environment Aware

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Technologies, Inc.

    Get More from Your IBM i

    Many users today struggle to get at the data they need on the IBM i. When users get reports, they look like they were formatted some time last century.

    Some organizations are still printing pre-printed forms and checks on impact printers.

    How often do operators log on to their system to look for messages they hope they don’t find?

    All of these scenarios can affect users’ perception of the IBM platform negatively, but there are simple solutions.

    DRV Technologies Inc. develops innovative solutions that help customers get more from their IBM i systems.

    Solutions include:

    • SpoolFlex spool conversion & distribution
    • FormFlex electronic forms
    • SecureChex MICR laser check printing
    • MessageFlex system monitoring

    FlexTools streamline resources, improve efficiency and enable pro-active system management.

    Better software, better service, DRV Tech.

    Learn how you can get more from your IBM i at www.drvtech.com

    Call 866 378-3366 for a Free Demonstration

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    COMMON:  2016 Annual Meeting & Expo, May 15 - 18, in New Orleans! Great Power Systems event!
    iTech Solutions:  Get your copy of Pete Massiello's The IBM i State of the Union report now!
    Rocket Software:  Extend green screen apps to HTML5 for use in any web or mobile browser.

    IBM Keeps Low Profile While Reaction To ‘Resource Action’ Boils IBM i 7.3 Arrives April 15; 7.2 TR4 Follows in May

    Leave a Reply Cancel reply

Volume 16, Number 08 -- April 5, 2016
THIS ISSUE SPONSORED BY:

Bug Busters Software Engineering
WorksRight Software
UCG Technologies

Table of Contents

  • Surge Of Services In DB2 For i, Part 1
  • Enable or Disable Code at Run Time
  • Refacing Your Database, Part 1

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Tweaks Some Power Systems Prices Down, Others Up
  • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
  • The Disconnect In Modernization Planning And Execution
  • Superior Support: One Of The Reasons You Pay The Power Systems Premium
  • IBM i PTF Guide, Volume 25, Number 13
  • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
  • When You Need Us, We Are Ready To Do Grunt Work
  • Generative AI: Coming to an ERP Near You
  • Four Hundred Monitor, March 22
  • IBM i PTF Guide, Volume 25, Number 12

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2023 IT Jungle