IBM Sterling products unofficial blog

Database, IBM Sterling B2B Integrator, IBM Sterling Filegateway, troubleshooting

Useful SQL queries for IBM Sterling B2B Integrator Database

useful SQL queries for sterling b2b integrator

Updated SQL queries  to understand the IBM Sterling B2B Integrator  Database.

SQL queries :

Index count

SELECT count(*) 
FROM ARCHIVE_INFO 
WHERE ARCHIVE_FLAG in (-1,-2,-5)

Purge count

SELECT count(*) 
FROM ARCHIVE_INFO 
WHERE ARCHIVE_FLAG in (1,2)

Eligible Purge records : Purge current backlog (Oracle)

SELECT count(*) 
FROM ARCHIVE_INFO 
WHERE ARCHIVE_FLAG in (1,2) and 
ARCHIVE_DATE < sysdate

DB2: replace sysdate by CURRENT DATE.

MS SQL SERVER : replace sysdate with GETDATE()

Purge records per month : DB2 and Oracle only:

SELECT count(*), 
to_char(archive_date,'mmyyyy') 
FROM archive_info 
WHERE archive_flag in (1,2) 
GROUP BY to_char(archive_date,'mmyyyy')

Oracle and DB2  archive_info stats by day :

SELECT count(*),
to_char(archive_date,'YYYYMMDD') 
FROM archive_info 
WHERE archive_flag=0 
GROUP BY to_char(archive_date,'YYYYMMDD') 
ORDER BY to_char(archive_date,'YYYYMMDD')

Oracle and DB2  archive_info stats  by year :

SELECT count(*),to_char(archive_date,'YYYY') 
FROM archive_info 
WHERE archive_flag in (0,1,2) 
GROUP BY to_char(archive_date,'YYYY') 
ORDER BY to_char(archive_date,'YYYY')

BP stats by number of runs and number of steps :

SELECT T2.NAME, 
COUNT(DISTINCT WORKFLOW_ID) AS NO_OF_RUNS, 
COUNT(*) AS NO_OF_STEPS 
FROM WORKFLOW_CONTEXT T1, WFD T2
WHERE T1.WFD_ID = T2.WFD_ID AND 
T1.WFD_VERSION = T2.WFD_VERSION 
GROUP BY T2.NAME 
ORDER BY 2 DESC

BP execution times stats (Oracle):

SELECT WFD.NAME,
WFC.WFD_ID,  
WFC.WORKFLOW_ID,
WFC.NODEEXECUTED,
MIN(WFC.START_TIME) as "Start", 
MAX(WFC.END_TIME) as "End",
round((MAX(WFC.END_TIME)-MIN(WFC.START_TIME))60*60*24) as " Runtime Sec"
FROM WORKFLOW_CONTEXT WFC,WFD
WHERE WFD.WFD_ID=WFC.WFD_ID
-- Uncomment to specify a time Interval
--and wfc.start_time between 
--to_timestamp('201903010030','YYYYMMDDHH24MI') and
--to_timestamp('201903011700','YYYYMMDDHH24MI')
 GROUP BY WFD.NAME,WFC.WFD_ID, WFC.WORKFLOW_ID,WFC.NODEEXECUTED
 ORDER BY 7 DESC

Bps with large number of steps (>3000 steps)

BPs with large number of steps can cause lock escalations during Purge on a non tuned MS SQL server :

SELECT DISTINCT WORKFLOW_ID , 
count(WORKFLOW_ID) as steps
FROM WORKFLOW_CONTEXT 
GROUP BY WORKFLOW_ID 
HAVING COUNT(WORKFLOW_ID) > 3000 
ORDER BY COUNT(WORKFLOW_ID) DESC

Number of executions per cluster node statistics:

SELECT count(distinct WORKFLOW_ID),
NODEEXECUTED 
FROM WORKFLOW_CONTEXT 
GROUP BY NODEEXECUTED

Communication sessions Stats by Protocol :

SELECT COUNT(*),
PROTOCOL, 
ENDPOINT1, 
ENDPOINT2,
CON_IS_SUCCESS, 
MAX(CON_START_TIME),
MIN(CON_START_TIME)
FROM  ACT_SESSION 
GROUP BY PROTOCOL, ENDPOINT1, ENDPOINT2 ,CON_IS_SUCCESS 
ORDER BY 1 DESC

