UNLOAD
The UNLOAD online utility copies data from one or more source objects to one or more BSAM sequential data sets in external formats. The output records that the UNLOAD utility writes are compatible as input to the LOAD utility. Therefore, you can use this output to reload the original table or different tables.
Although the function of the UNLOAD utility is often referred to as unloading data, the data is not deleted from the source object. The utility just makes a copy of the data. That copy includes the data only; it does not include all of the pages, such as the system pages and header pages, that are included in an image copy.
The source for UNLOAD can be Db2 table spaces or Db2 image copy data sets. The source cannot be a concurrent copy or a FlashCopy® image copy.
You can unload rows from an
entire table space or select specific partitions or tables to unload. You can also
select columns by using the field specification list. If a table space is
partitioned, you can unload all of the selected partitions into a single data set.
Alternatively, you can unload each partition in parallel into physically distinct
data sets, except for partition-by-growth (PBG) table spaces, which do not support
parallelism.
UNLOAD must be run on the system where the definitions of the table space and the table exist.
Output
UNLOAD generates an unloaded table space or partition.
Authorization required
To execute this utility, you must use a privilege set that includes one of the following authorities:
- Ownership of the tables
- UNLOAD privilege on the tables
- SELECT privilege on the tables (if the AUTH_COMPATIBILITY system parameter is set to the SELECT_FOR_UNLOAD option)
- DBADM authority for the database. If the object on which the utility operates is in an implicitly created database, DBADM authority on DSNDB04 or the implicitly created database is sufficient.
- DATAACCESS authority
- SYSADM authority
- SYSCTRL authority (catalog tables only)
- SQLADM authority (catalog tables only)
- System DBADM authority (catalog tables only)
- ACCESSCTRL authority (catalog tables only)
- SECADM authority (catalog tables only)
If you use RACF® access control with multilevel security and UNLOAD is to process a table space that contains a table that has multilevel security with row-level granularity, you must be identified to RACF and have an accessible valid security label. Each row is unloaded only if your security label dominates the data security label. If your security label does not dominate the data security label, the row is not unloaded, but Db2 does not issue an error message.
Restrictions on running UNLOAD
- UNLOAD cannot be run on a table space during the period after RECOVER is run to a point in time before materialization of pending definition changes and before REORG is run to complete the point-in-time recovery process.
- A column in an ASCII or Unicode table cannot be unloaded as a Unicode column in an EBCDIC table. A field specification for a Unicode column in an EBCDIC table includes CCSID 1200 or CCSID 1208.
Execution phases of UNLOAD
The UNLOAD utility operates in these phases:
- UTILINIT initializes the environment.
- UNLOAD unloads records to sequential data sets. One pass through the input data set is made. If UNLOAD is processing a table space or partition, Db2 takes internal commits. These commits provide commit points at which the utility can be restarted if the utility stops in this phase.
- UTILTERM cleans up the environment.
Before running UNLOAD
If you plan to run UNLOAD on encrypted data, do not use the WHEN statement to filter encrypted fields; UNLOAD cannot filter rows that contain encrypted data
If the table into which you are loading data has an index with these characteristics, the LOAD fails:
- The index was created on a VARBINARY column or a column with a distinct type that is based on a VARBINARY data type.
- The index column has the DESC attribute.
To fix the problem, drop the index, or alter the column data type to BINARY, and then rebuild the index.
Data sets that UNLOAD uses
The following table lists the data sets that UNLOAD uses. The table lists the DD name that is used to identify the data set, a description of the data set, and an indication of whether it is required. Include statements in your JCL for each required data set and any optional data sets that you want to use.
Data set | Description | Required? |
---|---|---|
SYSIN | Input data set that contains the utility control statement. | Yes |
SYSPRINT | Output data set for messages. | Yes |
SYSPUNCH | One or more work data sets that contain the generated LOAD statements for subsequently reloading the data. The default DD name is PUNCHDDN. | No1 |
Unload data set | One or more work data sets that contain the unloaded table rows. The default DD name is SYSREC. | Yes |
Note:
|
The following object is named in the utility control statement and does not require a DD statement in the JCL:
- Table space
- Table space that is to be unloaded. (If you want to unload only one partition of a table space, you must specify the PART option in the control statement.)
Concurrency for UNLOAD
Db2 treats Individual data partitions as distinct source objects. Utilities that operate on different partitions of the same table space are compatible.
Claims and drains for UNLOAD
The following table shows which claim classes UNLOAD drains and the restrictive states that the utility sets.
Target | UNLOAD | UNLOAD PART |
---|---|---|
Table space or physical partition of a table space with SHRLEVEL REFERENCE | DW/UTRO | DW/UTRO |
Table space or physical partition of a table space with SHRLEVEL CHANGE | CR/UTRW | CR/UTRW |
Image copy* | CR/UTRW | CR/UTRW |
Legend:
Note: * If the target object is an image copy, the UNLOAD utility applies CR/UTRW to the
corresponding table space or physical partitions to prevent the table space from being dropped while
data is being unloaded from the image copy, even though the UNLOAD utility does not access the data
in the table space.
|
Compatibility for UNLOAD
The compatibility of the UNLOAD utility and the other utilities on the same target objects are shown in the following table. If the SHRLEVEL REFERENCE option is specified, only SQL read operations are allowed on the same target objects; otherwise SQL INSERT, DELETE, and UPDATE are also allowed. If the target object is an image copy, INSERT, DELETE, and UPDATE are always allowed on the corresponding table space. In any case, DROP or ALTER cannot be applied to the target object while the UNLOAD utility is running.
Action | UNLOAD SHRLEVEL REFERENCE | UNLOAD SHRLEVEL CHANGE | FROM IMAGE COPY |
---|---|---|---|
CHECK DATA DELETE NO | Yes | Yes | Yes |
CHECK DATA DELETE YES | No | No | No |
CHECK INDEX | Yes | Yes | Yes |
CHECK LOB | Yes | Yes | Yes |
COPY INDEXSPACE | Yes | Yes | Yes |
COPY TABLESPACE | Yes | Yes | Yes* |
DIAGNOSE | Yes | Yes | Yes |
LOAD SHRLEVEL CHANGE | No | Yes | Yes |
LOAD SHRLEVEL NONE | No | No | No |
MERGECOPY | Yes | Yes | No |
MODIFY RECOVERY | Yes | Yes | No |
MODIFY STATISTICS | Yes | Yes | Yes |
QUIESCE | Yes | Yes | Yes |
REBUILD INDEX | Yes | Yes | Yes |
RECOVER (no options) | No | No | No |
RECOVER ERROR RANGE | No | No | No |
RECOVER TOCOPY or TORBA | No | No | No |
REORG INDEX | Yes | Yes | Yes |
REORG TABLESPACE UNLOAD CONTINUE or PAUSE | No | No | No |
REORG TABLESPACE UNLOAD ONLY or EXTERNAL | Yes | Yes | Yes |
REPAIR DUMP or VERIFY | Yes | Yes | Yes |
REPAIR LOCATE INDEX PAGE REPLACE | Yes | Yes | Yes |
REPAIR LOCATE KEY or RID DELETE or REPLACE | No | No | No |
REPAIR LOCATE TABLESPACE PAGE REPLACE | No | No | No |
REPORT | Yes | Yes | Yes |
RUNSTATS INDEX | Yes | Yes | Yes |
RUNSTATS TABLESPACE | Yes | Yes | Yes |
STOSPACE | Yes | Yes | Yes |
Note: If the same data set is used as the output from the COPY utility and as the input
data set of the UNLOAD utility, unexpected results can occur.
|
UNLOAD utility syntax and options
Termination or restart of UNLOAD
If you terminate UNLOAD by using the TERM UTILITY command during the unload phase, the output records are not erased. The output data set remains incomplete until you either delete it or restart the utility job.
When the source is one or more table spaces, you can restart the UNLOAD job at the partition level or at the table space level when data is unloaded from multiple table spaces by using the LIST option. When you restart a terminated UNLOAD job, processing begins with the table spaces or partitions that had not yet been completed. For a table space or partitions that were being processed at termination, UNLOAD resets the output data sets and processes those table space or partitions again.
When the source is one or more image copy data sets (when FROMCOPY or FROMCOPYDDN is specified), UNLOAD always starts processing from the beginning.