SQL for the system administrator – UIIPA- October-2014

advertisement
SQL for the System Administrator
Power Systems 2014
Scott Forstie
[email protected]
DB2 for i Business Architect
For…
1
© 2014 IBM Corporation
SQL for the System Admin
Commands, APIs and tools – consider the options
• IBM i has a long history of creating Commands and APIs, so much
so that we frequently conclude that further investment in these
interfaces is the appropriate approach to deliver new capabilities to
our customers
• The subject of this presentation is to explain the role of SQL based
interfaces to allow non-DB2 for i products and components to
understand that an alternative / additional choice exists
• Development Cost, Value to the customer and Risk are the important
factors to consider for any enhancement
2
© 2014 IBM Corporation
SQL for the System Admin
Commands, APIs and tools – Why consider SQL?
• Even though IBM i customers are used to commands and APIs, they
are not always the easiest interfaces for customers to utilize
(especially if from a client or the web).
• In many cases, customers are required to write specialized programs
to exploit a new IBM i command or API.
• Across the industry, SQL is recognized as a standardized and easy
language to access the database. SQL skills are either commonplace
or customers have a desire to do more with SQL.
• SQL as a language construct does not need to be limited to database
topics.
• SQL can be used on IBM i to easily extract deep details on nondatabase topics. This presentation contains proof of this point.
3
© 2014 IBM Corporation
SQL for the System Admin
Commands, APIs and tools – Why consider SQL?
• With SQL-based options, consider which interface provides the best
“tool for the task”
• Customer feedback SQL based interfaces has been very positive
• Besides being easy to use, SQL queries can be used for:
– Selection (WHERE clause)
– Ordering
– Grouping
– Joining
– Top ‘n’ results
– IN, LIKE, NOT, and more…
Unleash the power of the DB2 for i query engine
4
© 2014 IBM Corporation
SQL for the System Admin
Where to start? Get educated
• Understand the SQL coding environments:
RUNSQL, RUNSQLSTM, Run SQL Scripts, STRSQL, CRTSQLxxxx,
ODBC, JDBC, PHP, DRDA, etc…
• Understand the query engine and optimizer options:
• Understand the SQL coding options:
Explicit 3-part names, Implicit 3-part names, INSERT with remote
subselect, CREATE TABLE with remote subselect, etc...
• Keep the SQL Reference close by
• Like other crafts… with repeated study and practice, your skills will
improve
5
© 2014 IBM Corporation
SQL for the System Admin
New to SQL? Use Navigator’s Run SQL Scripts
• Powerful, graphical interface
IBM i Navigator (aka System i Navigator)
IBM i Access Windows Service Pack
7.1 – SI53584  TR8
Product Download Site:
www-03.ibm.com/systems/power/software/i/access/windows_sp.html
Right click
Next Planned Update…December 31, 2014
6
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  TCP/IP Services
TCP/IP Services
7
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/TCPIP_INFO – view
Client/server identification, logging and other instrumentation is possible using SQL.
The TCPIP_INFO view returns detailed information for the current connection.
SELECT * from QSYS2/TCPIP_INFO
Columns which don’t exist on IBM i 6.1:
SERVER_IP_ADDRESS and SERVER_IP_ADDRESS_TYPE
8
© 2014 IBM Corporation
SQL for the System Admin
TCPIP_INFO – example usage
•
Well defined port numbers - http://bit.ly/ibmiPorts
Now it’s possible (and easy) to deploy interface specific logics with SQL
9
© 2014 IBM Corporation
SQL for the System Admin
TCPIP_INFO – Trigger example
This trigger can have conditional logic when running within a QZDASOINIT job.
Varies by the caller 
10
© 2014 IBM Corporation
SQL for the System Admin
SYSIBMADM/ENV_SYS_INFO – view
•
•
SYSIBMADM/ENV_SYS_INFO catalog returns information about the current server
This is a DB2 family compatible administrative view
11
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Program Temporary Fix (PTF)
PTF Services
12
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/GROUP_PTF_INFO – view
Explore the catalog columns and detail…
SELECT * FROM QSYS2/GROUP_PTF_INFO
13
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/GROUP_PTF_INFO – view
• Use SQL to interrogate PTF Group information
• Alternative to the Work with PTF Groups (WRKPTFGRP) command
• Since this command has no OUTPUT(*OUTFILE) capability, the
command is not easily consumable from a program
-- What PTF Groups will change on the next IPL?
SELECT * FROM QSYS2/GROUP_PTF_INFO
WHERE PTF_GROUP_STATUS = ‘APPLY AT NEXT IPL’
ORDER BY PTF_GROUP_LEVEL DESC
-- What is the most recently installed CUM?
SELECT MAX(PTF_GROUP_LEVEL) AS CUM_LEVEL FROM
QSYS2/GROUP_PTF_INFO
WHERE PTF_GROUP_NAME IN (‘SF99610’,‘SF99710’)
AND PTF_GROUP_STATUS = ‘INSTALLED’
14
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/PTF_INFO – view
• Similar to being able to use SQL to query PTF Group information,
(QSYS2/GROUP_PTF_INFO) you can interrogate PTF information using
a DB2 for i catalog (QSYS2/PTF_INFO)
• Data returned is similar to the QpzListPTF() API output
-- I’m about to IPL, will the IPL impact PTF state?
SELECT PTF_IDENTIFIER, PTF_IPL_ACTION, A.*
FROM QSYS2/PTF_INFO A
WHERE PTF_IPL_ACTION <> 'NONE‘
15
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/PTF_INFO – view
-- Which PTFs are loaded, but not applied?
SELECT PTF_IDENTIFIER, PTF_PRODUCT_DESCRIPTION, A.*
FROM QSYS2/PTF_INFO A
WHERE PTF_LOADED_STATUS = 'LOADED'
ORDER BY PTF_PRODUCT_ID
16
© 2014 IBM Corporation
SQL for the System Admin
SYSTOOLS.GROUP_PTF_CURRENCY View
SELECT * from SYSTOOLS.GROUP_PTF_CURRENCY
WHERE PTF_GROUP_RELEASE = ‘R720’
ORDER BY ptf_group_level_available - ptf_group_level_installed
DESC
Current or
behind on
service?
17
© 2014 IBM Corporation
PTF Group
Info
Level
installed
on this
partition
Level
available
from IBM
Date that
IBM last
updated
this group
SYSTOOLS.GROUP_PTF_CURRENCY View
http://www-912.ibm.com/s_dir/sline003.nsf/PSPbyNumL.xml?OpenView&count=500
XML
namespace
&
structure
18
© 2014 IBM Corporation
SYSTOOLS.GROUP_PTF_CURRENCY View
Study the XML structure to define the data to the HTTP function.
HTTPXML document
structure
TCP/IP Enablement:
‘www-912.ibm.com’ maps to 129.42.160.32
IBM i TCP/IP configuration Technote:
Enablement
http://www-01.ibm.com/support/docview.wss?uid=nas8N1018980
White papers:
• https://ibm.biz/XMLandDB2fori
• https://ibm.biz/HTTPandDB2fori
19
© 2014 IBM Corporation
Developer
resources
SQL catalogs  Journal Services
Journal Services
20
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.JOURNAL_INFO – View
• Use SQL to retrieve detail for local & remote journals
• Information from QjoRetrieveJournalInformation() API, RJRN0100 format.
• The view returns Key 1 & 3 information, one row == information about one journal.
-- Which remote journals are the most heavily used?
SELECT JOURNALED_OBJECTS, A.* FROM QSYS2.JOURNAL_INFO A WHERE
NUMBER_REMOTE_JOURNALS > 0 AND JOURNALED_OBJECTS IS NOT NULL
ORDER BY JOURNALED_OBJECTS DESC
-- Find journals that are nearing the limit of journaled
objects:
SELECT * FROM QSYS2.JOURNAL_INFO WHERE
JOURNALED_OBJECT_LIMIT = '*MAX250K' AND
JOURNALED_OBJECTS > 200000
21
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.JOURNAL_INFO – View
• Use this new source of information to achieve better journal management
• Recognize conditions that require attention
-- Which remote journals fell the farthest behind this week?
SELECT MAXIMUM_TIME_BEHIND, MAXIMUM_BEHIND_TIMESTAMP,
ESTIMATED_TIME_BEHIND, TOTAL_SIZE_JOURNAL_RECEIVERS,
RTRIM(ATTACHED_JOURNAL_RECEIVER_LIBRARY) CONCAT '/' CONCAT
RTRIM(ATTACHED_JOURNAL_RECEIVER_NAME) AS JrnName, A.*
FROM QSYS2.JOURNAL_INFO A WHERE
MAXIMUM_BEHIND_TIMESTAMP > CURRENT TIMESTAMP - 7 DAYS AND
MAXIMUM_TIME_BEHIND > 0 AND MAXIMUM_TIME_BEHIND IS NOT NULL
ORDER BY MAXIMUM_TIME_BEHIND DESC FETCH FIRST 10 ROWS ONLY
22
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/DISPLAY_JOURNAL() – UDTF
• Use SQL to extract data from journals
• Either call the UDTF directly or use IBM i Navigator
• Why use these capabilities over the green screen commands?
 Isolate detail from complex data, efficiently
 Automate frequent audit analysis
 Add logic to applications
 Leverage the SQL Query Engine (SQE) to order, group,
