Developer ToolsFree generatorPDF, Excel, Word exportInfor XAAll Infor XA tools

Infor XA IBM i SQL Services Health Query Generator

This generator writes five Db2 for i queries that use IBM i SQL services to check the health of an Infor XA system: largest files, reorganise candidates, inactive users, active XA jobs and history file sizes. Fill in your library and thresholds, then paste the SQL into Run SQL Scripts in IBM i Access Client Solutions.

Fill in

Upper case, as stored in the catalog

Leave blank for all profiles

Leave blank to list jobs in all subsystems

Generated code
Download:

1. Largest files in AMFLIB

-- Largest physical files in the XA library by data space size
SELECT TABLE_NAME,
       NUMBER_ROWS,
       NUMBER_DELETED_ROWS,
       DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
       LAST_CHANGE_TIMESTAMP
  FROM QSYS2.SYSTABLESTAT
 WHERE TABLE_SCHEMA = 'AMFLIB'
 ORDER BY DATA_SIZE DESC
 FETCH FIRST 25 ROWS ONLY;

2. RGZPFM candidates (deleted rows above 20%)

-- Files where deleted records exceed the threshold, with the CL command to run
-- Run RGZPFM only when the file is not in use (XA users and batch stopped, backup taken)
SELECT TABLE_NAME,
       NUMBER_ROWS,
       NUMBER_DELETED_ROWS,
       DEC(NUMBER_DELETED_ROWS * 100.0
           / NULLIF(NUMBER_ROWS + NUMBER_DELETED_ROWS, 0), 7, 2) AS DELETED_PCT,
       DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
       'RGZPFM FILE(' CONCAT TRIM(TABLE_SCHEMA) CONCAT '/'
         CONCAT TRIM(SYSTEM_TABLE_NAME) CONCAT ')' AS RGZ_COMMAND
  FROM QSYS2.SYSTABLESTAT
 WHERE TABLE_SCHEMA = 'AMFLIB'
   AND NUMBER_DELETED_ROWS * 100.0
       / NULLIF(NUMBER_ROWS + NUMBER_DELETED_ROWS, 0) > 20
 ORDER BY NUMBER_DELETED_ROWS DESC;

-- Example CL for one file:
-- RGZPFM FILE(AMFLIB/IMHIST)

3. IBM i user list report: profiles not signed on in 90 days

-- IBM i profiles (prefix '[User profile prefix filter]') with no sign-on in the last 90 days
SELECT AUTHORIZATION_NAME,
       STATUS,
       PREVIOUS_SIGNON,
       TEXT_DESCRIPTION,
       GROUP_PROFILE_NAME
  FROM QSYS2.USER_INFO
 WHERE AUTHORIZATION_NAME LIKE '[User profile prefix filter]%'
   AND (PREVIOUS_SIGNON IS NULL
        OR PREVIOUS_SIGNON < CURRENT TIMESTAMP - 90 DAYS)
 ORDER BY PREVIOUS_SIGNON;

4. Active jobs in the XA subsystem

-- Active jobs, highest CPU first (CPU_TIME is in milliseconds)
-- An empty SUBSYSTEM_LIST_FILTER returns jobs in all subsystems
SELECT JOB_NAME,
       SUBSYSTEM,
       AUTHORIZATION_NAME,
       JOB_STATUS,
       CPU_TIME,
       ELAPSED_CPU_PERCENTAGE
  FROM TABLE(QSYS2.ACTIVE_JOB_INFO(
         SUBSYSTEM_LIST_FILTER => '[XA subsystem name]')) X
 ORDER BY CPU_TIME DESC;

5. XA history file sizes

-- Row counts and size of the main XA history files
SELECT TABLE_NAME,
       NUMBER_ROWS,
       NUMBER_DELETED_ROWS,
       DEC(DATA_SIZE / 1048576.0, 15, 1) AS DATA_MB,
       LAST_CHANGE_TIMESTAMP
  FROM QSYS2.SYSTABLESTAT
 WHERE TABLE_SCHEMA = 'AMFLIB'
   AND TABLE_NAME IN ('IMHIST', 'MOHMST', 'MOHDTA', 'MOHRTG', 'MOHTRN',
                      'POHSTM', 'POHISTI', 'MBFBREP', 'MBDRREP')
 ORDER BY DATA_SIZE DESC;

