IBM Support

How to create an empty DB2 database with objects and config from an existing one

Technical Blog Post


Abstract

How to create an empty DB2 database with objects and config from an existing one

Body

db2look is the tool  which could be used to achieve this purpose.

http://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002051.html?lang=en

 

From DB2 10.1  onwards there is a  -createdb  option  which helps to get the original create database syntax.

The create database syntax is put at the beginning of  db2look output, so that, when it's used as a  script to recreate the database,  the  first thing  which will be invoked  is the create  database command.

 

Also,   -printdbcfg option helps to get the database configurations and put in the output file in a way   which could be  directly used to update the database configurations.

 

Following example will get the create database syntax  along with  all object  DDLs,   mimic and  config used for optimizer and database config  as a whole,

 db2look -d sample -createdb -f -m -l -a -e -printdbcfg -o db2look.out

 

So, with this db2look output script  an empty database similar to source database could be recreated.

 

To recreate the empty database  and  create the objects etc   just need to run,

db2 -tvf  db2look.out

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

UID

ibm11140814