Skip to content

Instantly share code, notes, and snippets.

View forstie's full-sized avatar

Scott Forstie forstie

  • IBM
View GitHub Profile
@forstie
forstie / job queue closing in on max active jobs.sql
Created April 7, 2020 18:40
How do you manage your job queues? Do you have caps on the maximum active jobs? Here's a technique for studying this topic....
-- Resources:
-- https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajq/rzajqudfactivejobinfo.htm
-- https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajq/rzajqviewjobqueueinfo.htm
-- Review job queues, from a percent of capacity consumed perspective
select maximum_active_jobs,
active_jobs,
dec(dec(active_jobs, 19, 2) / dec(maximum_active_jobs, 19, 2), 19, 2) as jobq_percent_consumed,
job_queue_name, job_queue_library, job_queue_status, number_of_jobs,
subsystem_name, subsystem_library_name, sequence_number, held_jobs, released_jobs, scheduled_jobs, text_description,
@forstie
forstie / ALLOBJ users coming in over non SSL network interfaces .sql
Created May 8, 2020 16:54
This is a probe of current network activity, showing what non-SSL interfaces are being used by users who have *ALLOBJ special authority. The idea here is to raise awareness to sensitive data being accessed over unencrypted interfaces.
--
-- Reference: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajr/rzajrservicesandports.htm
--
-- description: Which users with *ALLOBJ (either directly or indirectly via group profile membership) are accessing the IBM i via a non-SSL interface right now?
--
select authorization_name as user_name, j.*
from qsys2.netstat_job_info j
where local_port in (23, 446, 449, 2001, 4402, 5544, 5555, 8470, 8471, 8472, 8473, 8474, 8475, 8476)
and j.authorization_name in (select authorization_name text_description
@forstie
forstie / HIPER PTFs and your IBM i.sql
Created June 3, 2020 22:39
In this Gist, there are two queries to tell you 1) If there are IBM i HIPER PTF Group levels missing from your IBM i and 2) Which IBM i HIPER PTFs are not installed? #SQLcandoit
--
-- Am I current on the IBM i Group Hiper PTF GROUP level?
--
With iLevel(iVersion, iRelease) AS
(
select OS_VERSION, OS_RELEASE from sysibmadm.env_sys_info
)
SELECT P.*
FROM iLevel, systools.group_ptf_currency P
@forstie
forstie / Have we answered the questions.sql
Last active June 9, 2020 20:34
Inquiry messages to the QSYSOPR message queue might be worth answering. Use this query to see which questions have not been answered today. #SQLcandoit
with qsysopr_inquiries_today (msg, asker, text, key) as (
select message_id, from_user, message_text, message_key
from qsys2.message_queue_info
where message_queue_library = 'QSYS'
and message_queue_name = 'QSYSOPR'
and message_type = 'INQUIRY'
and date(message_timestamp) = current_date
),
qsysopr_answers_today (assoc_key) as (
select associated_message_key
@forstie
forstie / Out of storage.sql
Created July 13, 2020 13:12
The IBM i has some built-in facilities to allow you to understand that an 'out of storage' condition exists. Here are some example SQL techniques for managing this alert mechanism.
--
-- Check the configuration of:
-- Maximum system disk pool usage (QSTGLOWACN and QSTGLOWLMT) system values
-- https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzakz/rzakzqstglowacn.htm
-- https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzakz/rzakzqstglowlmt.htm
--
select current_character_value from qsys2.system_value_info
where system_value_name = 'QSTGLOWACN';
stop;
@forstie
forstie / Activation Groups.sql
Created September 22, 2020 14:57
In this Gist, we see how we can query the Db2 for i Health Center and inquire what Environmental Limits shows as the jobs that consumed the most activation groups within a single job, where the activation group executed SQL.
--
-- description: Since the last IPL, which jobs have used the most Activation Groups to execute SQL?
-- resource: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_74/rzajq/rzajqhealthenvlimits.htm
-- minvrm: V6R1M0
--
select b.sizing_name,
a.highwater_mark,
a.when_recorded,
a.job_name,
a.current_user,
@forstie
forstie / Bringing order to the IFS.sql
Last active October 3, 2020 23:40
This example picks on the IFS stream files found within and under the /tmp directory. How much gunk has been accumulated under /tmp and what can you do to manage it? A bit of SQL to the rescue. The IFS_OBJECT_STATISTICS() UDTF returns many elements of data for you to leverage for improved management of the IFS.
--
-- Reference material: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajq/rzajqudfifsobjstat.htm
--
--
-- How much space is used by stream files from /tmp (and subdirs) that haven't been used in 6 months
--
select varchar_format(sum(data_size),'999G999G999G999G999G999G999') tmp_size
from table (
qsys2.ifs_object_statistics(start_path_name => '/tmp',
@forstie
forstie / Smaller Index is nearing a limit.sql
Last active October 30, 2020 15:12
I had a client reach out this week because they encountered the maximum size for an index. (ouch) They had some indexes that were constructed to use a smaller maximum size than what's possible for SQL indexes. This query allows them to monitor when their Max 4GB sized indexes have grown to the level that they are over 60% of the max size.
--
-- Show me the 4GB maximum size database radix indexes that have eclipsed 60% of the maximum allowed size
-- SQL indexes are *MAX1TB (where the maximum size is really closer to 2TB)
-- Non-SQL indexes created with CRTLF can be either *MAX1TB or *MAX4GB
--
-- https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzajq/rzajqserviceshealth.htm
--
WITH OVER_60_PERCENT(Object_Name, limit_id, Sizing_name,
Current_value, Maximum_value, Row_Number) AS
(
@forstie
forstie / Find save files.sql
Last active November 6, 2020 15:58
I was asked to provide an SQL approach that could be used to identify save file that are needlessly chewing up storage. The following examples find those pesky save file and provide some context as to their size and usage.
--
-- description: Find save file objects within QGPL, and order by size descending
--
select a.iasp_name, a.iasp_number, objname, objsize, max(objcreated, change_timestamp) as change_timestamp, last_used_timestamp, objowner, objdefiner
from table (
qsys2.object_statistics(object_schema => 'QGPL', objtypelist => '*FILE')
) a
where objattribute = 'SAVF'
order by objsize desc;
stop;
@forstie
forstie / Well isnt that special.sql
Last active December 3, 2020 18:49
I was asked to provide a technique for the SQL user to access the special authorities granted to user and group profiles, and return the data in a non-list form for ease of reporting and analysis. To accomplish this request, I used the SYSTOOLS.SPLIT table function, but had to be careful to use the perfect split character (3 spaces), trim off bl…
--
-- Complete review of special authorities granted to user profiles
--
select user_name, ordinal_position, ltrim(element) as special_authority
from qsys2.user_info, table (
systools.split(rtrim(special_authorities), ' ')
) b
where user_name not in (select authorization_name
from qsys2.authids
where authorization_attr = 'GROUP');