1 删除Db2数据库时,提示失败,报错SQL1035N。

$ db2 drop db isimdb
SQL1035N The operation failed because the specified database cannot be connected to in the mode requested. SQLSTATE=57019

2 解决步骤:
$ db2 force application all
The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.

$ db2 terminate
DB20000I The TERMINATE command completed successfully.
$ db2 drop db isimdb
DB20000I The DROP DATABASE command completed successfully.

3 还原数据库:(原先数据库服务器的日志目录是/home/isimdb,现在新服务器改到/opt/isimdb)

Path to log files

/opt/isimdb/db2inst1/NODE0000/SQL00001/LOGSTREAM0000/

$ db2 “restore db ISIMDB from ‘/opt/backup’ to ‘/opt/isimdb’ redirect without prompting”
SQL1277W A redirected restore operation is being performed. During a table space restore, only table spaces being restored can have their paths reconfigured. During a database restore, storage group storage paths and DMS table space containers can be reconfigured.
DB20000I The RESTORE DATABASE command completed successfully.
$ db2 “SET STOGROUP PATHS FOR IBMSTOGROUP ON /opt/isimdb'”
DB20000I The SET STOGROUP PATHS command completed successfully.
$ db2 restore db ISIMDB continue
DB20000I The RESTORE DATABASE command completed successfully.

4 通过备份数据库的修改时间戳,判断数据库写入的时间2025-3-21 18:45:

1 db2inst1 db2iadm1 2492665856 Mar 21 18:45 ISIMDB.0.db2inst1.DBPART000. 20250321150955.001

所以需要从源服务器拿到事务日志。

5 列出历史备份:

$ db2 list history backup all for isimdb

Op Obj Timestamp+Sequence Type Dev Earliest Log Current Log Backup ID

B D 20250321150955001 N D S0128052.LOG S0128053.LOG

Contains 5 tablespace (s) :

00001 SYSCATSPACE
00002 USERSPACE1
00003 SYSTOOLSPACE
00004 ENROLE DATA
00005 ENROLE INDEXES

Comment: DB2 BACKUP ISIMDB ONLINE
Start Time: 20250321150955
End Time: 20250321151007
Status: A

EID: 130385 Location: /opt2

6 如果缺少日志文件,前端会提示报错:

$ db2 rollforward database isimdb to end of logs and complete
SQL1273N An operation reading the logs on database “ISIMDB” cannot continue because of a missing log file “S0128053.LOG” on database partition “0” and log stream “0”.

把S0128052.LOG S0128053.LOG 这两个事务日志文件都拷贝到目标Db2服务器。

$ cp /tmp/S0128053.LOG /opt/data/log_archive/isim/db2inst1/ISIMDB/NODE0000/LOGSTREAM0000/C0000004/

7前滚日志,解除访问限制

$ db2 rollforward database isimdb to end of logs and complete

Rollforward Status

Input database alias = isimdb
Number of members have returned status = 1
Member ID = 0
Rollforward Status = not pending
Next log file to be read
Log files processed = S0128052.LOG – S0128052.LOG
Last committed transaction = 2025-03-21-07.10.06.000000 UTC

DB20000I The ROLLFORWARD command completed successfully.

$ db2 connect to isimdb

Database Connection Information

Database server = DB2/LINUXX8664 11.5.8.0
SQL authorization ID = DB2INST1
Local database alias = ISIMDB