Using a split mirror to clone a database

Use the following procedure to create a clone database in an environment outside of a Db2® pureScale® environment. Although you can write to clone databases, they are generally used for read-only activities such as running reports.

About this task

If the source database was configured for log archiving, the cloned database will share the same log archiving configuration. If the archive log location is accessible to the cloned database, this could cause the cloned database to archive log files to the same location as the source database and can affect the recoverability of both databases. While the cloned database will initially use a different log chain from the source database, the source database could eventually use the same log chain value as the cloned database. You should change the log archiving destination for the cloned database to be different from that of the source database before running the db2inidb command to avoid recoverability issues.

You cannot back up a cloned database, restore the backup image on the original system, or roll forward through log files produced on the original system. The cloned database provides an instantaneous copy of the database only at that time when the I/O is suspended; any other outstanding uncommitted work will be rolled back after the db2inidb command is executed on the clone.

Procedure

To clone a database:
  1. Connect to the source database using the following command:
    db2 connect to db_name
  2. Suspend the I/O write operations on the source database using the following command:
    db2 set write suspend for database
    Note: While the database is in suspended state, you should not be running other utilities or tools. You should only be making a copy of the database. You can optionally flush all buffer pools before issuing SET WRITE SUSPEND to minimize the recovery window. This can be achieved using the FLUSH BUFFERPOOLS ALL statement.
  3. Create one or multiple split mirrors from the source database using the appropriate operating system-level and storage-level commands.
    Note:
    • Ensure that you copy the entire database directory, including the volume directory. You must also copy the log directory and any container directories that exist outside the database directory. To gather this information, refer to the DBPATHS administrative view, which shows all the files and directories of the database that need to be split.
    • If you specified the EXCLUDE LOGS with the SET WRITE command, do not include the log files in the copy.
  4. Resume the I/O write operations on the source database using the following command:
    db2 set write resume for database
  5. Catalog the mirrored database on the secondary system.
    Note: By default, a mirrored database cannot exist on the same system as the source database. It must be located on a secondary system that has the same directory structure and uses the same instance name as the source database. If the mirrored database must exist on the same system as the source database, you can use the db2relocatedb utility or the RELOCATE USING option of the db2inidb command to accomplish this.
  6. Start the database instance on the secondary system using the following command:
    db2start
  7. Initialize the mirrored database on the secondary system:
    db2inidb database_alias as snapshot

    If required, specify the RELOCATE USING option of the db2inidb command to relocate the clone database:

     db2inidb database_alias as snapshot relocate using relocatedbcfg.txt

    where the relocatedbcfg.txt file contains the information required to relocate the database.

    Note: This command rolls back transactions that are in flight when the split occurs, and starts a new log chain sequence so that any logs from the source database cannot be replayed on the cloned database.
  8. Ensure that the cloned database uses a separate log archive from the source database. All database configuration parameters of the cloned database are set to the same values as the source database. If the location of the log archive (specified by the logarchmeth1/logarchmeth2 database configuration) is set to a shared location that can be accessed by both the source database and the cloned database, specify a different location for the log archive of the cloned database:
    db2 update db cfg for <database_alias> using logarchmeth1 <archive_location_for_cloned_database>