DB2 Server for VSE & VM: Database Administration


Chapter 3. Maintaining Your Database

The previous chapter described how to implement your database design. This chapter deals with the various maintenance tasks you may need to perform to maintain tables and dbspaces. The following tasks are discussed:

Maintaining Tables

Maintaining Dbspaces

Reorganizing Catalog Table Indexes

The catalog tables have indexes to improve the speed of access. Occasionally, you should reorganize these indexes. See Reorganizing Indexes on the Catalog Tables.


Maintaining Tables

After designing and creating a table, you may have to load data into it, copy it, move it from one dbspace to another, move data in it from one application server to another, change an aspect of its design, or remove it from the database.

Loading Data into Tables

This section reviews the possible ways to load data into tables. Many of these methods use the Database Services Utility commands: for more information on these commands, refer to the DB2 Server for VSE & VM Database Services Utility manual.

Loading Data in VM Using the DBS Utility

Interactively

You can load data into tables interactively through the DBS Utility. To do this, invoke the utility so the terminal controls file input (SYSIN). You can then either enter multiple INSERT statements, or execute the DBS Utility DATALOAD TABLE command using the INFILE (*) subcommand.

From a CMS File

The DBS Utility DATALOAD TABLE command will accept input data records in a user-created CMS file. One or more tables can be loaded during a single pass of the data records. The existing data in the tables loaded with this method are not affected. Rows are added to a table through the PREPARE, OPEN, PUT, and CLOSE facilities of SQL.

From a Virtual Reader File

The DBS Utility DATALOAD TABLE command will also accept input data records in a CMS virtual reader file with no header. One or more tables can be loaded during a single pass of the data records. The existing data in the tables loaded with this method are not affected. Rows are added to a table through INSERT statements executed using the PREPARE and EXECUTE facilities of SQL.

Refer to the DB2 Server for VSE & VM Database Services Utility manual for more information.

Loading Data Using the DBS Utility in VSE/ICCF

To load data into a table from data records entered from a terminal, as an alternative to entering multiple INSERT statements, users can use the DBS Utility under VSE/ICCF in conversational mode. To initiate this, enter the following VSE/ICCF control statements:

   /LOAD ARIDBS
   /OPTION GETVIS=AUTO
   /DATA INCON

In response to the prompt to ENTER DATA, the appropriate series of SQL statements or DBS Utility DATALOAD TABLE commands must be entered. After a DATALOAD TABLE command the user must enter the INFILE (*) subcommand to initiate input data record processing and the ENDDATA subcommand to end it. An outline of the interactive terminal input is:

   CONNECT userid IDENTIFIED BY password;
   DATALOAD TABLE (table-name)
     column-name1   1-5
     column-name2   6-7
     
·
·
·
INFILE (*) data record data record
·
·
·
ENDDATA

These commands are described in the DB2 Server for VSE & VM Database Services Utility manual.

Each record (row) is entered in a fixed format as defined by the column specifications in your DATALOAD command. In this example, the user enters column 1 data into typing positions 1-5 of the command line, column 2 data into positions 6-7, and so on.

Do not put quotation marks around character data, and do not use commas to separate data values. Such punctuation can be used outside the data positions of the command line defined by the column specifications of the DATALOAD command.

As an alternative to entering each input data record interactively, the user can embed DBS Utility commands and data records in the VSE/ICCF control statements. An outline of loading a table under VSE/ICCF in a nonconversational manner is:

   /LOAD ARIDBS
   /OPTION GETVIS=AUTO
   /DATA
   CONNECT userid IDENTIFIED BY password;
   DATALOAD TABLE (table-name)
     column-name1   1-5
     column-name2   6-7
     
·
·
·
INFILE (*) data record
·
·
·
ENDDATA

Loading Data from a Terminal Using ISQL INPUT

The ISQL INPUT statement enables a user to enter multiple rows of data into a table. The table name and (optionally) the column names need to be entered only once. The column names, along with their data types, are then displayed in the order that the data must be entered, and the user can then enter data one row at a time.

For data that is similar, the user can use the PF12 RETRIEVE function. That is, the user can retrieve the previous data row entered, and then type over the fields that are different. This can save keystrokes.

Data entered with an INPUT statement is not stored in the table until the INPUT statement is ended by an END statement. ISQL will issue an INSERT statement for every row entered, using the PREPARE and EXECUTE facilities of SQL. However, before the INPUT statement is ended, the data can be committed or backed out by the statement:

