Project

General

Profile

Database Mirroring (DB2) on remote site » History » Revision 19

Revision 18 (chin-yeh, 03/22/2012 12:03 PM) → Revision 19/23 (chin-yeh, 03/22/2012 12:51 PM)

{{toc}} 

 h1. Database Mirroring (DB2) on remote site 

 h2. Introduction 

 To mirror production database(s) to remote site, there are a number of approaches: 
 # Use <code>(full)</code> database backup 
 # Use <code>(full + cumulative)</code> database backup 
 # Use <code>(full + delta)</code> database backup 
 # Use <code>(full + cumulative+ delta)</code> database backup - _not recommended because it is too complex_ 
 # Use <code>(full database backup + transaction logs)</code> 

 > the approach 1-4 are described in "Using DB2 incremental backup":http://www.ibm.com/developerworks/data/library/techarticle/dm-0910db2incrementalbackup/ 

 We will only discuss about the last approach, _full + transaction logs_ in the coming sections. Before that, let's do a quick compare for these approaches: 
 ||_.full|_.full + cumulative|_.full + delta|_.full + cumulative + delta|_.full + transaction logs| 
 |*Backup Image Size*|Biggest|Small|Smallest|In between Small and Smallest|Smaller| 
 |*Backup Time*|Longest|Depends on how the data is stored across tablespaces. If all data is stored in one tablespace then it won't make any difference|Depends on how the data is stored across tablespaces. If all data is stored in one tablespace then it won't make any difference|Depends on how the data is stored across tablespaces. If all data is stored in one tablespace then it won't make any difference|Fast| 
 |*Easy To Recover*|Easiest|Easy|Difficult|Very Difficult|Easy| 
 |*Need To Revise Backup Strategies*|No|Yes|Yes|Yes|No| 
 |*Resources Utilization*|High|High to Medium|High to Medium|High to Medium|Low| 
 |*DB is usable after first restored*|Yes|No|No|No|No| 
 |*Functions Used*|backup + restore + rollforward|backup + restore + rollforward|backup + restore + rollforward|backup + restore + rollforward|backup + restore + rollforward + rsync| 


 h2. Full Database Backup + Transaction Logs 

 Below diagram describes how this approach works: 

 !full_transaction_logs_approach.png! 

 _Sample steps:_ 
 # Like any other approaches, you must perform a full database backup _(either offline or online)_ 
 ** e.g.: 
 <pre>$ db2 backup db prod_db online</pre> 
 # Transfer the full backup image to the standby site and perform a database restoration: 
 ** e.g.: 
 <pre>$ db2 restore db prod_db replace history file</pre> 
 # Use the <code>rsync</code> command to do an one way incremental sync from remote (production) site to standby site. 
 ** e.g.: 
 <pre>$ rsync -var --delete db2inst1@db-prod:/home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/ /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR</pre> 
 # Execute the <code>rollfoward</code> on the standby database: (*do not* include the *complete* option) 
 ** e.g.: 
 <pre>$ db2 rollforward db prod_db to end of logs</pre> 
 # Repeat the <code>Step 3 & 4</code> to keep the standby database sync with the production database 
 # If want to bring up the standby database, just execute this command (_change the database alias_): 
 <pre>$ db2 rollforward db prod_db complete</pre> 


 The biggest advantage of this approach is there's little or no need to revise current backup strategies, however, the mirror database cannot be used until the <code>rollforward</code> process is completed (_also happens on the other db incremental backup approaches_). 

 h2. Test Tools 

 Install the following <code>VirtualBox</code> appliances to try out the backup approaches mentioned above: 
 * "db-prod":http://192.168.2.13/download/vb-db-prod.zip - Acted as production database server 
 * "db-prod-mirror":http://192.168.2.13/download/vb-db-prod-mirror.zip - Acted as standby database server 

 Appliance Details: 
 * *OS* - CentOS 5.7 32-bit 
 * *DB2 version* - IBM DB2 Express-C for Linux 32-bit 
 * *root user* - root/abcdef 
 * *DB2 user* - db2inst1/abcdef 
 * *DB2 instance* - db2inst1 
 * *IP Address:* 
 ** <code>vb-db-prod</code> - <code>192.168.56.120</code> 
 ** <code>vb-db-prod-mirror</code> - <code>192.168.56.121</code> 

 Before continue, ensure that your computer have: 
 * A decent CPU processor, say, 2GHz Dual Core processor 
 * 20 GB of free disk space 
 * Those appliances will use up 1GB of RAM so your PC must have at least 3GB RAM installed. 

 _How To Setup:_ Install:_ 
 # Install the "VirtualBox":http://192.168.2.13/download/VirtualBox-4.1.10-76836-Win.exe 
 # Download and un-compress the following appliances: 
 ** "vb-db-prod.zip":http://192.168.2.13/download/vb-db-prod.zip 
 ** "vb-db-prod-mirror.zip":http://192.168.2.13/download/vb-db-prod-mirror.zip 
 # Launch the <code>VirtualBox</code> and then go to _File - Preferences - Network_ 
 # Press the _Add host-only network_ button to add <code>VirtualBox Host-Only Ethernet Adapter</code> 
 ## Select the newly created adapter and press the _Edit host-only network_ button, and then: 
 ## Adjust the settings: 
 *** !Host-only_Network_Details.png! 
 ** _If encountered any error, refer to "this article":http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-can-i-find-out-how-many-network-filter-drivers/78a969d0-1e37-402a-b94d-877334cc07a7?tab=MoreHelp&auth=1 to remove unused network filters_. 
 # Navigate to the folder where the appliances being extracted, <code>.../vb-db-prod</code>, <code>.../vb-db-prod-mirror</code>, and then double-click the <code>xxxxx.vbox</code>, e.g _vb-db-prod.vbox_ to boot up the appliances. 
 # <code>SSH</code> to the appliance via this IP: 
 ** _vb-db-prod_ - <code>192.168.56.120</code>  
 ** _vb-db-prod-mirror_ - <code>192.168.56.121</code> 
 # Done. 

 > Do make use of the VirtualBox snapshots feature to revert the appliance state, testing, and etc...