Needs IBM i 7.2 or later with a current Db2 for i group PTF (SF99xxx) so that QSYS2.SYSTABLESTAT, QSYS2.USER_INFO and QSYS2.ACTIVE_JOB_INFO are present; check column names in IBM Docs for your release. QSYS2.USER_INFO can be slow on systems with many profiles. ELAPSED_CPU_PERCENTAGE is measured from a baseline, so the first run in a connection is not meaningful; run the query twice. Query 3 reports IBM i profiles; XA application users are also defined in AMFLIB/MZF0REP and need their own review.

Get your XA health results reviewed

Send us the output of these five queries and we will point out the files to purge or reorganise first and the profiles worth reviewing.

Optional. The tool and every export work without this. No spam.

Was this tool useful?

How to use it

Set the data library to the XA environment you want to check, normally AMFLIB, in upper case. Choose how many files to list, the deleted-row percentage above which a file is worth reorganising, and the number of days without sign-on that makes a profile inactive. Enter the subsystem your XA interactive and batch jobs run in, or leave it blank to see every active job. Run the queries from Run SQL Scripts with a profile that has read access to the catalog; query 3 needs authority to see other user profiles, which in practice means a security administrator profile. Save the output with the date so you can compare month to month.

What the queries read

QSYS2.SYSTABLESTAT returns one row per table or physical file with NUMBER_ROWS, NUMBER_DELETED_ROWS, DATA_SIZE in bytes and LAST_CHANGE_TIMESTAMP. Deleted records still take space until the file is reorganised with RGZPFM or the space is reused because the file has REUSEDLT(*YES). QSYS2.USER_INFO returns one row per user profile with STATUS, PREVIOUS_SIGNON and GROUP_PROFILE_NAME. QSYS2.ACTIVE_JOB_INFO is a table function; SUBSYSTEM_LIST_FILTER takes up to 25 subsystem names separated by commas, and CPU_TIME is reported in milliseconds.

  • Deleted percent = deleted rows x 100 / (rows + deleted rows)
  • DATA_MB = DATA_SIZE / 1,048,576
  • Profiles that never signed on have a null PREVIOUS_SIGNON and are included

Reading the results

In most XA systems the top of query 1 is dominated by history: IMHIST, MOHTRN and the CO history files. A history file with a high deleted percentage usually means a purge has run but no reorganise followed, so the disk space has not come back. Schedule RGZPFM for those files in a maintenance window with XA users and batch stopped, and take a backup first. In query 3, check each inactive profile against the XA user file before disabling it: a service profile used by an integration can look inactive if it only connects through ODBC with a different profile. Query 4 shows which jobs are using CPU right now.

Version notes and gotchas

SQL services are delivered through the Db2 for i group PTF, so a system that is behind on PTFs may be missing a column or the whole view. If a column is rejected, check IBM Docs for your release and drop it. File names in query 5 come from the XA 9.2.0 definition list; if your site has purged or renamed history, adjust the list. This tool reports IBM i profiles only. XA has its own user file (MZF0REP) and security file (MZGUCPP), and a full user review covers both. For a single-file extract of business data use the separate XA SQL extract generator.

Frequently Asked Questions

How do I get a user list report for Infor XA?

For IBM i profiles, query QSYS2.USER_INFO as in block 3: it returns each profile with status, previous sign-on, description and group profile. XA application users are also held in AMFLIB/MZF0REP, so compare the two lists. Profiles that exist in only one place are the first ones to review.

How do I find which XA files need RGZPFM?

Query QSYS2.SYSTABLESTAT for the XA library and compare NUMBER_DELETED_ROWS with NUMBER_ROWS. Files where deleted rows are more than about 20 percent of the total are worth reorganising. Block 2 builds the RGZPFM command for each one. Run it only with the file not in use, after a backup.

Which IBM i release do these queries need?

IBM i 7.2 or later with a current Db2 for i group PTF. SYSTABLESTAT has existed for a long time, while USER_INFO and ACTIVE_JOB_INFO have gained columns and parameters over several PTF levels. If a query fails with an unknown column, apply the latest group PTF or remove that column.

Is it safe to run these queries during the working day?

Yes, they only read catalog and system information, but QSYS2.USER_INFO can take a while on systems with thousands of profiles and ACTIVE_JOB_INFO adds a short burst of work. Run them from a single session, not from a dashboard that refreshes every few seconds.

If you want these checks run on a schedule and explained in plain English by an assistant on your own IBM i network, we can set that up.

ArchRay builder
Design the on-prem AI stack for Infor XA: model, GPUs, RAG pipeline, guardrails
See memory, speed and cost as you swap parts, then export the diagram. Free, in your browser.
Open the builder

Keep exploring

Free tools

ERP fixes and how-tos

Guides

AI on your ERP

Integrations

Software