SAVE -- Stores all data entered since the last SAVE statement. If no SAVE statement has been issued, it commits all the data since the start of the INPUT statement.
BACKOUT -- Deletes all data entered since the last SAVE statement. If no SAVE statement has been issued, it deletes all the data since the start of the INPUT statement.
CANCEL -- Performs a BACKOUT and also ends the INPUT statement.

Remember that the AUTOCOMMIT mode affects the processing of the SAVE, BACKOUT, and CANCEL statements. For additional information on the ISQL INPUT, SAVE, and BACKOUT statements, refer to the DB2 Server for VSE & VM Interactive SQL Guide and Reference manual.

Loading Data from Sequential Files in VSE

The DBS Utility DATALOAD TABLE command accepts SYSIPT data records or data records contained in a user-created sequential file. One or more tables can be loaded during a single pass of the data records. The existing data in the tables loaded with this method is not affected. The DATALOAD TABLE processing adds rows to a table through the PREPARE, OPEN, PUT, and CLOSE facilities of SQL.

Loading Data from VSAM Files

A VSAM file can be converted to either of the following:

This sequential file can then be identified as the input data file to DBS Utility DATALOAD TABLE processing.
Note:The VSAM REPRO command should never be used to copy the DB2 database itself.

Loading Data from Other Tables

Data can be copied into a table from other tables by using the following methods:

All of these techniques allow the source of the data to be copied to be identified by a view that is defined on one or more tables. A view can be used to identify the target table if the view definition meets the requirements defined for inserting rows into a view.

If referential constraints are in place on tables in which you wish to load data, you should consider whether you would like to enforce constraints while the data is loading or after it is loaded. See Enforcing Referential Constraints for more information.

Copying Tables

To make a copy of an existing table, use the DBS Utility UNLOAD and RELOAD commands.

Example

A user with the user ID SMITH has the SELECT privilege on the SQLDBA.EMPLOYEE table. To make a copy of this table, to be called SMITH.EMPLOYEE, in the PRIVATE dbspace SMITHDB, enter the following commands either in a CMS file called CONTROL DBSINPUT A or in the appropriate job control:

     CONNECT SMITH IDENTIFIED BY SMITHPW;
     UNLOAD TABLE (SQLDBA.EMPLOYEE)  OUTFILE(TEMPFIL);
     RELOAD TABLE (EMPLOYEE) NEW (SMITHDB)
     INTABLE (SQLDBA.EMPLOYEE)  INFILE(TEMPFIL);