Total document_size per month : Oracle and DB2

SELECT count(*), 
sum(document_size)/1024/1024 MB,
to_char(create_time,'mmyyyy') 
FROM DOCUMENT 
GROUP BY to_char(create_time,'mmyyyy') 
ORDER BY 2 desc;

MS SQL server : query to return the total size of documents per month:

SELECT 
convert(varchar(6),CREATE_TIME,112) TIME_YYYYMM,
count(*) COUNT,
cast(ROUND(sum(DOCUMENT_SIZE)/1024/1024,2,1) as decimal(10,2)) SIZE_MB
FROM DOCUMENT 
GROUP BY convert(varchar(6),CREATE_TIME,112) 
ORDER BY 1

Oracle and DB2  workflow_context BP records per month:

SELECT count(*), 
to_char(start_time,'mmyyyy') 
FROM WORKFLOW_CONTEXT 
GROUP BY to_char(start_time,'mmyyyy') 

Oracle and DB2   Workflow_context BP stats by Hour:

SELECT to_char(START_TIME, 'HH24'), 
count(*) 
FROM workflow_context 
GROUP BY to_char(START_TIME, 'HH24') 
ORDER BY 1 desc

Oracle Tablespace statistics  :

SELECT Total.name "Tablespace Name", 
nvl(Free_space, 0) Free_space, nvl(total_space-Free_space, 0) Used_space,
total_space FROM (select tablespace_name,
 sum(bytes/1024/1024) Free_Space from sys.dba_free_space group by tablespace_name ) Free, 