join, transform journal based data
23
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/Display_Journal – User Defined Table Function
Before 7.2 (must specify 15 parameters):
SELECT journal_code, journal_entry_type, object, object_type, X.*
FROM TABLE (
QSYS2.Display_Journal(
'PRODDATA', 'QSQJRN',
-- Journal library and name
'', '',
-- Receiver library and name
CAST(null as TIMESTAMP),
-- Starting timestamp
CAST(null as DECIMAL(21,0)),
-- Starting sequence number
'',
-- Journal codes
'',
-- Journal entries
'',‘’,'',‘',
-- Object library, Object name, Object type, Object member
‘SCOTT',
-- User
'',
-- Job
''
-- Program
) ) AS x
ORDER BY entry_timestamp DESC
With 7.2 (leverage the optional parameters):
SELECT journal_code, journal_entry_type, object, object_type, X.*
FROM TABLE (
QSYS2.Display_Journal(
'PRODDATA', 'QSQJRN',
-- Journal library and name
“USER” => ‘SCOTT’
-- User
) ) AS x
ORDER BY entry_timestamp DESC
24
© 2014 IBM Corporation
SQL for the System Admin
DISPLAY_JOURNAL()  Example: What happened to my SALES data?
-- What rows were deleted from TOYSTORE5/SALES table this week?
select ENTRY_DATA,ENTRY_TIMESTAMP,JOURNAL_ENTRY_TYPE,COUNT_OR_RRN as
ROW_DELETED,"CURRENT_USER", RTRIM(JOB_NUMBER) CONCAT '/' CONCAT
RTRIM(JOB_USER) CONCAT '/' CONCAT RTRIM(JOB_NAME) AS Qualified_Job_Name from
table (
QSYS2.Display_Journal(
'TOYSTORE5', 'QSQJRN', -- Journal library and name
'', '', -- Receiver library and name
CURRENT TIMESTAMP - 7 DAYS, -- Starting timestamp
CAST(null as DECIMAL(21,0)), -- Starting sequence number
'', -- Journal codes
'DL', -- Journal entry type
'TOYSTORE5','SALES','*FILE','SALES', -- Object library, Object name, Object
type, Object member
'', -- User
'', -- Job
'' -- Program
) ) as x
order by entry_timestamp desc ;
25
© 2014 IBM Corporation
SQL for the System Admin
DISPLAY_JOURNAL()  Example: What happened to my SALES data?
-- What data was deleted from PRODDATA/SALES table this week?
select
cast(cast(substring(entry_data,610-610+1,10) as VARCHAR(10) for bit data) as DATE) AS SALES_DATE,
cast(cast(substring(entry_data,622-610+1,15) as VARCHAR(15) for bit data) as varchar(15) ccsid 37) as SALES_PERSON,
cast(cast(substring(entry_data,638-610+1,15) as VARCHAR(15) for bit data) as varchar(15) ccsid 37) as REGION,
cast(cast(substring(entry_data,655-610+1,4) as VARCHAR(4) for bit data) as varchar(4)) as SALES
from table (
QSYS2.Display_Journal(
'TOYSTORE5', 'QSQJRN', -- Journal library and name
'', '', -- Receiver library and name
CURRENT TIMESTAMP - 7 DAYS, -- Starting timestamp
CAST(null as DECIMAL(21,0)), -- Starting sequence number
'', -- Journal codes
'DL', -- Journal entries
'TOYSTORE5','SALES','*FILE','SALES', -- Object library, Object name, Object type, Object member
'', -- User
'', -- Job
'' -- Program
) ) as x
order by entry_timestamp desc
26
© 2014 IBM Corporation
SQL for the System Admin
Navigator  Example: What happened to my SALES data?
Schemas  Journals  View Entries  Enter Filter Criteria
We find the file and use the file format to format the data!
27
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Work Management Services
Work Management Services
28
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/GET_JOB_INFO() – user defined table function
•
•
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
Example 1) Get job information for the current job
select a.* from table(qsys2.get_job_info('*')) a;
Example 2) Get job information for the current job
select a.* from table(qsys2.get_job_info('803868/Quser/Qzdasoinit')) a;
29
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/SYSTEM_VALUE_INFO – view
•
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
Example:
-- Examine the system values related to maximums
SELECT * FROM QSYS2/SYSTEM_VALUE_INFO
WHERE SYSTEM_VALUE_NAME LIKE '%MAX%'
ORDER BY SYSTEM_VALUE_NAME
30
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/SYSTEM_VALUE_INFO – view
DECLARE GLOBAL TEMPORARY TABLE SESSION . Remote_System_Values
( SYSTEM_VALUE_NAME,CURRENT_NUMERIC_VALUE,CURRENT_CHARACTER_VALUE )
AS (SELECT * FROM X1423P2.QSYS2.SYSTEM_VALUE_INFO) WITH DATA
WITH REPLACE;
Remote 3-part
DGTT
statement
SELECT 'LP13UT16' AS "System Name",
A.SYSTEM_VALUE_NAME,A.CURRENT_NUMERIC_VALUE,A.CURRENT_CHARACTER_VALUE FROM
QSYS2.SYSTEM_VALUE_INFO A
LEFT EXCEPTION JOIN SESSION.Remote_System_Values B
ON A.SYSTEM_VALUE_NAME = B.SYSTEM_VALUE_NAME AND
A.CURRENT_NUMERIC_VALUE IS NOT DISTINCT FROM B.CURRENT_NUMERIC_VALUE AND
A.CURRENT_CHARACTER_VALUE IS NOT DISTINCT FROM B.CURRENT_CHARACTER_VALUE
UNION ALL
SELECT 'X1423P2' AS "System Name",
B.SYSTEM_VALUE_NAME,B.CURRENT_NUMERIC_VALUE,B.CURRENT_CHARACTER_VALUE FROM
QSYS2.SYSTEM_VALUE_INFO A
RIGHT EXCEPTION JOIN SESSION.Remote_System_Values B
ON A.SYSTEM_VALUE_NAME = B.SYSTEM_VALUE_NAME AND
Use a query to
find the
SYSVAL
differences
between the
two systems
A.CURRENT_NUMERIC_VALUE IS NOT DISTINCT FROM B.CURRENT_NUMERIC_VALUE AND
A.CURRENT_CHARACTER_VALUE IS NOT DISTINCT FROM B.CURRENT_CHARACTER_VALUE
ORDER BY SYSTEM_VALUE_NAME;
31
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/SYSTEM_VALUE_INFO – view
Example exception join output using SYSTEM_VALUE_INFO.
32
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Command Services
Librarian Services
33
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.LIBRARY_LIST_INFO – view
•
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
Example:
SELECT * FROM QSYS2.LIBRARY_LIST_INFO
34
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Command Services
Message Handling Services
35
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.JOBLOG_INFO – UDTF
•
Job logs contain essential information.
• To understand a failure, job log messages are reviewed
• To understand which CL commands were issued, REQUEST messages in
the job log are reviewed
• Even though trace and failure collection instrumentation exists, job logs are
frequently requested by IBM Service
The JOBLOG_INFO() UDTF provides a new service for application developers
and system managers
A single parameter indicates the target job.
‘*’ can be used to indicate use the current job as the target.
•
•
•
Example 1: Find the most recently executed command in a target job
SELECT MESSAGE_TEXT FROM
TABLE(QSYS2.JOBLOG_INFO('706721/SCOTTF/QPADEV0006')) A
WHERE A.MESSAGE_TYPE = 'REQUEST'
ORDER BY ORDINAL_POSITION DESC
FETCH FIRST 1 ROW ONLY
36
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.JOBLOG_INFO – UDTF
Example 2: Automatic consumption of job log in an application
CREATE OR REPLACE PROCEDURE TOYSTORE.UPDATE_SALES
(IN P_NEW_SALES INTEGER, IN P_SALES_PERSON VARCHAR(100),
IN P_SALES_DATE DATE)
DYNAMIC RESULT SETS 1
LANGUAGE SQL MODIFIES SQL DATA SET OPTION COMMIT = *CHG
BEGIN
DECLARE C_RESULT_SET1 CURSOR WITH RETURN TO CALLER FOR SELECT MESSAGE_ID, MESSAGE_TEXT,
MESSAGE_TYPE FROM SESSION.My_Joblog;
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 ;
CALL TOYSTORE.UPDATE_SALES(3, 'LUCCHESSI', '1995-12-31')
37
© 2014 IBM Corporation
SQL for the System Admin
QSYS2.REPLY_LIST_INFO – view
•
•
One reply list handles system wide automatic response to messages
Now, SQL can be used to:
 Compare (exception join) the configuration of two machines
 Determine whether a specific sequence number is already in use
 Confirm whether setup is complete