To execute these commands in VM, invoke the DBS Utility, as follows:

   FILEDEF TEMPFIL DISK MYDATA |MYFILE A4 (RECFM VBS BLOCK 800
   SQLDBSU SYSIN(CONTROL DBSINPUT A) SYSPRINT(LIST DBSLIST A)

The RELOAD statement creates tables without const raints, losing all referential constraints on the table you are copying. You must reinstate referential constraints later with the ALTER TABLE statement. See Altering Referential and Unique Constraints.

The RELOAD statement with the 'NEW' parameter recreates the table without field procedures. Instead of reloading the table using the 'NEW' parameter, recreate the table to include field procedures and reload the table using the 'PURGE' parameter.

Moving Tables from One Dbspace to Another

To move a table from one dbspace to another, you must first unload it using the DBS UNLOAD command, drop it from the database, then reload it into the new dbspace. When a table is dropped, all indexes, privileges, views, primary and foreign keys, and unique constraints for it are removed, and must be re-established.

As well, if a table has field procedures associated with it, the table should be dropped and recreated to include the field procedures and reloaded using the 'PURGE' parameter.

Example

User SMITH has a table (called SMITH.MYTABLE) that he wishes to move from the SMITH.PERSONAL dbspace to the SMITH.SECRET dbspace.

Enter the following commands in either a CMS file called CONTROL DBSINPUT A, or inside the appropriate job control:

   CONNECT SMITH IDENTIFIED BY SMITHPW;
   UNLOAD  TABLE (SMITH.MYTABLE) OUTFILE(TEMPFIL);
   DROP    TABLE SMITH.MYTABLE;
   RELOAD  TABLE (SMITH.MYTABLE)
           NEW (SMITH.SECRET) INFILE(TEMPFIL);

In VM you run these commands by invoking the DBS Utility, as follows:

   FILEDEF TEMPFIL DISK MYDATA |MYFILE A4 (RECFM VBS BLOCK 800
   SQLDBSU SYSIN(CONTROL DBSINPUT A) SYSPRINT(LIST DBSLIST A)

Merging Data from Multiple Tables

It may be necessary to combine all columns or a subset of the columns from different tables into a new table. You can do this through ISQL or the DBS Utility using the following procedure:

  1. Create the new table with a CREATE TABLE statement.
  2. Insert rows into the new table by selecting columns from the source tables with an INSERT with Subselect statement.
  3. Execute an UPDATE STATISTICS statement against the new table.
  4. Create the required indexes for the new table with CREATE INDEX statements.
  5. Create the required views on the new table.
  6. Grant the required authorizations on the new table and views.
  7. If necessary, redefine the views on the old tables to eliminate access to the columns merged into the new table.

To identify authorizations and views on the old tables, you can query the system catalog with a SELECT statement entered through ISQL or the DBS Utility. The following tables contain information pertinent to this task:

Example

To identify the base tables for the view ORGANIZATION, enter the following query:

   SELECT BNAME FROM SYSTEM.SYSUSAGE
     WHERE DNAME = 'ORGANIZATION'

To identify the view definitions, enter the following query:

   SELECT VIEWTEXT FROM SYSTEM.SYSVIEWS
     WHERE VIEWNAME = 'ORGANIZATION'

To identify the users who have privileges to access the view or its base tables, enter the following query:

   SELECT GRANTEE, STNAME FROM SYSTEM.SYSTABAUTH
     WHERE TTNAME = 'ORGANIZATION'

If a view is defined for all the columns required in the new table, steps 1, 2, and 3 (needed to merge data from multiple tables) can be replaced by the following:

  1. Enter the DBS Utility UNLOAD command to unload the view.
  2. Enter the DBS Utility RELOAD command to create and load the new table.
  3. Process an UPDATE STATISTICS statement for the new table, if necessary. By default, this statement is performed for each table loaded during RELOAD TABLE command processing. For more information, see the DB2 Server for VSE & VM Database Services Utility manual.

Examples

In VM: Include the following SQL statements and DBS Utility commands within your DBS Utility control file to perform the above task:

   CONNECT userid IDENTIFIED BY userpw;
   UNLOAD TABLE creator.viewname OUTFILE(DUMPFIL);
   RELOAD TABLE creator.newtablename NEW INFILE(DUMPFIL);

Invoke the DBS Utility, as usual, to process the above statements and commands.

 

In VSE: Use the following job control commands, SQL statements, and DBS Utility commands to perform the above task:

   // JOB MERGE DATA
   // EXEC PROC=DBNAME01
   // ASSGN SYS005,...
   // ASSGN SYS004,...
   // TLBL DUMPFIL,...
       
·
·
·
CONNECT userid IDENTIFIED BY userpw; UNLOAD TABLE creator.viewname OUTFILE(DUMPFIL) RELOAD TABLE creator.newtablename NEW INFILE(DUMPFIL) /&

See the DB2 Server for VSE & VM Database Services Utility manual for details.

Altering the Design of a Table

If you want to change the design of a table after it has been created, use the SQL ALTER TABLE statement. This will not change the data in the table; only its specifications. You can:

When you alter a table, information in the system catalog about it is also changed. For example, when you add a new column to a table, SYSTEM.SYSCOLUMNS is changed to record it, and the field in there that records the number of columns is increased by one.

Authorization

To alter a table, you must have the ALTER privilege on it, and if the operation involves a primary key you must have the ALTER privilege on all dependent tables as well. If the operation involves a foreign key, you must have the REFERENCES privilege on the parent table.

You can alter any table if you have DBA authority.

You cannot delete a column, change the name of a column, change the data type of a column, or add or change a field procedure for a column for existing tables using the ALTER TABLE statement. To do these operations, you must drop the existing table and re-create it.

Example

There are two ways to change the data type of the DEPTNAME column of the DEPARTMENT table from VARCHAR(36) to VARCHAR(40):

Adding a New Column

When you add a column to an existing table, it is placed on the far right.

The physical records are not actually changed until users insert values in the new column, so access time to the table is not affected immediately. After values are inserted, however, this could impact performance by forcing rows onto another physical page. To avoid that situation, define enough free space on each page ahead of time.

You cannot define the new column as NOT NULL; it must allow NULL values.

Example

Add a new column to the table DEPARTMENT, containing a location code for the department. The column name is LOCNCODE, and its data type is CHAR (4).

   ALTER TABLE DEPARTMENT
     ADD LOCNCODE CHAR (4)

Table 15 shows part of the original table.

Table 15. Before Adding a New Column to a Table
DEPTNO DEPTNAME MGRNO ADMRDEPT
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00
B01 PLANNING 000020 A00
C01 INFORMATION CENTER 000030 A00

Table 16 shows the table after adding the new column and updating a location code in the third row.

Table 16. After Adding a New Column to a Table and Updating a Row
DEPTNO DEPTNAME MGRNO ADMRDEPT LOCNCODE
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 ?
B01 PLANNING 000020 A00 ?
C01 INFORMATION CENTER 000030 A00 B126

Altering Referential and Unique Constraints

If you plan to let the database manager enforce referential integrity in a set of tables, see Considerations for Referential Integrity when Creating Tables and Specifying a UNIQUE Constraint.

The following terms are used in the discussion of the ALTER TABLE statement:

Inactive Key or Constraint
A primary key, a foreign key, or a unique constraint that has been made inoperable by the ALTER TABLE ... DEACTIVATE statement. Neither referential nor unique constraints are enforced until the related keys are activated.

Implicitly Inactive Key
A foreign key that is not explicitly inactive, but references a table with an inactive primary key. A referential constraint is not enforced until the related primary key is activated.

Inactive Table
A table that contains an inactive or implicitly inactive key, or contains an active primary key referenced by an inactive foreign key. This limits access to the table to the creator or a DBA, and allows deferred constraint enforcement.

Dependently Inactive Table
A dependent table or foreign key that has been flagged as inactive because the primary key of its parent table has been deactivated.

Table 17 is a summary of the authorization required to alter referential constraints.

Table 17. Authorization Required when Altering Referential Constraints
Statement Parent Table Dependent Table
ADD
Primary Key
Foreign Key
 
A
R
 
 
A
DROP
Primary Key
Foreign Key
 
A, R(1)
R
 
A
A
ACTIVATE
Primary Key
Foreign Key
All
 
A, R(1)
R
A, R(1)
 
A
A
A
DEACTIVATE
Primary Key
Foreign Key
All
 
A, R(1)
R
A, R(1)
 
A
A
A
Note:ALTER privilege is required when A appears. REFERENCES privilege is required when R appears, and (1) applies when a dependent table exists.

Considerations When Adding Keys or Constraints

The following restrictions apply when you add a primary key, a foreign key, or a unique constraint to an existing table:

For further information on referential integrity, refer to Elements of Referential Integrity.

Considerations When Dropping a Primary or Foreign Key

The following restrictions apply when you drop a primary key or a foreign key from an existing table:

In both situations, you should consider carefully the effects on your application programs of dropping keys. The primary key of a table is intended to serve as a permanent, unique identifier of the occurrences of the entities it describes, and quite likely some of your programs depend on that. The foreign key defines a referential relationship and a delete rule, and without it your programs must enforce the constraints.

Considerations When Activating Keys and Constraints

Primary Key

To activate a primary key you must have ALTER privilege on the parent and dependent tables and REFERENCES privilege on all dependent tables.

If any dependent foreign keys were deactivated implicitly when the primary key was made inactive, they will be verified against the primary key. If the primary key index can be created successfully and the dependent foreign key values are found in the parent table's primary key, then the primary key and the dependent foreign keys will be activated. If any of these processes fail, none of the keys will be activated.

Activating the primary key will neither verify nor affect the status of any dependent foreign keys that were deactivated explicitly with the ALTER TABLE table-name DEACTIVATE FOREIGN KEY statement.

Foreign Key

To activate a foreign key you must have ALTER privilege on the dependent table and REFERENCES privilege on the parent table.

If a foreign key is already active, attempts to activate it are ignored. If the primary key of the parent table referenced by this foreign key is inactive, the foreign key cannot be activated. Otherwise, the inactive foreign key will have its values verified against its parent table. If all values can be found in the parent's primary key, the foreign key will be activated.

Unique Constraint

To activate a unique constraint you must have ALTER privilege on the table. The unique constraint will be activated only if all values in its key are unique. If there are duplicate values you must change them to be unique before the constraint can be activated.

All

To activate the primary key, each unique constraint, and each explicitly inactive foreign key in a table, use the ACTIVATE ALL option. You must have the required ALTER and REFERENCES privileges.

Implications of Activating a Primary Key or Unique Constraint

Activating a primary key or unique constraint that is already active causes the unique index associated with the key or constraint to be reorganized. This is more efficient than deactivating the key or constraint (which would drop the underlying index), and then activating the key or constraint (which would re-create the underlying index). For more information on the benefits of reorganizing an index, see the DB2 Server for VSE & VM Diagnosis Guide and Reference manual.

Considerations When Deactivating Keys and Constraints

Primary Key

Deactivating a primary key drops the primary key index from the parent table and implicitly deactivates all active dependent foreign keys. This limits the access to all inactive dependent tables to the creator or a DBA, and allow deferred constraint enforcement. For information on deferred constraint enforcement see Enforcing Referential Constraints.

To deactivate a primary key you must have ALTER and REFERENCES privileges on the parent table, and ALTER privilege on all dependent tables.

Foreign Key

To deactivate a referential constraint that is active, you must have ALTER privilege on the dependent table and REFERENCES privilege on the parent table.

If a foreign key has been explicitly deactivated already, attempts to deactivate it again are ignored.

Deactivating a foreign key will make the two tables in the relationship inactive. Access to the inactive table is limited to the creator or a DBA. For information on the effects of deactivating a foreign key, see Advantages and Disadvantages of Deferred Constraint Enforcement.

Unique Constraints

Deactivating a unique constraint drops the unique index associated with the constraint, causing the table to become inactive. This will limit access to the table to its creator or a DBA.

Enforcing Referential Constraints

Two forms of enforcement are possible:

Advantages and Disadvantages of Deferred Constraint Enforcement

You may want to deactivate the enforcement of referential integrity among tables to improve performance when you are loading data into a table.

When referential integrity is active between two tables, each INSERT statement on a dependent table causes a check to be issued against the parent table. This check verifies that the foreign key value being inserted has a matching primary key value in the parent table. When data is being loaded into a dependent table, each inserted row causes a check of the parent table; if many rows are being loaded, the overhead of this checking becomes significant. In this case, you may improve your overall performance of the load by deactivating any referential constraints. When the load completes, you then reactivate them to validate the data.

If referential integrity is in effect at the beginning of an LUW, and the constraints are deactivated, the data loaded and the constraints re-activated all within the same LUW, then referential integrity exists at the end of the LUW as well. However, within that LUW, referential constraints are not enforced. You could load rows into the dependent table that had no parents when loaded. Since the database can be in an inconsistent state during an LUW, but not at its completion, you can use a more flexible sequence of statements within an LUW. At some point you must load parent rows for the dependent rows into the parent table. Otherwise, you would be unable to reactivate the referential constraint. There are some disadvantages to deactivating a referential constraint between tables:

Repairing Rows that Violate Referential Constraints

If you deactivate a referential constraint in order to load data, then receive an error when you try to reactivate it, it could be for one of the following reasons:

Note:When the above error occurs, SQLCODE -667 (SQLSTATE 22519) and the name of the constraint in error are returned as a message token in SQLCA.

Isolating Duplicate Primary Key Values

To find duplicate primary key values, use the statement shown below. In the example, the name of the table is P1, and the primary key is represented by the columns PKCOL1, PKCOL2, and so on, for all columns that form the primary key:

  SELECT PKCOL1, PKCOL2, ... FROM P1
     GROUP BY PKCOL1, PKCOL2, ...
     HAVING COUNT(*) > 1

You could then eliminate the duplicate values with UPDATE and DELETE statements, or move them to a special table if you do not want to eliminate them immediately.

To move the rows to a special table (called an EXCEPTION table in this explanation), create a table with the same column definitions as the original table (but with no key definitions). If there are many duplicate values, you may want to create a nonunique index for the duplicate primary key columns in the EXCEPTION table to improve performance.

Use the statements shown below to copy the rows with duplicate primary key values into the EXCEPTION table (called E1 in this example):

   INSERT INTO E1
      SELECT * FROM P1 A WHERE EXISTS
         (SELECT PKCOL1, PKCOL2, ...  FROM P1 B
            GROUP BY PKCOL1, PKCOL2, ...
            HAVING COUNT(*) > 1
                   AND B.PKCOL1 = A.PKCOL1
                   AND B.PKCOL2 = A.PKCOL2
                   ... )

To remove these rows from P1, use this statement:

   DELETE FROM P1 A  WHERE EXISTS
      (SELECT 1 FROM E1
          WHERE E1.PKCOL1 = A.PKCOL1
            AND E1.PKCOL2 = A.PKCOL2
            ... )

Isolating Nonmatching Foreign Key Values

Foreign key values may not match primary key values because either of them may be wrong. This example shows you how to move the nonmatching foreign keys to a separate table. Then, you can determine whether the foreign or the primary keys are wrong, and fix them with INSERT, UPDATE, or DELETE statements.

This statement retrieves nonmatching foreign key values. In the example, P1 is the parent table; C1 is the dependent table; PKCOL1, PKCOL2, and so on form the primary key; and FKCOL1, FKCOL2, and so on form the foreign key.

   SELECT FKCOL1, FKCOL2, ...  FROM C1 A
      WHERE (FKCOL1 IS NOT NULL AND
             FKCOL2 IS NOT NULL AND
              ... )
        AND NOT EXISTS
            (SELECT 1 FROM P1 B
                WHERE  B.PKCOL1 = A.FKCOL1 AND
                       B.PKCOL2 = A.FKCOL2 AND
                       ... )

To move the rows to a special table (called an EXCEPTION table in this explanation), create a table with the same column definitions as the dependent table (but with no key definitions). If there are many duplicate values, you may want to create a nonunique index for the foreign key columns in the EXCEPTION table to improve performance. To copy the rows with nonmatching foreign keys to the EXCEPTION table (E1 in this example), use the following statement:

   INSERT INTO E1
      SELECT * FROM C1 A
         WHERE (FKCOL1 IS NOT NULL AND
                FKCOL2 IS NOT NULL AND
                ... )
         AND NOT EXISTS
               (SELECT 1 FROM P1 B
                   WHERE  B.PKCOL1 = A.FKCOL1 AND
                          B.PKCOL2 = A.FKCOL2 AND
                          ... )

To remove the rows from C1, use the following statement:

   DELETE FROM C1 A  WHERE EXISTS
      (SELECT 1 FROM E1
          WHERE E1.FKCOL1 = A.FKCOL1
            AND E1.FKCOL2 = A.FKCOL2
            ... )

Moving Data from One Application Server to Another

You can use the DBS Utility to move data from one application server to another.

Moving data from a DB2 Server for VSE & VM application server to a remote DRDA application server requires unloading the data from the DB2 Server for VSE & VM application server using the DBS Utility DATAUNLOAD command and reloading the data into the other application server using the DBS Utility DATALOAD command. Moving data from one DB2 Server for VSE & VM application server to another local DB2 Server for VSE & VM application server can be done as above, or by using the DBS Utility UNLOAD and RELOAD commands.

For more information about DBS Utility commands, refer to the DB2 Server for VSE & VM Database Services Utility manual.

Notes:

  1. When moving data between two application servers, ensure that the appropriate coded character set identifier (CCSID) conversion is done to maintain the correct interpretation of the data.

    For example, an application server uses a CHARNAME value of ENGLISH (or the CCSID equivalent), and another application server uses a CHARNAME value of GERMAN (or the CCSID equivalent). Issue the SQLINIT EXEC |(in VM), the transaction DSQU (in CICS), or the VSE batch program |ARIRBGUD (JCL: ARISBGUD.Z) and specify a CHARNAME for the application requester corresponding to the CHARNAME of one of the application servers (either ENGLISH or GERMAN). Then, to ensure the integrity of the data when moving it between these two application servers, specify the same CHARNAME value for the application requester for both the DATAUNLOAD (or UNLOAD) and DATALOAD (or RELOAD) operations. If ENGLISH is the CHARNAME value specified for the application requester for the data unload operation, then it must also be set to ENGLISH for the data load operation. You can then perform the data unloading and reloading operations.

    For more information on CCSID conversion, see the DB2 Server for VSE System Administration manual.

  2. If you want to move data from one DB2 Server for VSE application server to a DB2 Server for VM application server |(not using Guest Sharing), or vice versa, using the DBS Utility UNLOAD command, you can only do so when using a tape.

Removing Tables

To remove tables from the database, use the DROP TABLE statement. For example, to remove a table called PROJECT, enter:

    DROP TABLE PROJECT

Only the table's creator or a user with DBA authority can remove the table. If you have DBA authority, include the user ID of the owner to remove a table. For example, to remove SMITH's table called PROJECT, enter:

    DROP TABLE SMITH.PROJECT

When a table is dropped, the row in the SYSTEM.SYSCATALOG catalog table that contains information about it is deleted. Any other objects that depend on that table are also dropped. As a result:

You must commit the DROP statement on a table before you can re-create a table of the same name, or before you can create any new indexes with the same name as an index on the table being dropped.


Maintaining Dbspaces

Altering the Design of a Dbspace

You may need to change the parameters of a dbspace for any of the following reasons:

For a review of these parameters, see Acquiring Dbspaces.

Changing the PAGES, STORPOOL, DBSPACE Type, NHEADER, or PCTINDEX

There is no statement to change these five parameters of a dbspace. If you need to change any of them, you must move all the data in the current dbspace to another dbspace that has the required characteristics. To do this:

  1. UNLOAD the current dbspace.
  2. DROP the current dbspace.
  3. ACQUIRE a new dbspace with the required characteristics.
  4. RELOAD the new dbspace.
  5. Drop the table with field procedures, recreate it to include the field procedures, and reload the table using the 'PURGE' parameter.
  6. CREATE all indexes for the tables involved.
  7. Recreate all referential constraints.
  8. GRANT all authorizations for the tables involved.
  9. CREATE all views relating to the tables involved.

To identify the tables, views, authorizations, and referential constraints related to the dbspace, query the system catalog.

To identify the tables with field procedures, query the SYSFILEDS and SYSFPARMS tables.

Example

To increase the storage capacity of a PRIVATE dbspace called SMITH.SAMPLE to 2 048 pages with defaults for the other dbspace parameters, use the following SQL statements and DBS Utility commands:

   CONNECT SQLDBA IDENTIFIED BY SQLDBAPW;
   UNLOAD DBSPACE (SMITH.SAMPLE)  OUTFILE (TEMPFIL);
   DROP DBSPACE SMITH.SAMPLE;
   ACQUIRE PRIVATE DBSPACE NAMED (SMITH.SAMPLE) (PAGES=2048);
   RELOAD DBSPACE (SMITH.SAMPLE)  NEW  INFILE(TEMPFIL);

Invoke the DBS Utility, as usual, to process the above statements and commands (see the DB2 Server for VSE & VM Database Services Utility manual for details).

Indexes, views, authorizations, and referential constraints must be recreated for all the tables in the dbspace.

Changing the PCTFREE and LOCK Parameters

To change these parameters, use the ALTER DBSPACE statement. You must have DBA authority or (in the case of a PRIVATE dbspace) be the owner of the dbspace.

Example

Change the PCTFREE parameter to 10 for the dbspace called MYDBSPACE. type:

   ALTER DBSPACE MYDBSPACE (PCTFREE = 10)

To change both the PCTFREE and the LOCK parameters at the same time, type:

   ALTER DBSPACE MYDBSPACE (PCTFREE = 10, LOCK = PAGE)

Reorganizing a Dbspace to Free Storage Pool Pages

Reorganizing a dbspace releases pages in it back to its storage pool. There are two reasons why you might want to do this:

To reorganize a dbspace, follow these steps:

  1. Unload all tables in the dbspace, except those that should be dropped.
  2. Drop the dbspace (see note 1 below).
  3. Reacquire the dbspace.
  4. Reload the tables (see note 2 and 4 below).
  5. Re-create all indexes and unique constraints for all tables.
  6. Grant all authorizations for the tables again.
  7. Re-create all referential constraints for tables (see note 3 below).
  8. Re-create all views that reference the tables.

Notes:

  1. Before dropping the dbspace, obtain the information necessary to perform steps 5, 6, 7, 8, and note 4 below from the catalog tables.

  2. The RELOAD TABLE commands create all tables by default with the user ID of the person who enters the commands, usually the DBA. If you want a table to retain the user ID of its original owner, specify this user ID in the table parameter of the RELOAD TABLE command. When performing this procedure, use the NEW option on the RELOAD TABLE and RELOAD DBSPACE commands. See the DB2 Server for VSE & VM Database Services Utility manual for more details.

  3. If a table has referential constraints, these will be lost when the table is unloaded and reloaded. To re-create any foreign keys, primary keys, unique constraints, or primary keys that have dependent foreign keys in tables that reside in other dbspaces, use the ALTER TABLE statement.

  4. If a table has field procedures, they will be lost when the table is reloaded using the 'NEW' option. To include the field procedures, drop the table, recreate it, and reload the table using the 'PURGE' option.

Removing Dbspaces

To drop the contents of a dbspace and return it to the available state, issue the DROP DBSPACE statement. Dbspaces that are available can then be reacquired, using the ACQUIRE DBSPACE statement.

When a dbspace is dropped, all tables in it are also dropped. When a table is dropped, all authorizations, views, referential constraints, unique constraints, and field procedures relating to it are dropped.

If a dbspace contains only one table, it is more efficient to drop and then reacquire the entire dbspace later, than to drop the table.

The DROP DBSPACE statement may be carried out on both PUBLIC and PRIVATE dbspaces. You must have DBA authority to delete a dbspace or (in the case of a PRIVATE dbspace) be the owner. No user, not even one with DBA authority, can delete the dbspace that contains the system catalog.

Example

To remove your own PRIVATE dbspace named MYDBSPACE, type:

   DROP DBSPACE MYDBSPACE

VSAM Restrictions

VSAM defines storage for DB2 Server for VSE databases but it does not manage this storage. VSAM commands such as EXPORT, IMPORT, REPRO, and VERIFY should never be used on the DB2 Server for VSE database. If you receive an error message indicating an OPEN error (RC=74), ignore it and do not run VERIFY.


Reorganizing Indexes on the Catalog Tables

The catalog indexes need to be reorganized when indexes on the catalog tables become fragmented, and the database manager can no longer insert entries into the catalog dbspace.

Index fragmentation often happens in an application development environment. Application development requires frequent preprocessing; and each time a program is preprocessed, many entries are added to the catalog tables. It may not be possible to plan properly for the range of index keys that might be created.

Index fragmentation can lead to the inefficient use of the index pages of the catalog dbspace (SYS0001). If most of the index pages in your catalog dbspace are occupied, fragmentation is a likely cause.

To determine the number of index pages occupied in the catalog dbspace, enter the SHOW DBSPACE command. (The number of this catalog dbspace is 1; so you type SHOW DBSPACE 1.) If there is a high percentage of occupied pages, consider running the catalog index reorganization utility, which optimizes the indexes as they exist on the catalog tables.

To run the catalog index reorganization utility in a VSE environment, start the database in single user mode with STARTUP=I specified. Figure 20 shows an example of the job control statements.

Figure 20. Example Job Control to Reorganize the Catalog Indexes

// JOB REORG
|// EXEC PROC=ARIS71SL
// EXEC PROC=DBNAME01
// EXEC PGM=ARISQLDS,SIZE=AUTO,PARM='SYSMODE=S,STARTUP=I,PARMID=name'
/*
/&

Notes:

  1. For |ARIS71SL, substitute your procedure or job control that identifies the DB2 Server for VSE service libraries. The catalog index reorganization utility uses the ARISCAT source member.

  2. For DBNAME01, substitute your procedure or job control that identifies the database whose catalog indexes you wish to reorganize.

  3. The initialization parameters SYSMODE=S and STARTUP=I are required. You can also supply any of the following initialization parameters (PARMID is included in the example in Figure 20.):
PARMID=name
DBPSWD=password
NPAGBUF=n
NDIRBUF=n
NCSCANS=n
LOGMODE=Y|A|L|N
CHKINTVL=n
SLOGCUSH=n
ARCHPCT=n
SOSLEVEL=n
CHARNAME=name
DSPLYDEV=L|C|B
DUMPTYPE=P|F|N
TRACDBSS=nnnnnnnnnnn
TRACRDS=nnnnnn
TRACCONV=n
TRACDSC=nn
TRACBUF=n
TRACSTG=n
LTIMEOUT=n
SYNCPNT=Y|N

See the DB2 Server for VSE System Administration manual for a description of initialization parameters.

To avoid the processing involved in switching log modes, use the same LOGMODE that you normally use.

To run the catalog index reorganization utility in a VM environment:

  1. Log on to the virtual machine that owns the database.
  2. Get read access to the service minidisk (ACCESS 193 V).
  3. Invoke the SQLCIREO EXEC. This EXEC resides on the service minidisk. It invokes the DB2 Server for VM application server in single-user mode with STARTUP=I. See SQLCIREO EXEC for its syntax.

Because the catalog index reorganization utility runs in single user mode, the only way to trace it is with the TRACRDS, TRACDBSS, TRACDSC, and TRACCONV initialization parameters. The TRACE operator command cannot be used in single user mode.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]