Cloning an online or offline DB2 Database
The db2relocatedb tool can be used to perform these same tasks and in many cases the time it takes (and the effort involved) is less than what would be necessary when doing the operation “within” DB2. But these aren’t the only things the tool can assist with. Here are all of the tasks where the tool can be useful:
Changing a database name Changing the path/drive that a database was created on Changing one or more table space containers Changing the log path associated with the database Changing the instance associated with a database Copying/moving a database to the same (or different) machine and making one or more of the above changes
Suppose db2data and db2logs used for DB2 database's table data and transaction logs respectively. The steps used to perform an offline clone of a DB2 UDB database are as follows:
Stop the database to be cloned by deactivating it and/or terminating all connections to it Clone the volume (disk) consisting source database's table data and transaction logs
Make the cloned volumes accessible to the database server. On UNIX systems, this is done through mounting the filesystems
Assign appropriate permissions to the cloned virtual volumes so users have read and write access to the data stored there. If the FlexVol mount point names are different for cloned database than the source database, modify all tablespace container header information associated with the DB2 UDB database stored on the FlexClone volumes by executing the DB2 UDB system command db2relocatedb from the server. Provide the configuration file that contains appropriate configuration change information. For example
db2relocatedb -f relocate.cfg
The following is a sample relocate.cfg file: DB_NAME=MyProdDB, MyProdDB_CL DB_PATH=/mnt/db2data,/mnt/db2data_cl INSTANCE=db2inst1 NODENUM=0 LOG_DIR=/mnt/db2logs/NODE0000,/mnt/db2logs_cl/NODE0000 CONT_PATH=/mnt/db2data/*,/mnt/db2data_cl/* If the source and cloned database are accessed from the same host, then recatalog the original database by executing the DB2 UDB CLP command catalog database from the server:
db2 catalog database MyProdDB as MyProdDB on /mnt/db2data
When these steps are completed, you should be able to connect to both the original database and the cloned database.
The steps used to create a clone of a DB2 UDB database stored on a NetApp flexible volume while the database remains online are as follows:
Connect to the database to be cloned Temporarily delay all writing activity to the database by executing the DB2 UDB CLI command:
db2 SET WRITE SUSPEND FOR DATABASE. Execute the following command from filer command prompt to clone the data and logs flex volumes of the source database:
Resume all writing activity for the source database by executing the DB2 UDB CLI command:
db2 SET WRITE RESUME FOR DATABASE. Make the cloned volumes accessible to the server. On UNIX systems, this is done through mounting; on Windows platforms, this is done using SnapDrive. Assign appropriate permissions to the FlexClone volumes. For example on UNIX change filer and folder ownership using following command:
chown -R db2inst1:db2adm /mnt/db2data_cl /mnt/db2logs_cl If the same database server is to be used to access both the source and the cloned database, do the following: Create a relocate.conf file and update the rename database and update tables space container's header info using DB2 system command db2relocate as follows:
db2relocatedb -f /home/db2inst1/dbrelocate.cfg
The following is a sample relocate.cfg file:
DB_NAME= MyProdDB, MyProdDB_CL DB_PATH=/mnt/db2data,/mnt/db2data_cl INSTANCE=db2inst1 NODENUM=0 LOG_DIR=/mnt/db2logs/NODE0000,/mnt/db2logs_cl/NODE0000 CONT_PATH=/mnt/db2data/*,/mnt/db2data_cl/*
After executing the db2relocatedb command the cloned database will remain in 'write suspended' state. The cloned database need to be removed from the 'write suspended' state before its used by executing the DB2 UDB CLP command:
db2 RESTART DATABASE with WRITE RESUME
On execution of the db2relocatedb command, the source database will be uncatalogged. Recatalog it by executing the DB2 UDB CLP command:
db2 catalog database MyProdDB as MyProdDB on /mnt/db2data
If the cloned database is accessed from a different host than the source database and the mount point names are the same as of the source database host, catalog the cloned database using the DB2 UDB CLI command
db2 catalog database MyProdDB_CL on /mnt/db2data The cloned database will remain in 'write suspended' state. The cloned database needs to be removed from the 'write suspended' state before its used by executing the DB2 UDB CLP command:
db2 RESTART DATABASE with WRITE RESUME
When these steps are completed, you should be able to connect to both the original database and the cloned database.