(select b.name, sum(bytes/1024/1024) TOTAL_SPACE from sys.v_$datafile a, sys.v_$tablespace B where a.ts# = b.ts# group by b.name ) Total 
WHERE Free.Tablespace_name(+) = Total.name ORDER BY Total.name; 

Oracle trans_data size distribution by reference_table: (very slow query on large DBs)

SELECT reference_table,
data_type,
count(*),
round(SUM (dbms_lob.getlength(DATA_OBJECT)) /1024/1024) total_MB 
FROM TRANS_DATA 
GROUP BY reference_table,data_type 
ORDER BY 1,2

Remember to run SQL queries returning large result-sets OUTSIDE of the B2B Integrator application SQL manager. Use external tools like Oracle SQL developer.

Check more useful SQL queries:

Best practices must reads:

Oracle Database best practices for Sterling B2B Integrator.

MS SQL Server best practices for Sterling B2B Integrator.

If you are struggling to find some information in the B2B Integrator Database, please post a comment below. You can also share your useful SQL for Integrator!

44 Comments

  1. Sathish Kumar Baskaran

    SQL query to check last execution of the Business Processes in IBM Sterling B2B Integrator

  2. SQL query that will return the executions of a specific BP in the last hour (sysdate – 1/24 for Oracle):

    SELECT WFD.NAME, WFC.WORKFLOW_ID, MIN(WFC.START_TIME) as “Start”, MAX(WFC.END_TIME) as “End”, round((MAX(WFC.END_TIME)-MIN(WFC.START_TIME))*60*60*24) as ” Runtime Sec”
    FROM WORKFLOW_CONTEXT WFC,WFD
    WHERE WFD.WFD_ID=WFC.WFD_ID AND
    WFD.NAME = ‘MailboxEvaluateAllAutomaticRulesSubMin’
    AND WFC.START_TIME>sysdate -1/24
    GROUP BY WFD.NAME, WFC.WORKFLOW_ID
    ORDER by 4 desc

  3. richard

    Since imports/exports are size limited in some cases, is there anywhere in a table that might show the size of a map, to plan out exporting maps for importing to another server?

  4. Richard

    Oh cool! Thanks a bunch. I check this out!

  5. Sathish Kumar Baskaran

    How to export the maps which are stored as a blob in the database?

    • Comment by post author

      Editor

      Hi ,

      You cannot export the maps directly from the blob columns in data_table, you need to use the product export tool. Or download the map from the UI.

      • Russ Schamburg

        You can export maps (.mxl,.map and .txo) from the database. You must unzip the blobs as they are zipped when stored.

  6. Douglas Rezende

    Hi,
    How move messages from MBX(es) from old system to a new one?I need create a ETL to do this?

    Regards,
    Douglas Rezende

    • Hello,

      You need to write a business process or an FTP/SFTP script to do this. To read from the original mailbox and write to the new mailbox. I am not aware of a tool that does this.

      Thanks

  7. Omkar Trikolikar

    Hello,

    In which sql table I can get the list of Bps / schedule with the creation date?

    • Comment by post author

      The BP definitions/versions with creation date will be stored in WFD table. The actual source of the BP is stored as a blob in the Data_table.
      For Schedules there is a table called Schedules that points to data_table as the timing information is stored in a blob.

  8. srini

    Hi All,

    I would like to know the below reports on SI , can anyone help on this .
    1. Transaction volumes
    2. Types of transactions exchanged
    3. Communication methods by trading partner
    4. Trading partners list
    5. Transactions exchanged by trading partner

    • Russ Schamburg

      I am able to capture EDI transaction volumes from our archives which are stored as files on a Unix server. This made the most sense to me as our legal archives are retained way beyond the time period of data on the SI server. Volume statistics is accomplished by a perl program that I have written . The perl program allows entry of run time parameters to specify the selection of data to be either reported and/or captured. There are many, many ways to select the data. Very granular selection allowed.

      Also, I have developed perl DBI programs to capture maps, envelopes, business processes etc. out of the SI database. These programs run via my Windows laptop and attach to our SI systems which are running on Unix servers. A thorough understanding of the SI tables is necessary. Understanding how to insure that only active version of the tables rows are determined. Because all envelope information is not stored in the ENVELOPE table, it is necessary to understand details of the ENVELOPE_PARMS table.

      Perl has a DBI module and also an unzip module. Perl programs can be written to select blobs into memory and also unzip those same blobs in memory. This makes it very easy to write unzipped .map, .mxl, .txo, .BPs, etc. to the file system.

      Unfortunately, IBM/Sterling did not provide all of the tools necessary to answer your questions. Someone will need to think “out of the box” (in this case inside the DB box) and put together SQL select statements to capture some of the data you want. For me it was much easier to write procedural perl programs rather than using pure SQL.

      Russ

      • Kirankanth

        Hello
        I want to take all the active envelops LinkedIn to ISA GS St so that I can take isa 997 control number

        Can anyone help me plz

    • Sabarish

      Did you get these queries? If so could you please post them here.

  9. srini

    can anyone correct this query i am able to pull out but not bale to pull out the other than EDI messages and by protocol
    I am close to 90% of this

    SELECT * FROM (

    SELECT
    TRUNC(TO_DATE(‘2020-09-01 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) – 1, ‘HH24’) as START_DATE,
    TO_DATE(‘2020-10-05 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) as END_DATE,
    SUM(cs5.VALUE) as CNT,
    cs1.VALUE as Partner,
    ‘Inbound’ as Direction,
    cs2.VALUE as Status,
    cs4.VALUE as Transaction
    FROM
    correlation_set cs1, — TP
    correlation_set cs2,
    correlation_set cs3, — Direction
    correlation_set cs4, — Transaction
    correlation_set cs5 — TransactionCount
    WHERE
    cs1.REC_TIME = TRUNC(TO_DATE(‘2020-09-01 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) – 1, ‘HH24’)
    AND cs1.NAME = ‘InterchangeSenderID’
    AND cs2.NAME = ‘Status’
    AND cs3.NAME = ‘Direction’
    AND cs3.VALUE = ‘Inbound’
    AND cs4.NAME = ‘TransactionSetID’
    AND cs5.NAME = ‘TransactionCount’
    AND cs1.OBJECT_ID = cs2.OBJECT_ID
    AND cs1.OBJECT_ID = cs3.OBJECT_ID
    AND cs1.WF_ID = cs4.WF_ID
    AND cs1.OBJECT_ID != cs4.OBJECT_ID — to exclude duplicate EDIFACTs
    AND cs4.OBJECT_ID = cs5.OBJECT_ID — important!
    GROUP BY cs1.VALUE, cs2.VALUE, cs4.VALUE

    UNION ALL

    SELECT
    TRUNC(TO_DATE(‘2020-09-01 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) – 1, ‘HH24’) as START_DATE,
    TO_DATE(‘2020-10-05 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) as END_DATE,
    SUM(cs5.VALUE) as Cnt,
    cs1.VALUE as Partner,
    cs2.VALUE as Direction,
    cs3.VALUE as Status,
    cs4.VALUE as Transaction
    FROM
    correlation_set cs1, — TP
    correlation_set cs2, — direction
    correlation_set cs3, — status
    correlation_set cs4, –transaction id
    correlation_set cs5 — # of transactions
    WHERE
    cs1.REC_TIME = TRUNC(TO_DATE(‘2020-09-01 07:00:00’, ‘yyyy-mm-dd HH24:MI:SS’) – 1, ‘HH24’)
    AND cs1.NAME = ‘InterchangeReceiverID’
    AND cs2.NAME = ‘Direction’
    AND cs2.VALUE = ‘Outbound’
    AND cs3.NAME = ‘Status’
    AND cs4.NAME = ‘TransactionSetID’
    AND cs5.NAME = ‘TransactionCount’
    AND cs1.object_id = cs2.object_id
    AND cs1.object_id = cs3.object_id
    AND cs1.object_id = cs4.object_id
    AND cs1.object_id = cs5.object_id
    GROUP BY cs1.VALUE, cs2.VALUE, cs3.VALUE, cs4.VALUE

    )

    ORDER BY Partner, Transaction, Status

  10. srini

    Can anyone tell me how to get the list of map names only in sterling integrator .

    I can run the report but I am getting all version of the map,

    all I need is only the map names nothing else

  11. Russ Schamburg

    SELECT MAP_NAME FROM MAP_VERSIONS

    Fortunately the map name is in the MAP_VERSIONS table. The MAP table contains one row for every version of the map and that is why you are getting the map names multiple times.

  12. Charmaine

    does the index count still work with ibm sterling b2b integrator ver 6.0.3?
    when i look at the Operations > Systems > Troubleshooter > Database Usage screen its shows Archive Count, Index Count, Purge Count. The query you show for Purge Counts matches the total, but, the query you show for Index Count does not match. Thus wondering if the version 6.0.3 has some change that is not reflected in the sql query. Also, do you have a query for the Archive Count? fyi, i have run the index count query multiple times at the same time i click on the database usage link.
    Thanks for your help

    • Comment by post author

      Editor

      Archive count will be :

      select count(*) from ARCHIVE_INFO where ARCHIVE_FLAG=0

      The Index query above
      SELECT count(*)
      FROM ARCHIVE_INFO
      WHERE ARCHIVE_FLAG in (-1,-2,-5)

      Is extended to give all the records that need to be indexes for all the groups (1 BPs, 2 DOCs) including the records that fail indexing.
      -2 being the ERROR ONLY BPs and -5 are the records that failed indexing.

      To get the same number of records showing in troubleshooter for index count you can run:

      SELECT count(*)
      FROM ARCHIVE_INFO
      WHERE ARCHIVE_FLAG =-1 AND GROUP_ID=1

      • Matteo

        Hello!

        Sorry the question, but what is the diference betwen the group_id 1 and 2

        SELECT count(*)
        FROM ARCHIVE_INFO
        WHERE ARCHIVE_FLAG =-1 AND GROUP_ID=1

        i am runing this query to see the same index from the troubleshooter but i really want to know why is the group 1 and the 2 is not taken in count for the troubleshooter

        Regards,

        Matteo Mottola

      • Matteo

        Oh thanks but why are there 2 entries? Are they processed differently when the housekeeping BP’s run?

        Lastly: are there other GROUP_ID?

        Regards,

        Matteo Mottola

        • Comment by post author

          Editor

          Yes they are processed differently. There are 4 groups in total.
          1 documents
          2 workflow
          3 and 4 visibility and tracking.

          Each group will address a defined set of tables.
          For example for documents group_id the housekeeping processes will look into tables like document, document_lifespan, document_extension, mbx_mailbox, correlation_set, trans_data…
          For workflows , tables like workflow_context, correlation_set, trans_data, wf_inst_s ….
          Tracking and Visibility you maintain tables like: FG_EVENT, FG_EVENTATTR, ACT_SESSION, ACT_XFER tables, Data_flow, abd other FG* tables….

      • Maaz

        Hello,
        The following query shows more results than what I see in Troubleshooter -> Database Usage -> Index. Sterling B2Bi version: 6.1.0.0

        SELECT count(*)
        FROM ARCHIVE_INFO
        WHERE ARCHIVE_FLAG =-1 AND GROUP_ID=1

  13. Jorge Campo

    Hi, can I get some help with a query to update a code list. Im using db2 and this query but got and error

    update CODELIST_XREF_ITEM set TEXT3 = ‘5’ FROM CODELIST_XREF_ITEM, CODELIST_XREF_VERS where CODELIST_XREF_VERS.LIST_NAME = ‘NameCodeList’ and CODELIST_XREF_VERS.DEFAULT_VERSION = CODELIST_XREF_ITEM.LIST_VERSION and CODELIST_XREF_ITEM.SENDER_ITEM =’Sender’ and CODELIST_XREF_ITEM.RECEIVER_ITEM = ‘Receiver’

    The error I got is DB2 SQL Error: SQLCODE=-203, SQLSTATE=42702, SQLERRMC=CODELIST_XREF_ITEM.TEXT3, DRIVER=3.63.123 Thanks

    • Comment by post author

      Editor

      Hi Jorge

      To make the query easy, work first on the inner select, as shown in the example, first to return all the records you want to update then use something like:

      update CODELIST_XREF_ITEM set TEXT3 = ‘5’ where TEXT3 in (select TEXT3 from CODELIST_XREF_ITEM, CODELIST_XREF_VERS where CODELIST_XREF_VERS.LIST_NAME = ‘NameCodeList’ and CODELIST_XREF_VERS.DEFAULT_VERSION = CODELIST_XREF_ITEM.LIST_VERSION and CODELIST_XREF_ITEM.SENDER_ITEM =’Sender’ and CODELIST_XREF_ITEM.RECEIVER_ITEM = ‘Receiver’ )

      I haven’t tested this SQL but the idea is to work separately on the inner select.

    • Eduart Doria

      Hello Jorge,

      Maybe this could work:

      update CODELIST_XREF_ITEM
      set TEXT3 = ‘5’
      where SENDER_ITEM =’Sender’
      and RECEIVER_ITEM = ‘Receiver’
      and LIST_VERSION IN (
      SELECT DEFAULT_VERSION
      FROM CODELIST_XREF_VERS
      WHERE LIST_NAME = ‘NameCodeList’
      )

  14. Syam Prasad

    Dear Team,

    Kindly help, how to delete data from database where extracable count ‘0’ from the database. please help us with query

  15. Lato

    Does anyone knows how to query MDN_Message_ID from MSGMDNCORRELATION table to find doc_name from document table? or other way to link the doc_name to MDN_Message_ID?

  16. Al Scherer

    This is an excellent site! Hey, is it possible to access the queue watcher “all queues” content from SQL? I’d love to be able to keep an eye on the queue depths without having to log onto the queue watcher.

    • Comment by post author

      Editor

      You can use OPSCMD described here:

      In IBM Sterling B2B Integrator how to view queueDepth details if the queueWatcher user interface (UI) is not available?

      Follow the below steps to view the current queue depth and job distribution amongst the queues

      1. Navigate to the directory.
      2. Run the following command from
      directory.

      ./bin/opscmd.sh -nnode1 -cGETQUEUEDEPTH (This is a sum of jobs across all queues on the node)
      ./bin/opscmd.sh -nnode1 -cGETALLQUEUEDEPTHS (Returns a count of jobs waiting to execute on the node per queue)

      If the environment is a cluster, to check the queueDepth on node2 run the following command.

      ./bin/opscmd.sh -nnode2 -cGETQUEUEDEPTH (This is a sum of jobs across all queues on the node)
      ./bin/opscmd.sh -nnode2 -cGETALLQUEUEDEPTHS (Returns a count of jobs waiting to execute on the node per queue)

      Note: The opscmd.sh/cmd script exists in /bin directory. However execute the script from directory as above and not from /bin directory. Because it requires the ops.pid to complete successfully and that exists in the directory.

      https://www.ibm.com/support/pages/node/552527

  17. Niño Fabito

    what table shows the list of SCHEDULES ?

  18. Chandrakala

    How to get the list BP’s are MAPS which are disabled?

  19. Vamsi

    Hi,

    Is it possible to find which processes are currently in active state by process name.

    I’m having issues with a process calling a CLA2 adapter and if multiple processes start at the same time, all processes are timing out and erroring.

Leave a Reply

We’ve detected that you’re using an ad blocker. Please disable it to support our website.