rzahfpdf
rzahfpdf
Version 7.2
Database
Database Administration
IBM
Note
Before using this information and the product it supports, read the information in “Notices” on page
25.
This edition applies to IBM i 7.2 (product number 5770-SS1) and to all subsequent releases and modifications until
otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor
does it run on CISC models.
This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is
licensed to you under the terms of the IBM License Agreement for Machine Code.
© Copyright International Business Machines Corporation 1998, 2013.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
Contents
Administration...................................................................................................... 1
What's new for IBM i 7.2..............................................................................................................................1
PDF file for Database administration...........................................................................................................1
Database administration..............................................................................................................................2
Accessing data through client interfaces...............................................................................................2
Altering and managing database objects...............................................................................................3
Creating database objects......................................................................................................................3
Ensuring data integrity........................................................................................................................... 4
Importing and exporting data between systems...................................................................................4
Working with multiple databases...........................................................................................................4
Working with triggers and constraints................................................................................................... 4
Writing DB2 programs............................................................................................................................ 5
Database backup and recovery................................................................................................................... 5
Distributed database administration...........................................................................................................5
Queries and reports..................................................................................................................................... 5
Security.........................................................................................................................................................6
Authority Options for SQL Analysis and Tuning .................................................................................... 6
Row and column access control (RCAC)................................................................................................... 11
Overview............................................................................................................................................... 12
Permissions and masks........................................................................................................................13
SQL statements ................................................................................................................................... 14
Secure functions...................................................................................................................................14
Secure triggers..................................................................................................................................... 14
Administrative authority.......................................................................................................................14
Best practices when using permissions and masks............................................................................15
Classic Query Engine (CQE) and SQL Query Engine (SQE)........................................................................24
Native and open query differences......................................................................................................24
Result set ordering............................................................................................................................... 24
Notices................................................................................................................25
Programming interface information.......................................................................................................... 26
Trademarks................................................................................................................................................ 26
Terms and conditions.................................................................................................................................27
iii
iv
Database administration
Db2® for i provides database administration, backup and recovery, query, and security functions.
You can also explore other database information using the main navigation tree or Database information
finder.
Database administration 3
Ensuring data integrity
Db2 for i provides several integrity measures, such as constraints, trigger programs, and commitment
control.
Constraints, triggers, and commitment control can protect your database against inadvertent insertions,
deletions, and updates. Constraints basically govern how data values can change, while triggers are
automatic actions that start, or trigger, an event, such as an update of a specific table.
Related concepts
Commitment control
Working with triggers and constraints
You can use triggers or constraints to manage data in your database tables.
Database administration 5
• Query Manager Use
In addition, you can build SELECT, INSERT, UPDATE, and DELETE SQL statements in the SQL Assist
window of System i Navigator.
Related concepts
SQL programming
Related tasks
Building SQL statements with SQL Assist
Related reference
Open Query File (OPNQRYF) command
Query (QQQQRY) API
Security
Authorizing users to data at the system and data levels allows you to control access to your database.
Securing your database requires you to establish ownership and public authority to objects and specific
authority to your applications.
Related concepts
DRDA server access control exit programs
Granting file and data authority
Limiting access to specific fields in a database file
Security
Specifying public authority
Using database file capabilities to control I/O operations
Using logical files to secure data
Database administration 7
Figure 2. Expand the Database group
Database administration 9
Table 1 describes some of the authorization changes related to DB2 commands, Stored Procedures, and
APIs.
RCAC terms
• Base table - The table (physical file) the permission or mask is added to.
• Dependent object - Any object (file, schema, function, or other object) the permission or mask
references.
• QIBM_DB_SECADM – The function usage identifer the user must be authorized to in order to manipulate
all actions that are related to permissions and masks.
• Row and Column Access Control (RCAC) – Access control is the ability to control the access to data by
using permissions and masks.
• Permission - A row permission defines a row access control rule for rows of a table.
• Mask - A column mask defines a column access control rule for a specific column in a table.
• RULETEXT – The expression to be used by the permission or mask.
• 5770-SS1 IBM Advanced Data Security for i (Option 47) – Product that needs to be ordered and
installed to be able to:
– create row permissions.
– create column masks.
– execute database access over objects that have active RCAC.
Database administration 11
Overview
IBM Advanced Data Security for i introduces RCAC as an extra layer of data security.
RCAC provides access control to a table at the row level, column level, or both. RCAC can be used to
complement the table privileges model. To comply with various government regulations, you might
implement procedures and methods to ensure that information is adequately protected. Individuals in
your organization are permitted access to only the subset of data that is required to perform their job
tasks. For example, government regulations in your area might state that a doctor is authorized to view
the medical records of their own patients, but not of other patients. The same regulations might also state
that, unless a patient gives their consent, a healthcare provider is not permitted access to patient
personal information, such as the patients home phone number. You can use RCAC to ensure that your
users only have access to the data that is required for their work. For example, RCAC can filter patient
information and data to include only that data, which a particular doctor is authorized to view.
Other patients do not exist as far as the doctor is concerned. Similarly, when a patient service
representative queries the patient table at the same hospital, they are able to view the patient name and
telephone number columns, but the medical history column is masked for them. If data is masked, a
NULL or an alternate value is displayed instead of the actual medical history. RCAC has the following
advantages:
1. No database user is inherently exempted from the RCAC rules. Even high-level authorities such as
users with all object authority (special authority (such as *ALLOBJ)) authority are not exempt from
these rules. Only users with QIBM_DB_SECADM authority can manage RCAC within a database.
Therefore you can use RCAC to prevent users with all object authority from freely accessing all data in
a database.
2. Table data is protected regardless of how a table is accessed. Applications, improvised query tools and
report generation tools are all subject to the access control rules. The enforcement is data-centric.
3. No application changes are required to take advantage of this additional layer of data security. RCAC is
established and defined in a way that is not apparent to existing applications. However RCAC
represents an important shift in paradigm in the sense that it is no longer what is being asked but
rather who is asking. Even though two users can execute what appears to be identical queries, when
row permission predicates are added to the query, those two users might observe a different result
set. This behavior is the exact intent of the solution. It means that application designers and DBAs
must be conscious that queries do not see the whole picture in terms of the data in the table unless
granted RCAC authorization.
4. Prior to RCAC controls for data-centric data protection, DB2 for i users would protect the data through
the creation of several to many SQL views or Select-omit logical files. While this technique of relying
upon a view/logical file to limit data achieves the goal, it creates several problems:
a. Applications had to be coded to work with specialized views, instead of a common object.
b. In large installations, the number of views which exist for this purpose quickly grows to a large
number, resulting in additional object management considerations like Save/Restore.
c. The security officer has to spend time adjusting authorizations to many objects.
d. For select-omit logical files, DB2 for i has to spend processing cycles to keep each select-omit
logical file up to date as the underlying object(s) change.
Besides achieving the benefits of innately secure data when deploying RCAC, DB2 for i customers can
retire the many views which exist solely to protect data.
Separation of duties
Separation of duties helps businesses comply with industry regulations or organizational requirements
and simplifies the management of authorities. Separation of duties is commonly used to prevent
fraudulent activities or errors by a single person. It provides the ability for administrative functions to be
divided across individuals without overlapping responsibilities, so that one user does not possess
unlimited authority, such as with *ALLOBJ authority.
For example, assume that a business has assigned the duty to manage security on IBM i to Theresa. Prior
to release IBM i 7.2, in order to grant privileges, Theresa had to have the same privileges Theresa was
granting. Thus, in order to grant *USE privileges to the PAYROLL table, Theresa had to have *OBJMGT and
*USE authority (or a higher level of authority such as *ALLOBJ). This requirement allowed Theresa to
access data in the PAYROLL table even though Theresa's job description was only to manage security.
In IBM i 7.2, the function usage, QIBM_DB_SECADM, provides a user with the ability to grant authority,
revoke authority, change ownership, or change primary group. This is done without giving access to the
object or, in the case of a database table, to the data that is in the table or allowing other operations on
the table. QIBM_DB_SECADM function usage can only be granted by a user with *SECADM special
authority and can be given to a user or a group.
QIBM_DB_SECADM is also responsible for administering RCAC. RCAC restricts which rows a user is
allowed to access in a table and whether a user is allowed to see information in certain columns of a table.
The best practice is that the RCAC administrator has QIBM_DB_SECADM function usage and absolutely no
data privileges. The RCAC administrator can deploy and maintain the RCAC constructs and would be
unable to grant themselves unauthorized access to data.
Database administration 13
• The definition of each column mask may reference the user or group in the search conditions in the
CASE WHEN clause. While multiple columns in a table may have column masks, only one column mask
can be created for a single column. When column access control is activated for the table, the CASE
expression in the column mask definition is applied to the output column to determine the masked
values that are returned to an application. The application of column masks affects the final output only.
It does not impact the operations, such as predicates and ordering in an SQL statement.
RCAC can be activated for a table before or after row permissions or column masks are created for the
table. If row permissions or column masks exist, activating row and column access control simply makes
the permissions or masks become effective. If row permissions do not yet exist, activating row access
control for a table means that Db2 for i generates a default row permission that prevents any access to
the data in the table.
SQL statements
The SQL create, alter, and drop statements support the implementation of RCAC with permissions and
masks.
• Create Permission
• Alter Permission
• Drop Permission
• Create Mask
• Alter Mask
• Drop Mask
• Alter Function
• Alter Trigger
• Alter Table
Authorization
The authorization ID of the SQL statement must be authorized to the Database Security Administrator
function of IBM i. See Administrative authority.
Secure functions
Functions must be defined as secure before they can be called within RCAC definitions.
The SECURED attribute is required if the UDF is referenced in the definition of a row permission or column
mask because the UDF will have access to data prior to the application of RCAC. The SECURED attribute is
also required for a UDF that is invoked in an SQL statement when the function arguments reference
columns that are activated with column access control.
Secure triggers
Triggers defined on a table with RCAC activated must be secure.
The SECURED attribute is required for a trigger when the associated table has RCAC activated or the
associated view whose underlying table is activated with RCAC. If a trigger exists but is not secure, RCAC
cannot be activated for the associated table.
Administrative authority
Authorization to the Database Security Administrator function of IBM i can be assigned through
Application Administration in IBM Navigator for i.
The Change Function Usage Information (CHGFCNUSG) command, with a function ID of
QIBM_DB_SECADM, can be used to change the list of authorized users.
The advantage of a single permission is the best query performance for applications. The disadvantage is
adding another user, the permission has to be dropped and created to add the new user.
The advantage of a single permission checking a group profile means the permission does not have to
change adding another user. The disadvantage for every query of the base table, the
VERIFY_GROUP_FOR_USER function is checked.
Database administration 15
INSERT INTO RCAC_DEPENDENT.USERS
VALUES('USER1 '),('USER2 '),('USER3 ')
CREATE TABLE MY_LIB.PERMISSION_TABLE (FIELD1 INT)
CREATE PERMISSION MY_LIB.PERM1 ON MY_LIB.PERMISSION_TABLE
FOR ROWS WHERE
CURRENT_USER IN (SELECT USERNAME FROM RCAC_DEPENDENT.USERS)
ENFORCED FOR ALL ACCESS ENABLE
ALTER TABLE MY_LIB.PERMISSION_TABLE ACTIVATE ROW ACCESS CONTROL
/***********************************************************************/
/* Sign on as USER1 */
/***********************************************************************/
INSERT INTO MY_LIB.PERMISSION_TABLE VALUES(1) /* Allowed. */
The advantage of a single permission checking a dependent table is that when adding another user, the
permission does not have to change. The disadvantage is the performance consideration of querying the
dependent table.
The advantage of a single permission checking a UDF is adding another user, the permission does not
have to change. The disadvantage appears when the UDF changed. During the next open of the table with
the permission, verification must be done to allow the new UDF to be used with the permission. The
verification causes the permission or mask to be regenerated once for the table.
The advantage of multiple permissions is the ease of use of having individual permissions. The
disadvantage is having to add another user, a new permission has to be added. The new permission
causes a regeneration of the composite permission used for the table.
/*******************************************************************/
/* The select statement will show the RULETEXT as being qualified. */
/*******************************************************************/
SELECT CHAR(RULETEXT,200) FROM QSYS2.SYSCONTROL
WHERE SCHEMA = 'MY_LIB'
/*******************************************************************/
/* The RULETEXT is now qualified. */
/*******************************************************************/
PERMISSION_TABLE.COLUMN1 IN
(SELECT RCAC_LIB.DEPENDENT_TABLE.COLUMN1 FROM RCAC_LIB.DEPENDENT_TABLE)
Database administration 17
Dependent objects
A number of considerations must be determined to decide how to handle dependent objects of the
permissions and masks.
Ownership
Dependent objects of a permission or mask should be owned by the user profile with the
QIBM_DB_SECADM functional authority and no object management authority should be granted to other
users.
This restricts the possibility of the dependent object being manipulated by an authorized user to change a
permission or mask to allow unintended access to data.
Schema
All dependent tables or views of a permission or mask should be created in a different schema than the
schema of the base table.
If the user executes a Create Duplicate Object (CRTDUPOBJ), or Restore (RSTOBJ) of the base table to a
new schema, the schema names of the dependent objects are not changed. By keeping the dependent
tables and views in a different schema after the CRTDUPOBJ or RSTOBJ of the base table, the newly
created base table references the same dependent objects as the original base table.
If the dependent objects of the permissions and masks are in the same schema, if the user duplicates the
schema, the duplicated permissions and masks reference the objects of the original schema. Therefore,
when cloning a schema and the objects within, the best practice is to use the Generate SQL feature within
IBM i Navigator. By de-selecting the "Schema Qualify Objects" option, the resulting SQL script will no
longer contain schema qualified references within the permissions and masks. The user can precede
execution of the SQL script with a SET SCHEMA statement specifying the target schema.
Schema authority
The schema that contains the dependent objects should not allow object management authority to users.
By not granting object management authority to users, the dependent objects will not be allowed to be
manipulated by users.
Secured UDFs
An SQL user-defined function (UDF) used in the RULETEXT of a permission or mask must be marked as
SECURE.
This same rule applies for any function that may be invoked with a masked column specified as an
argument. The SECURE attribute is stored in the *PGM or *SRVPGM executable that is called when the
UDF is invoked. When the *PGM/*SRVPGM for a SECURED SQL function is restored, the SECURE attribute
that is associated with the function may be lost unless one of the following is true:
• The user doing the restore is authorized to the QIBM_DB_SECADM function.
• The user doing the restore has *SAVSYS special authority.
• The user named QSECOFR is doing the restore.
Old Program Model (OPM) programs cannot be used for functions (UDFs) defined in permissions or masks.
This is because the system cannot verify the program during other database operations such as restore or
rename.
When creating a UDTF or UDF, the default is FENCED, meaning the UDTF or UDF is executed in a
secondary thread. Certain SQL special registers like CURRENT USER may not behave as expected when
referenced in a FENCED UDF. Therefore, when UDTFs or UDFs are used in the RCAC text, use NOT
FENCED.
Restoring objects
Restoring a different version of a dependent object of the base table can impact the existing permissions
and masks.
The process to verify the dependent objects for permissions and masks is done the first time the base
table is opened and not during the restore process.
Therefore, after restoring the dependent objects for the permissions or masks, the system administrator
should include in the process a simple open operation of the base table. This allows the verification to be
completed and avoid verification at application run time.
It is important to ensure that the proper dependent objects of the permissions and masks are restored
when restoring the base tables with the permissions and masks.
Additional operations
A number of considerations must be reviewed creating permissions or masks for a table.
Reclaim Storage
After completing a Reclaim Storage (RCLSTG), any data spaces that are orphaned and found by the
reclaim storage operation are added to the QRCL library as a table.
Since these data spaces could be the result of a base table that had RCAC, the data spaces that are now
tables in QRCL do not have any RCAC. After the RCLSTG completes, the system administrator needs to
query the tables in QRCL and handle (copy the data and delete the table) the tables that need to be
protected with RCAC.
Query Reports
This recommendation applies to query report writer functions such as Query for i or DB2 for i Query
Manager.
When using a web query report writer function, it is recommended, for consistent results, that a sort is
also applied to any column that is used for report break processing. With the application of column masks,
the sorting is done on a column before masks are applied, but the break processing that is done by the
report writer function may be done using masked values. As a result, inconsistent break groupings and
different summary values may be seen when running a query report after masks are defined on the based
table.
MQTs
When populating or refreshing an MQT, it does not account for any predicates or expressions from masks
or permissions on dependent tables.
When the MQT is used for optimization in a query, the underlying row permissions and column masks are
built into the query that uses the MQT. In order for the MQT to be used for optimization, the MQT must
include any columns that are used by the masks or permissions.
Database administration 19
In the following example, the MQT TOTALSALES cannot be used by any query that includes
CreditCardNum because CustID is used by the mask for CreditCardNum but it is not in the select list from
the MQT.
ADDLIBLE MY_LIB
CRTLF FILE(MY_LIB/LF1) SRCFILE(MY_LIB/QDDSSRC)
Database administration 21
CURRENT_USER = 'USER3' ENFORCED FOR ALL ACCESS
The statement would fail with SQ20478 – Row or column access control is not valid.
However, assume for this example, TABLE1 and TABLE2 contain two columns, NAME and SSN. For the
user doing the INSERT, the mask is defined to return the string ‘XXX-XX-nnnn’ when querying TABLE2.
This same type of problem can also occur if the user is running a native database application. A READ
from TABLE2 followed by a WRITE into TABLE1 could result in masked data that is written to the file. Or in
the case of an update, even if the SSN column is not intended to change on the UPDATE, the record being
updated contains the masked value for the SSN column and the SSN column changes.
Two solutions to prevent masked data are provided:
1. BEFORE trigger.
2. CHECK constraint.
Before Trigger Solution
The trigger solution checks the new data that is written into a column and conditionally sets the column to
the current value, or sets it to the DEFAULT.
This is an example of a before insert/update trigger for preventing masked data:
/********************************************************************/
/* Create a mask to give COL2_ssn for DBMGR, but for any other user */
/* mask the column. This table will contain a trigger to ensure the */
/* column can never contain a masked value. */
/********************************************************************/
Attempting an insert or update operation causes the before trigger to be executed and ensure the correct
data into column COL2_ssn.
Check Constraint Solution
The check constraint-based solution provides new SQL syntax to allow the specification of an action to
perform when a violation of the check constraint’s check-condition occurs instead of returning a hard
error. However, if the check-condition continues to fail after the action is taken, a hard error will be
returned and the SQL statement fails with the existing constraint failure, (SQLSTATE=23513,
SQLCODE=-545).
A check constraint with the on-violation-clause is allowed on both the CREATE TABLE and ALTER TABLE
statements.
In the following example, the mask is defined to return a value of ‘XXX-XX-nnnn’ for any query that is not
done by a user profile in the ‘DBMGR’ group. The constraint checks that the column SSN does not have
the masked value.
Database administration 23
Classic Query Engine (CQE) and SQL Query Engine (SQE)
The section explains the native open and query processing differences between CQE and SQE.
For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property
Department in your country or send inquiries, in writing, to:
The following paragraph does not apply to the United Kingdom or any other country where such
provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION
PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of
express or implied warranties in certain transactions, therefore, this statement may not apply to you.
This information could include technical inaccuracies or typographical errors. Changes are periodically
made to the information herein; these changes will be incorporated in new editions of the publication.
IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this
publication at any time without notice.
Any references in this information to non-IBM Web sites are provided for convenience only and do not in
any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of
the materials for this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it believes appropriate without
incurring any obligation to you.
Licensees of this program who wish to have information about it for the purpose of enabling: (i) the
exchange of information between independently created programs and other programs (including this
one) and (ii) the mutual use of the information which has been exchanged, should contact:
IBM Corporation
Software Interoperability Coordinator, Department YBWA
3605 Highway 52 N
Rochester, MN 55901
U.S.A.
Trademarks
IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business
Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be
trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at
"Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml.
26 Notices
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or
trademarks of Adobe Systems Incorporated in the United States, and/or other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the
United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Java and all Java-based trademarks and logos are trademarks of Oracle, Inc. in the United States, other
countries, or both.
Other product and service names might be trademarks of IBM or other companies.
Notices 27
28 IBM i: Database Database Administration
IBM®