SQL For The System Administrator
SQL For The System Administrator
For…
• Development Cost, Value to the customer and Risk are the important
factors to consider for any enhancement
TCP/IP Services
Now it’s possible (and easy) to deploy interface specific logic with SQL
This trigger can have conditional logic when running within a QZDASOINIT job.
PTF Services
http://www-912.ibm.com/s_dir/sline003.nsf/PSPbyNumL.xml?OpenView&count=500
XML
namespace
&
structure
Study the XML structure to define the data to the HTTP function.
HTTPXML document
structure
TCP/IP Enablement:
Enablement
‘www-912.ibm.com’ maps to 129.42.160.32
IBM i TCP/IP configuration Technote:
http://www-01.ibm.com/support/docview.wss?uid=nas8N1018980
White papers:
• https://ibm.biz/XMLandDB2fori Developer
• https://ibm.biz/HTTPandDB2fori
resources
20 © 2015 IBM Corporation
SQL catalogs Journal Services
Journal Services
• GET_JOB_INFO() accepts the jobname as input and returns a single row result
table containing detail about that job.
• Enhanced with TR8:
• Use ‘*’ to return detail on the current job
• Current (or most recent) SQL Statement text returned
• The new view return the same data as the Retrieve System Values (QWCRSVAL) API
• *ALLOBJ or *AUDIT special authority is required to retrieve the values for QAUDCTL,
QAUDENDACN, QAUDFRCLVL, QAUDLVL, QAUDLVL2, and QCRTOBJAUD
(‘*NOTAVL’ or -1 are returned when accessed by an unauthorized user):
Catalog definition:
SYSTEM_VALUE_NAME VARCHAR(10) – Name of the system value
CURRENT_NUMERIC_VALUE BIGINT – System value when binary data is returned
CURRENT_CHARACTER_VALUE VARGRAPHIC(1280) – System value when character data is returned
Librarian Services
• With direct access to the library list, SQL users can tap into the library list detail to:
• Programmatically review the environment
• Know when the library list needs to be adjusted
• Derive information about the libraries
IASP Number
Schema vs Library name mapping
User vs System vs Product libraries
Above all else, order of libraries searched for unqualified objects
-- Query the existence & state of the local database and iASPs
SELECT CATALOG_NAME, CATALOG_STATUS, CATALOG_ASPNUM FROM
QSYS2.SYSCATALOGS WHERE CATALOG_TYPE = 'LOCAL‘;
Mainline: BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
DECLARE GLOBAL TEMPORARY TABLE My_Joblog AS
(SELECT * FROM TABLE(QSYS2.JOBLOG_INFO('*')) A)
WITH DATA WITH REPLACE;
OPEN C_RESULT_SET1;
END;
UPDATE TOYSTORE.SALES
SET SALES = SALES + P_NEW_SALES
WHERE SALES_PERSON = P_SALES_PERSON
AND SALES_DATE = P_SALES_DATE;
END Mainline;
END ;
Mainline: BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
INSERT INTO APPLIB.Joblog_Detail
SELECT QSYS2.JOB_NAME, A.* FROM TABLE(QSYS2.JOBLOG_INFO('*')) A
ORDER BY ORDINAL_POSITION DESC
FETCH FIRST 5 ROWS ONLY;
UPDATE TOYSTORE.SALES
SET SALES = SALES + P_NEW_SALES
WHERE SALES_PERSON = P_SALES_PERSON
AND SALES_DATE = P_SALES_DATE;
END Mainline;
40 © 2015 IBM Corporation SQL for the System Admin
QSYS2.JOBLOG_INFO – UDTF
Automatic consumption of job log in an application
call TOYSTORE.UPDATE_SALES(5, 'Frank Salesguy', '2014-1011');
-- Review reply list detail for all messages which begin with ‘CPA’
SELECT * FROM QSYS2.REPLY_LIST_INFO
WHERE message_ID like 'CPA%‘;
Security Services
• Built upon the data returned by the Retrieve User Information (QSYRUSRI) API.
• Users see the data for any *USRPRF to which they have *READ authority
• Setup details, authorizations, and more… easy access to deep details
--
-- Which users have *ALLOBJ authority either directly
-- or via a Group or Supplemental profile?
--
SELECT AUTHORIZATION_NAME, STATUS, NO_PASSWORD_INDICATOR,
PREVIOUS_SIGNON,
TEXT_DESCRIPTION
FROM QSYS2.USER_INFO
WHERE SPECIAL_AUTHORITIES LIKE '%*ALLOBJ%'
OR AUTHORIZATION_NAME IN (
SELECT USER_PROFILE_NAME
FROM QSYS2.GROUP_PROFILE_ENTRIES
WHERE GROUP_PROFILE_NAME IN (
SELECT AUTHORIZATION_NAME
FROM QSYS2.USER_INFO
WHERE SPECIAL_AUTHORITIES like '%*ALLOBJ%'
)
)
ORDER BY AUTHORIZATION_NAME;
47 © 2015 IBM Corporation SQL for the System Admin
USER_INFO & GROUP_PROFILE_ENTRIES
• Query results…
• Extended to include columns that are available to users of the QSYRUSRI() API.
New Columns
Storage Services
• Built upon the data returned by the Retrieve User Information (QSYRUSRI) API.
• Users see the data for any *USRPRF to which they have *READ authority
• User storage is broken down by SYSBAS and iASPs
Command Services
61
ROUTINE_TYPE SYSIBM CHAR 1
SQL for the System Admin
© 2015 IBM Corporation
Built-in Global Variables – Client information
• Two ways to extract the detail
• Global variables fit nicely into view definitions &
RCAC masks/permissions
SELECT SYSIBM.client_host AS CLIENT_HOST,
SYSIBM.client_ipaddr AS CLIENT_IP,
SYSIBM.client_port AS CLIENT_PORT
FROM LP92UT27.SYSIBM.SYSDUMMY1;
CALL scottf.show_GV_values(?,?,?);
• Similar to the routine variables, this can provide easy identification of remote
execution of embedded SQL programs.
Landscape
http://ibm.biz/DB2foriServices
The Power Architecture and Power.org wordmarks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org.
UNIX is a registered trademark of The Open Group in the United States, other countries or both.
Linux is a registered trademark of Linus Torvalds in the United States, other countries or both.
Microsoft, Windows and the Windows logo are registered trademarks of Microsoft Corporation in the United States, other countries or both.
Intel, Itanium, Pentium are registered trademarks and Xeon is a trademark of Intel Corporation or its subsidiaries in the United States, other countries or both.
AMD Opteron is a trademark of Advanced Micro Devices, Inc.
Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in the United States, other countries or both.
TPC-C and TPC-H are trademarks of the Transaction Performance Processing Council (TPPC).
SPECint, SPECfp, SPECjbb, SPECweb, SPECjAppServer, SPEC OMP, SPECviewperf, SPECapc, SPEChpc, SPECjvm, SPECmail, SPECimap and SPECsfs are
trademarks of the Standard Performance Evaluation Corp (SPEC).
NetBench is a registered trademark of Ziff Davis Media in the United States, other countries or both.
AltiVec is a trademark of Freescale Semiconductor, Inc.
Cell Broadband Engine is a trademark of Sony Computer Entertainment Inc.
InfiniBand, InfiniBand Trade Association and the InfiniBand design marks are trademarks and/or service marks of the InfiniBand Trade Association.
Other company, product and service names may be trademarks or service marks of others.