日期:2014-05-16 浏览次数:20768 次
环境: Server: 127.0.0.1 Primary instance: db2inst4 Primary service/port: 42099 Standby instance: db2inst5 Standby service/port: 41099 DB name: SAMPLE --注意,切勿使用与DBM SVCENAME 太接近的端口,因为实例会默认使用那端口之后的连续几个端口,所以应尝试更远一些的端口
--在Primary: --启用归档模式 [db2inst4@localhost instance]$ db2 update db cfg for SAMPLE using LOGRETAIN on DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully. --启用LOGINDEXBUILD,以便日志有关索引的操作 [db2inst4@localhost instance]$ db2 update db cfg for SAMPLE using LOGINDEXBUILD on DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
--备份primary [db2inst4@localhost arch]$ db2 list db directory System Database Directory Number of entries in the directory = 1 Database 1 entry: Database alias = SAMPLE Database name = SAMPLE Local database directory = /home/db2inst4 Database release level = d.00 Comment = Directory entry type = Indirect Catalog database partition number = 0 Alternate server hostname = Alternate server port number = [db2inst4@localhost arch]$ db2 backup db sample to /arch Backup successful. The timestamp for this backup image is : 20110430101950 [db2inst4@localhost arch]$ ls -atrl total 135208 drwxr-x--- 3 db2inst1 db2iadm1 4096 Dec 8 12:12 db2inst1 drwxr-xr-x 27 root root 4096 Apr 22 23:45 .. drwxrwxrwx 3 root root 4096 Apr 30 10:19 . -rw------- 1 db2inst4 db2iadm1 138297344 Apr 30 10:20 SAMPLE.0.db2inst4.NODE0000.CATN0000.20110430101950.001 --注意修改备份文件属性,以便standby实例能够访问 [db2inst4@localhost arch]$ chmod 777 SAMPLE.0.db2inst4.NODE0000.CATN0000.20110430101950.001 --在standby: [db2inst5@localhost ~]$ db2 restore db sample from /arch/ on /home/db2inst5/ DB20000I The RESTORE DATABASE command completed successfully. [db2inst5@localhost ~]$ db2 list db directory System Database Directory Number of entries in the directory = 1 Database 1 entry: Database alias = SAMPLE Database name = SAMPLE Local database directory = /home/db2inst5 Database release level = d.00 Comment = Directory entry type = Indirect Catalog database partition number = 0 Alternate server hostname = Alternate server port number = --这时候standby的数据库应该是roll-forward pedning的状态,切勿手动roll-forward [db2inst5@localhost ~]$ db2 connect to SAMPLE SQL1117N A connection to or activation of database "SAMPLE" cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019
--在Primary:
db2 update db cfg for sample using HADR_LOCAL_HOST 127.0.0.1
db2 update db cfg for sample using HADR_LOCAL_SVC 42099
db2 update db cfg for sample using HADR_REMOTE_HOST 127.0.0.1
db2 update db cfg for sample using HADR_REMOTE_SVC 41099
db2 update db cfg for sample using HADR_REMOTE_INST db2inst5
db2 update db cfg for sample using HADR_SYNCMODE SYNC
db2 update db cfg for sample using HADR_TIMEOUT 3
db2 update db cfg for sample using HADR_PEER_WINDOW 120
db2 connect to sample
db2 quiesce database immediate force connections
db2 unquiesce database
db2 connect reset
--在Standby:
db2 update db cfg for sample using HADR_LOCAL_HOST 127.0.0.1
db2 update db cfg for sample using HADR_LOCAL_SVC 41099
db2 update db cfg for sample using HADR_REMOTE_HOST 127.0.0.1
db2 update db cfg for sample using HADR_REMOTE_SVC 42099
db2 update db cfg for sample using HADR_REMOTE_INST db2inst4
db2 update db cfg for sample using HADR_SYNCMODE SYNC
db2 update db