问题描述:
Db2重定向恢复的命令都没有报错(Error),显示成功,但连库却报SQL1119N: A connection to or activation of database "SAMPLE1" cannot be made because a previous restore is incomplete or still in progress.
Session 1:
inst105@db2a:~$
db2 restore db sample1 taken at 20180303061305 redirect
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.
inst105@db2a:~$
db2 "SET TABLESPACE CONTAINERS FOR 2 USING ( FILE 'file02' 10000)"
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
inst105@db2a:~$
db2 RESTORE DATABASE sample1 CONTINUE
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.
inst105@db2a:~$
db2 connect to sample1
SQL0752N Connecting to a database is not permitted within a logical unit of
work when the CONNECT type 1 setting is in use.
Session 2:
inst105@db2a:~$
db2 connect to sample1
SQL1119N A connection to or activation of database "SAMPLE1" cannot be made
because a previous restore is incomplete or still in progress. SQLSTATE=57019
原因解析:
其实,如果真正恢复成功的话,第三步的db2 RESTORE DATABASE sample1 continue命令是不应该再有SQL1277W 的warning的。如果查看db2diag.log,则会发现有Warning,这里的warning是说set tablespace container时指定的数据页太少,应该至少为81952页
2018-03-03-06.47.58.865029-480 I37572E871 LEVEL: Warning
PID : 1507 TID : 140060812896000 PROC : db2sysc 0
INSTANCE: inst105 NODE : 000 DB : SAMPLE1
APPHDL : 0-138 APPID: *LOCAL.inst105.180303144743
AUTHID : INST105 HOSTNAME: db2a
EDUID : 1021 EDUNAME: db2agent (SAMPLE1) 0
FUNCTION: DB2 UDB, database utilities, sqludCheckRedirectedStatus, probe:1154
DATA #1 :
Insufficient space in tablespace USERSPACE1; you must have at least 81920
usable pages. (The "usable pages" total does not include pages used
internally by DB2, so the value specified on the SET TABLESPACE
CONTAINERS operation should be increased by one extent per container.
Based on the latest SET TABLESPACE CONTAINERS values specifed, the
tablespace should have 81952 pages in total.)
在之前备份的时候,表空间USERSPACE1的使用状态如下,可以看到,虽然Used pages很少,只有160,但重定向恢复要求SET TABLESPACE CONTAINERS 时指定的页数要大于高水位,这里的高水位是81920,但SET TABLESPACE CONTAINERS 指定值为10000,所以会有上面的Warning,导致数据库实际上没有恢复成功:
Tablespace ID = 2
Name = USERSPACE1
Type = Database managed space
Contents = All permanent data. Large table space.
State = 0x0000
Detailed explanation:
Normal
Total pages = 524288
Useable pages = 524256
Used pages = 160
Free pages = 524096
High water mark (pages) = 81920
Page size (bytes) = 4096
Extent size (pages) = 32
Prefetch size (pages) = 32
Number of containers = 1
解决方案
可以在Session 1里使用 db2 RESTORE DATABASE sample1 abort,或者直接删除数据库,然后重新从头开始恢复(RESTORE DATBASE .. REDIRECT),恢复到SET TABLESPACE CONTAINERS这一步时指定一个足够大的页数。
Session 1:
inst105@db2a:~$ db2 RESTORE DATABASE sample1 abort
SQL2001N The utility was interrupted. The output data may be incomplete.
inst105@db2a:~$ db2 restore db sample1 taken at 20180303061305 redirect
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.
inst105@db2a:~$ db2 "SET TABLESPACE CONTAINERS FOR 2 USING ( FILE 'file02' 100000)"
DB20000I The SET TABLESPACE CONTAINERS command completed successfully.
inst105@db2a:~$ db2 RESTORE DATABASE sample1 continue
DB20000I The RESTORE DATABASE command completed successfully.
inst105@db2a:~$ db2 connect to sample1
Database Connection Information
Database server = DB2/LINUXX8664 10.5.8
SQL authorization ID = INST105
Local database alias = SAMPLE1
参考资料:
http://www-01.ibm.com/support/docview.wss?uid=swg21246513