REPLY_LIST_INFO matches the Work Reply List Entry (WRKRPYLE) command
behavior of allowing *PUBLIC users to view the reply list information
•
Example:
SELECT * FROM QSYS2.REPLY_LIST_INFO
WHERE message_ID like 'CPA%'
38
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Security Services
Security Services
39
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/GROUP_PROFILE_ENTRIES – view
Use SQL to understand:
•
What Group Profiles exist
•
Which User Profiles belong to specific Group Profiles
•
The text associated with the profile
Handles both:
Group profile . . . . . . . . . GRPPRF
Supplemental groups . . SUPGRPPRF
Example:
select * from qsys2.group_profile_entries
40
© 2014 IBM Corporation
SQL for the System Admin
SYSIBM.AUTHORIZATIONS – view
The AUTHORIZATIONS catalog has been extended to include a new column,
which differentiates users from groups.
The AUTHORIZATIONS view is a DB2 family compatible catalog which contains
one row for every authorization ID.
41
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/USER_INFO – view
•
•
•
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
Example:
-- Which users are having trouble signing on?
SELECT * FROM USER_INFO
WHERE SIGN_ON_ATTEMPTS_NOT_VALID > 0
42
© 2014 IBM Corporation
SQL for the System Admin
USER_INFO & GROUP_PROFILE_ENTRIES
•
Leverage multiple services to answer more interesting questions
--- 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;
43
© 2014 IBM Corporation
SQL for the System Admin
USER_INFO & GROUP_PROFILE_ENTRIES
•
Query results…
44
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/USER_INFO – view
• Extended to include columns that are available to users of the QSYRUSRI() API.
Example:
-- Which enabled users are at risk of becoming disabled due to lack of use?
SELECT * FROM QSYS2.USER_INFO
WHERE STATUS = '*ENABLED' AND LAST_USED_TIMESTAMP IS NOT NULL
ORDER BY LAST_USED_TIMESTAMP ASC
New Columns
FETCH FIRST 20 ROWS ONLY
45
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/USER_STORAGE – view
•
•
•
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
Example:
-- How much storage has user SCOTTF consumed?
SELECT * FROM QSYS2/USER_STORAGE
WHERE USER_NAME = ‘SCOTTF’
46
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/FUNCTION_INFO – view
•
Built upon the data returned by the Retrieve Function Information
(QSYRTVFI, QsyRetrieveFunctionInformation) API
• Any user can examine the function usage identifiers.
• Only users with *SECADM user special authority can examine the function usage
configuration details returned via the QSYS2.FUNCTION_INFO catalog.
• Each row describes the function usage defined on the machine.
Example:
-- Which function usage IDs exist and what is the default configuration?
SELECT * FROM QSYS2/FUNCTION_INFO ORDER BY FUNCTION_ID
47
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/FUNCTION_USAGE – view
•
The detail returned corresponds to the data returned by
the Retrieve Function Usage Information
(QSYRTFUI, QsyRetrieveFunctionUsageInfo) API.
• Only users with *SECADM user special authority can examine the function usage
configuration details returned with this view. Users without *SECADM authority who attempt
to reference this view will get SQLCODE -443.
• Each row corresponds with users or groups that have function usage settings
Example:
-- What function usage has been granted or revoked?
SELECT * FROM QSYS2/FUNCTION_USAGE ORDER BY FUNCTION_ID, USER_NAME
48
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Storage Services
Storage Services
49
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/SYSDISKSTAT – view
The SYSDISKSTAT catalog can be used to quickly and easily understand the DISK
information using SQL.
Examples:
-- Query information for all SSD units
SELECT * FROM QSYS2/SYSDISKSTAT WHERE UNIT_TYPE = 1
-- Query information for all DISKs, order by percentage used
SELECT PERCENT_USED, A.* FROM QSYS2/SYSDISKSTAT A
ORDER BY PERCENT_USED DESC
50
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/SYSTMPSTG – view
•
•
Improved
Observe System-wide Temporary storage consumption
via a new DB2 for i Service: QSYS2/SYSTMPSTG
Read all about it in IBM Knowledge Center:
System Management
with DB2 for i
www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzajq/rzajqviewsystmpstg.htm
-- Which jobs are the top consumers of temporary storage?
SELECT bucket_current_size, bucket_peak_size,
rtrim(job_number) concat '/' concat rtrim(job_user_name) concat '/' concat
rtrim(job_name) as q_job_name
FROM QSYS2.SYSTMPSTG
WHERE job_status = '*ACTIVE'
ORDER BY
bucket_current_size desc
51
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Command Services
Command Services
52
© 2014 IBM Corporation
SQL for the System Admin
QSYS2/QCMDEXC – Procedure
The QCMDEXC procedure can be used within SQL applications to easily execute CL
Commands.
Examples:
• DECLARE V_CPYLIB_COMMAND VARCHAR(500);
DECLARE V_CPYLIB_LEN DECIMAL(15, 5);
SET V_CPYLIB_COMMAND =
'CPYLIB FROMLIB(' CONCAT RTRIM(V_LIBRARY) CONCAT ') TOLIB(' CONCAT
RTRIM(V_NEW_LIBRARY) CONCAT ') DATA(*NO)‘;
SET V_CPYLIB_LEN = CHARACTER_LENGTH(V_CPYLIB_COMMAND);
CALL QSYS2/QCMDEXC(V_CPYLIB_COMMAND, V_CPYLIB_LEN);
• CALL QSYS2/QCMDEXC('ADDLIBLE PRODLIB2',17);
•
Length argument no longer required:
CALL QSYS2/QCMDEXC('ADDLIBLE PRODLIB2');
53
© 2014 IBM Corporation
SQL for the System Admin
DB2 for i built-in Global Variables
Built-in Global Variables
54
© 2014 IBM Corporation
SQL for the System Admin
DB2 for i Built-in Global Variables
•
•
•
The qualified job name of the current connection is easily accessed
When SQL Server Mode is used, the job name of the application instance
which owns the connection is accessed through SERVER_MODE_JOB_NAME
Use these variables to deploy advanced logic in triggers, RCAC rules, and
more
New with
IBM i 7.2
SF99702
Level 3
Available
with
base
IBM i 7.2
55
© 2014 IBM Corporation
Variable name
Schema
Data Type
Size
JOB_NAME
QSYS2
VARCHAR
28
SERVER_MODE_JOB_NAME
QSYS2
VARCHAR
28
CLIENT_IPADDR
SYSIBM
VARCHAR
128
CLIENT_HOST
SYSIBM
VARCHAR
255
CLIENT_PORT
SYSIBM
INTEGER
-
PACKAGE_NAME
SYSIBM
VARCHAR
128
PACKAGE_SCHEMA
SYSIBM
VARCHAR
128
PACKAGE_VERSION
SYSIBM
VARCHAR
64
ROUTINE_SCHEMA
SYSIBM
VARCHAR
128
ROUTINE_SPECIFIC_NAME
SYSIBM
VARCHAR
128
ROUTINE_TYPE
SYSIBM
CHAR
1
SQL for the System Admin
Built-in Global Variables – Client information
SELECT SYSIBM.client_host AS CLIENT_HOST,
SYSIBM.client_ipaddr AS CLIENT_IP,
SYSIBM.client_port AS CLIENT_PORT
FROM LP92UT27.SYSIBM.SYSDUMMY1
•
Two ways to extract the detail
•
Global variables fit nicely into
View definitions &
RCAC masks/permissions
SELECT * FROM LP92UT27.QSYS2.TCPIP_INFO
56
© 2014 IBM Corporation
SQL for the System Admin
SQL catalogs  Landscape view
Landscape
60
© 2014 IBM Corporation
SQL for the System Admin
IBM® DB2® for i Catalogs
Privileges
Catalogs
SYSCATALOGS
INFORMATION_SCHEMA_CATALOG_NAME
Schemas
SYSSCHEMAS
SQLSCHEMAS
SCHEMATA
Database Support
SQL_FEATURES
SQL_LANGUAGES
SQL_SIZING
CHARACTER_SETS
Tables Views Indexes
SYSCOLUMNS
SYSCOLUMNS2
SYSFIELDS
SYSINDEXES
SYSKEYS
SYSTABLEDEP
SYSTABLES
SYSVIEWDEP
SYSVIEWS
Routines
SYSCOLAUTH
SYSCONTROLS
SYSCONTROLSDEP
SYSPACKAGEAUTH
SYSROUTINEAUTH
SYSSCHEMAAUTH
SYSSEQUENCEAUTH
SYSTABAUTH
SYSUDTAUTH
SYSVARIABLEAUTH
SYSXSROBJECTAUTH
SQLCOLPRIVILEGES
SQLTABLEPRIVILEGES
Constraints
SYSCHKCST
SYSCST
SYSCSTCOL
SYSCSTDEP
SYSKEYCST
SYSREFCST
SQLFUNCTIONCOLS
SQLFUNCTIONS
SQLPROCEDURECOLS
SQLPROCEDURES
PARAMETERS
ROUTINES
Triggers
XML Schemas
SQLCOLUMNS
SQLSPECIALCOLUMNS
SQLTABLES
SQLFOREIGNKEYS
SQLPRIMARYKEYS
COLUMNS
TABLES
VIEWS
CHECK_CONSTRAINTS
REFERENTIAL_CONSTRAINTS
TABLE_CONSTRAINTS
SYSCOLUMNSTAT
SYSINDEXSTAT
SYSMQTSTAT
SYSPACKAGESTAT
SYSPACKAGESTMTSTAT
SYSPARTITIONDISK
SYSPARTITIONINDEXES
SYSPARTITIONINDEXDISK
SYSPARTITIONINDEXSTAT
SYSPARTITIONMQTS
SYSPARTITIONSTAT
SYSPROGRAMSTAT
SYSPROGRAMSTMTSTAT
SYSTABLEINDEXSTAT
SYSTABLESTAT
SYSFUNCS
SYSJARCONTENTS
SYSJAROBJECTS
SYSPARMS
SYSPROCS
SYSROUTINEDEP
SYSROUTINES
AUTHORIZATIONS
ROUTINE_PRIVILEGES
UDT_PRIVILEGES
USAGE_PRIVILEGES
VARIABLE_PRIVILEGES
SYSTRIGCOL
SYSTRIGDEP
SYSTRIGGERS
SYSTRIGUPD
Statistics
SQLSTATISTICS
Miscellaneous Objects
SYSPACKAGE
SYSSEQUENCES
SYSTYPES
SYSVARIABLEDEP
SYSVARIABLES
XSRANNOTATIONINFO
XSROBJECTCOMPONENTS
XSROBJECTHIERARCHIES
XSROBJECTS
SQLTYPEINFO
SQLUDTS
DB2 for i catalog views (QSYS2)
ODBC and JDBC
TM
catalog views (SYSIBM)
ANS and ISO catalog views (QSYS2)
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.
Other company, product or service names may be trademarks or service marks of others.
USER_DEFINED_TYPES
SEQUENCES
http://www.ibm.com/systems/i/software/db2/
IBM® DB2® for i Services
Health Center Procedures
QSYS2.HEALTH_ACTIVITY
QSYS2.HEALTH_DATABASE_OVERVIEW
QSYS2.HEALTH_DESIGN_LIMITS
QSYS2.HEALTH_ENVIRONMENTAL_LIMITS
QSYS2.HEALTH_SIZE_LIMITS
QSYS2.RESET_ENVIRONMENTAL_LIMITS
Utility Procedures
QSYS2.CANCEL_SQL
QSYS2.DUMP_SQL_CURSORS
QSYS2.EXTRACT_STATEMENTS
QSYS2.FIND_AND_CANCEL_QSQSRVR_SQL
QSYS2.FIND_QSQSRVR_JOBS
QSYS2.GENERATE_SQL
QSYS2.RESTART_IDENTITY
SYSTOOLS.CHECK_CST
SYSTOOLS.CHECK_SYSROUTINE
Plan Cache Procedures
Application Services
QSYS2.QCMDEXC - PROCEDURE
QSYS2.OVERRIDE_TABLE – PROCEDURE
QSYS2.DELIMIT_NAME – UDF
SYSPROC.WLM_SET_CLIENT_INFO – PROCEDURE
Security Services
QSYS2.FUNCTION_INFO – VIEW
QSYS2.FUNCTION_USAGE – VIEW
QSYS2.GROUP_PROFILE_ENTRIES – VIEW
SYSPROC.SET_COLUMN_ATTRIBUTE - PROCEDURE
QSYS2.SQL_CHECK_AUTHORITY - UDF
QSYS2.USER_INFO – VIEW
System Health Services
QSYS2.SYSLIMTBL - TABLE
QSYS2.SYSLIMITS – VIEW
QSYS2.CHANGE_PLAN_CACHE_SIZE
QSYS2.DUMP_PLAN_CACHE
QSYS2.DUMP_PLAN_CACHE_PROPERTIES
QSYS2.DUMP_PLAN_CACHE_topN
QSYS2/DUMP_SNAP_SHOT_PROPERTIES
QSYS2.END_ALL_PLAN_CACHE_EVENT_MONITORS
QSYS2.END_PLAN_CACHE_EVENT_MONITOR
QSYS2.START_PLAN_CACHE_EVENT_MONITOR (2)
QSYS2.PTF_INFO – VIEW
QSYS2.GROUP_PTF_INFO – VIEW
TCP/IP Services
QSYS2.TCPIP_INFO – VIEW
SYSIBMADM.ENV_SYS_INFO – VIEW
Work Management Services
QSYS2.SYSTEM_VALUE_INFO – VIEW
QSYS2.GET_JOB_INFO – UDTF
Object Services
QSYS2.OBJECT_STATISTICS – UDTF
Storage Services
QSYS2.SYSDISKSTAT – VIEW
QSYS2.SYSTMPSTG – VIEW
QSYS2.USER_STORAGE – VIEW
Journal Services
QSYS2.DISPLAY_JOURNAL – UDTF
QSYS2.JOURNAL_INFO – View
Message Handling Services
QSYS2.JOBLOG_INFO – View
QSYS2.REPLY_LIST_INFO – View
Performance Services
SYSTOOLS.ACT_ON_INDEX_ADVICE - PROCEDURE
SYSTOOLS.HARVEST_INDEX_ADVICE - PROCEDURE
QSYS2.OVERRIDE_QAQQINI - PROCEDURE
QSYS2.RESET_TABLE_INDEX_STATISTICS PROCEDURE
QSYS2.SYSIXADV - TABLE
SYSTOOLS.REMOVE_INDEXES - PROCEDURE
PTF Services
DB2 for i Services
IBM i Services
Librarian Services
QSYS2.LIBRARY_LIST_INFO – View
http://www.ibm.com/developerworks/ibmi/db2
Documentation
•
With IBM i 7.2, these and other
services will be documented within
the “Database Performance and
Optimization” book
•
The Technology Updates wiki
includes fact pages for these
services
www.ibm.com/developerworks/ibmi/techupdates/db2
63
© 2014 IBM Corporation
SQL for the System Admin
Special notices
This document was developed for IBM offerings in the United States as of the date of publication. IBM may not make these offerings available in
other countries, and the information is subject to change without notice. Consult your local IBM business contact for information on the IBM
offerings available in your area.
Information in this document concerning non-IBM products was obtained from the suppliers of these products or other public sources. Questions
on the capabilities of non-IBM products should be addressed to the suppliers of those products.
IBM may have patents or pending patent applications covering subject matter in this document. The furnishing of this document does not give
you any license to these patents. Send license inquires, in writing, to IBM Director of Licensing, IBM Corporation, New Castle Drive, Armonk, NY
10504-1785 USA.
All statements regarding IBM future direction and intent are subject to change or withdrawal without notice, and represent goals and objectives
only.
The information contained in this document has not been submitted to any formal IBM test and is provided "AS IS" with no warranties or
guarantees either expressed or implied.
All examples cited or described in this document are presented as illustrations of the manner in which some IBM products can be used and the
results that may be achieved. Actual environmental costs and performance characteristics will vary depending on individual client configurations
and conditions.
IBM Global Financing offerings are provided through IBM Credit Corporation in the United States and other IBM subsidiaries and divisions
worldwide to qualified commercial and government clients. Rates are based on a client's credit rating, financing terms, offering type, equipment
type and options, and may vary by country. Other restrictions may apply. Rates and offerings are subject to change, extension or withdrawal
without notice.
IBM is not responsible for printing errors in this document that result in pricing or information inaccuracies.
All prices shown are IBM's United States suggested list prices and are subject to change without notice; reseller prices may vary.
IBM hardware products are manufactured from new parts, or new and serviceable used parts. Regardless, our warranty terms apply.
Any performance data contained in this document was determined in a controlled environment. Actual results may vary significantly and are
dependent on many factors including system hardware configuration and software design and configuration. Some measurements quoted in this
document may have been made on development-level systems. There is no guarantee these measurements will be the same on generallyavailable systems. Some measurements quoted in this document may have been estimated through extrapolation. Users of this document
should verify the applicable data for their specific environment.
64
© 2014 IBM Corporation
SQL for the System Admin
Special notices (cont.)
IBM, the IBM logo, ibm.com AIX, AIX (logo), AIX 6 (logo), AS/400, BladeCenter, Blue Gene, ClusterProven, DB2, ESCON, i5/OS, i5/OS (logo), IBM Business Partner
(logo), IntelliStation, LoadLeveler, Lotus, Lotus Notes, Notes, Operating System/400, OS/400, PartnerLink, PartnerWorld, PowerPC, pSeries, Rational, RISC
System/6000, RS/6000, THINK, Tivoli, Tivoli (logo), Tivoli Management Environment, WebSphere, xSeries, z/OS, zSeries, AIX 5L, Chiphopper, Chipkill, Cloudscape, DB2
Universal Database, DS4000, DS6000, DS8000, EnergyScale, Enterprise Workload Manager, General Purpose File System, , GPFS, HACMP, HACMP/6000, HASM, IBM
Systems Director Active Energy Manager, iSeries, Micro-Partitioning, POWER, PowerExecutive, PowerVM, PowerVM (logo), PowerHA, Power Architecture, Power
Everywhere, Power Family, POWER Hypervisor, Power Systems, Power Systems (logo), Power Systems Software, Power Systems Software (logo), POWER2,
POWER3, POWER4, POWER4+, POWER5, POWER5+, POWER6, POWER6+, System i, System p, System p5, System Storage, System z, Tivoli Enterprise, TME 10,
Workload Partitions Manager and X-Architecture are trademarks or registered trademarks of International Business Machines Corporation in the United States, other
countries, or both. If these and other IBM trademarked terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these symbols
indicate U.S. registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered or common law
trademarks in other countries. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml
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.
65
© 2014 IBM Corporation
SQL for the System Admin
Download
Related flashcards

Theory of computation

16 cards

Computer science

25 cards

Software

43 cards

Borland software

18 cards

Create Flashcards