Creating a consistent database for query and review
Every evening at midnight, a version of an order and shipping database must be migrated to a query database. To create management reports, you must be able to execute long-running queries on the query database without interfering with online transactions.
Orders and shipping data are added by the online transactions. These transactions cannot interfere with the consistency of a series of queries against the query database that remains static while you create the management reports.
In this example, the databases are defined on the same Db2 subsystem. Your challenge is to create a consistent database for query and review (see the following figure).
To create a consistent database for query and review
Obtain data definitions.Obtain the definitions of the database, table spaces, and tables from the online application. These are the source objects. Also, obtain definitions for the indexes if you want to create them.
The DDL for this example is shown in the following figure.
CREATE DATABASE AFRORDER;
CREATE TABLESPACE AFRORDER IN AFRORDER USING STOGROUP PROD1;
CREATE TABLESPACE AFRSHIPS IN AFRORDER USING STOGROUP PROD1;
CREATE TABLE AFRORDER (
ORDERNUM INT
ITEMCODE INT
PRICE DECIMAL (5,2)
QUANTITY SMALLINT
TOTAL DECIMAL (7,2)
)
IN AFRORDER.AFRORDER;
CREATE TABLE AFRSHIPS (
ORDERNUM INT
DATEORDERED DATE
DATESHIPPED DATE
)
IN AFRORDER.AFRSHIPS;
CREATE UNIQUE INDEX AFRORDI ON AFRORDER (ORDERNUM)
USING STOGROUP PROD1;
CREATE UNIQUE INDEX AFRSHPI ON AFRSHIPS (ORDERNUM)
USING STOGROUP PROD1;Create the database.Modify the DDL for the source objects to change the names so that table spaces and tables are distinctly defined. You might want to create a new database as shown in the following figure. Also, consider other possible changes such as the STOGROUP and index type. The following figure shows the DDL for the target objects.
CREATE DATABASE AFRSUMOR;
CREATE TABLESPACE AFRSUMOR IN AFRSUMOR USING STOGROUP MIS1;
CREATE TABLESPACE AFRSUMSH IN AFRSUMOR USING STOGROUP MIS1;
CREATE TABLE AFRSUMORDER ( ORDERNUM INT
ITEMCODE INT
PRICE DECIMAL (5,2)
QUANTITY SMALLINT
TOTAL DECIMAL (7,2))
IN AFRSUMOR.AFRSUMOR;
CREATE TABLE AFRSUMSHIPS ( ORDERNUM INT
DATEORDERED DATE
DATESHIPPED DATE )
IN AFRSUMOR.AFRSUMSH;
CREATE UNIQUE INDEX AFRORDSI ON AFRSUMORDER (ORDERNUM)
USING STOGROUP MIS1;
CREATE UNIQUE INDEX AFRSHPSI ON AFRSUMSHIPS (ORDERNUM)
USING STOGROUP MIS1;Obtain internal IDs.You need the internal Db2 OBIDs for the source and target objects to set up the migration. You can use SQL to obtain these identifiers from the Db2 system catalog. See the following figure for an example.
SELECT NAME, DBID, PSID FROM SYSIBM.SYSTABLESPACE
WHERE NAME = 'AFRORDER' OR NAME = 'AFRSUMOR' OR NAME = 'AFRSHIPS' OR NAME = 'AFRSUMSH';
+-----------------------------------+
| NAME | DBID | PSID |
+-----------------------------------+
1_| AFRORDER | 352 | 2 |
2_| AFRSHIPS | 352 | 7 |
3_| AFRSUMOR | 449 | 2 |
4_| AFRSUMSH | 449 | 7 |
+-----------------------------------+
SELECT CREATOR, NAME, INDEXTYPE, DBID, ISOBID FROM SYSIBM.SYSINDEXES
WHERE NAME = 'AFRORDI' OR NAME = 'AFRSHPI' OR NAME = 'AFRORDSI' OR NAME = 'AFRSHPSI';
+----------------------------------------------------------+
| CREATOR | NAME | INDEXTYPE | DBID | ISOBID |
+---------------------------------------------=------------+
1_| OWNERID | AFRORDI | 2 | 352 | 5 |
2_| OWNERID | AFRORDSI | 2 | 352 | 5 |
3_| OWNERID | AFRSHPI | 2 | 449 | 10 |
4_| OWNERID | AFRSHPSI | 2 | 449 | 10 |
+----------------------------------------------------------+
SELECT NAME, OBID FROM SYSIBM.SYSTABLES WHERE DBNAME = 'AFRORDER';
+---------------------------------+
| NAME | OBID |
+---------------------------------+
1_| AFRORDER | 3 |
2_| AFRSHIPS | 8 |
+---------------------------------+
SELECT NAME, OBID FROM SYSIBM.SYSTABLES WHERE DBNAME = 'AFRSUMOR';
+---------------------------------+
| NAME | OBID |
+---------------------------------+
1_| AFRSUMORDER | 3 |
2_| AFRSUMSHIPS | 8 |
+---------------------------------+Quiesce the source objects.Issue a QUIESCE command on the source table spaces. Example JCL and output are shown in the following figures.
//QUIESCE EXEC DSNUPROC,SYSTEM=DBAN,UID='AFRRESM1',
// UTPROC='',REGION=4M,
// LIB='SYS2.DB2.PROD.DSNLOAD'
//DSNUPROC.SYSPRINT DD SYSOUT=*
//DSNUPROC.SYSIN DD *
QUIESCE TABLESPACE AFRORDER.AFRORDER
TABLESPACE AFRORDER.AFRSHIPSDSNU000I DSNUGUTC - OUTPUT START FOR UTILITY, UTILID = LSBRESM1
DSNU050I DSNUGUTC - QUIESCE TABLESPACE AFRORDER.AFRORDER TABLESPACE AFRORDER.AFRSHIPS
DSNU477I *DSNP DSNUQUIA - QUIESCE SUCCESSFUL FOR TABLESPACE AFRORDER.AFRORDER
DSNU477I *DSNP DSNUQUIA - QUIESCE SUCCESSFUL FOR TABLESPACE AFRORDER.AFRSHIPS
DSNU474I *DSNP DSNUQUIA - QUIESCE AT RBA 0003D5B9A3C2 AND AT LRSN 0003D5B9A3C2
DSNU475I DSNUQUIB - QUIESCE UTILITY COMPLETE, ELAPSED TIME= 00:00:00
DSNU010I DSNUGBAC - UTILITY EXECUTION COMPLETE, HIGHEST RETURN CODE=0Stop the target objects.Issue a STOP command against the database or table space where the query image will be built.
Run BMC AMI Recover to create the target image.In this step, you migrate the image to the other spaces using the BMC AMI Recover INDEPENDENT OUTSPACE and OBIDXLAT options.
The data sets that are to receive the migrated data were created when the data definition was done for the target table spaces and index spaces. These data sets are specified in the syntax with their VSAM cluster names.
In the example shown in the following figure, the IDs from Step 3 are used to define the objects required. Note that TORBA (or TOLOGPOINT) LASTQUIESCE is used. If other quiesce points might be created by other activities, use TORBA (or TOLOGPOINT) X’0003D5B9A3C2’--the LRSN from the QUIESCE operation.
//RECINDEP EXEC PGM=AFRMAIN,REGION=0M,
// PARM='DBAN,AFRAQDN,NEW,MSGLEVEL(1)'
//STEPLIB DD DISP=SHR,DSN=product.libraries
// DD DISP=SHR,DSN=DB2.DSNEXIT
// DD DISP=SHR,DSN=DB2.DSNLOAD
//SORTOUT DD DUMMY
//SYSIN DD *
OPTIONS INDEXLOG YES
RECOVER TABLESPACE AFRORDER.AFRORDER
OBIDXLAT DBID(352,449) PSID (2,2) OBID (3,3)
INDEP OUTSPACE MODEL
DBANCAT.DSNDBC.AFRSUMOR.AFRSUMOR.I0001.A001
TORBA LASTQUIESCE
RECOVER INDEX OWNERID.AFRORDI
OBIDXLAT DBID(352,449) PSID (5,5) OBID (3,3)
INDEP OUTSPACE MODEL
DBANCAT.DSNDBC.AFRSUMOR.AFRORDSI.I0001.A001
TORBA LASTQUIESCE
RECOVER INDEX OWNERID.AFRSHPI
OBIDXLAT DBID(352,449) PSID (10,10) OBID (8,8)
INDEP OUTSPACE MODEL
DBANCAT.DSNDBC.AFRSUMOR.AFRSHPSI.I0001.A001
TORBA LASTQUIESCE
RECOVER TABLESPACE AFRORDER.AFRSHIPS
OBIDXLAT DBID(352,449) PSID (7,7) OBID (8,8)
INDEP OUTSPACE MODEL
DBANCAT.DSNDBC.AFRSUMOR.AFRSUMSH.I0001.A001
TORBA LASTQUIESCEStart the target objects.Issue a START command to start the target objects. They are now ready for queries.
Allow queries.Queries such as the one shown in the following figure (which requires a table space scan) can be completed without interfering with the online processing. Because data will not be changing on this image, the result of the query will be consistent with other queries made until the data is refreshed again.
SELECT COUNT(*), SUM(TOTAL)
FROM AFR.AFRSUMORDER ORD,
AFR.AFRSUMSHIPS SHIP
WHERE (
DAYS(DATESHIPPED) > DAYS(DATEORDERED) + 2 OR
DAYS(DATEORDERED) + 2 < DAYS(CURRENT DATE) AND
DATESHIPPED IS NULL
)
AND ORD.ORDERNUM = SHIP.ORDERNUM;
+--------------------------------------+
| | |
+--------------------------------------+
1_| 2 | 888.50 |
+--------------------------------------+
Related topic