今天有人反馈说,在做db2 restore的时候。 如果是AIX环境,那么restore过程中的文件系统使用率是随着restore的进度的增加而增长的。但是Linux环境下,看到restore操作一开始并不会真正进行(db2pd -uti中CompletedWork没有变化),而是先把文件系统空间分配好(df的输出能看到文件系统使用率一直增加),直到空间分配完成之后,restore才会有进展,是不是正常现象?
要问是不是正常,先看有没有说明吧,在 IBM support网站上搜索关键字 "db2 restore pre-allocate",发现一个关键字 DB2_USE_FAST_PREALLOCATION 及说明,链接如下:
http://www-01.ibm.com/support/docview.wss?uid=swg21996340
我把内容贴出来:
Effect of DB2_USE_FAST_PREALLOCATION on a DB2 restore
Question
What is the effect of using DB2_USE_FAST_PREALLOCATION ON when doing a DB2 restore with the IBM Spectrum Protect API
Answer
DB2 running on AIX, Solaris, or Linux host can use the DB2 performance setting DB2_USE_FAST_PREALLOCATION ON if they are on a VeritasVxFS, JFS2, GPFS™, or ext4 (Linux only) file system. The default setting is ON for VeritasVxFS, JFS2, and GPFS; specifically setting this to OFF would stop the use of this option.
DB2_USE_FAST_PREALLOCATION allows for a much quicker allocation of space when DB2 creates or alters large table spaces. This can be advantageous for restores, as a restore of a large table space to an AIX, Solaris, or Linux host with thesetting of ON may be able to immediately stream data for the restore without any delays for creation of the DB2 containers.
The documentation for DB2_USE_FAST_PREALLOCATION indicates that this fast pre-allocation comes at the cost of a small amount of additional time spent when the data is actually written. Thus, the overall time for the restore may not be reduced.
The documentation for the DB2_USE_FAST_PREALLOCATION is available at the link below:
http://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.regvars.doc/doc/r0005665.html
看上面说明的意思是,在恢复的时候,创建容器也需要时间,如果开启了DB2_USE_FAST_PREALLOCATION,就避免了创建容器的时间,但在实际写入数据的时候会慢一点,所以总体性能不一定有所提升。
结下来在Linux上验证一下,在Linux上做了一些测试,使用的文件系统是ext4。发现无论是否设置DB2_USE_FAST_PREALLOCATION,restore的时候都会预先分配空间,我的备份介质大小为10多个G:
1. 没有设置DB2_USE_FAST_PREALLOCATION时,对ext4来讲,默认为ON,在1秒之内(也可能是瞬时的)就(看起来)预先分配了十多G的空间。
2. 设置DB2_USE_FAST_PREALLOCATION为OFF后,也是预先分配了存储空间,不过没那么快,差不多每秒分配一个G。
具体的测试方法是,使用下面的脚本监控文件系统使用率和restore的进度:
$ cat monidu.sh2
#!/bin/bash
while true
do
date >> info.log2
df -hT /dev/sda1 >> info.log2
db2pd -uti >> info.log2
echo "+++++++++++++++" >> info.log2
sleep 1
done
1. 没有设置DB2_USE_FAST_PREALLOCATION时,结果如下,可以看到df输出上一秒Used还是20G,下一秒就变成了33G,但restore命令的CompletedWork没有变化
+++++++++++++++
Mon Nov 27 06:54:30 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 20G 120G 14% /
Database Partition 0 -- Active -- Up 0 days 01:53:54 -- Date 2017-11-27-06.54.30.545112
Utilities:
Address ID Type State
Progress:
Address ID PhaseNum CompletedWork <略去部分输出,以下同>
+++++++++++++++
Mon Nov 27 06:54:31 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 20G 120G 14% /
Database Partition 0 -- Active -- Up 0 days 01:53:55 -- Date 2017-11-27-06.54.31.638366
Utilities:
Address ID Type State
0x0000000200DBECE0 44 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DBF008 44 1 36204544 bytes
+++++++++++++++
Mon Nov 27 06:54:32 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 33G 107G 24% /
Database Partition 0 -- Active -- Up 0 days 01:53:56 -- Date 2017-11-27-06.54.32.864485
Utilities:
Address ID Type State
0x0000000200DBECE0 44 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DBF008 44 1 36204544 bytes
+++++++++++++++
2. 设置DB2_USE_FAST_PREALLOCATION为OFF后,结果如下,可以看到,从07:03:10开始,每一秒都有1G的文件系统被使用,但restore操作的CompleteWork却没有变化:
+++++++++++++++
Mon Nov 27 07:03:10 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 20G 120G 14% /
Database Partition 0 -- Active -- Up 0 days 00:00:44 -- Date 2017-11-27-07.03.10.394551
Utilities:
Address ID Type State
0x0000000200DCF1E0 1 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DCF508 1 1 36204544 bytes
+++++++++++++++
Mon Nov 27 07:03:11 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 21G 119G 15% /
Database Partition 0 -- Active -- Up 0 days 00:00:45 -- Date 2017-11-27-07.03.11.504389
Utilities:
Address ID Type State
0x0000000200DCF1E0 1 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DCF508 1 1 36204544 bytes
+++++++++++++++
Mon Nov 27 07:03:12 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 22G 117G 16% /
Database Partition 0 -- Active -- Up 0 days 00:00:46 -- Date 2017-11-27-07.03.12.624897
Utilities:
Address ID Type State
0x0000000200DCF1E0 1 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DCF508 1 1 36204544 bytes
+++++++++++++++
Mon Nov 27 07:03:13 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 24G 116G 17% /
<下面都省略了db2pd的输出,因为没有变化,始终保持在36204544 bytes,直到文件系统到达33G之后才开始增加>
+++++++++++++++
Mon Nov 27 07:03:14 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 25G 115G 18% /
..
+++++++++++++++
Mon Nov 27 07:03:15 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 26G 113G 19% /
..
+++++++++++++++
Mon Nov 27 07:03:16 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 28G 112G 20% /
..
+++++++++++++++
Mon Nov 27 07:03:18 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 29G 111G 21% /
..
+++++++++++++++
Mon Nov 27 07:03:19 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 30G 110G 22% /
..
+++++++++++++++
Mon Nov 27 07:03:20 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 31G 108G 23% /
..
+++++++++++++++
Mon Nov 27 07:03:21 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 33G 107G 24% /
Database Partition 0 -- Active -- Up 0 days 00:00:55 -- Date 2017-11-27-07.03.21.468777
Utilities:
Address ID Type State
0x0000000200DCF1E0 1 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DCF508 1 1 36204544 bytes
+++++++++++++++
Mon Nov 27 07:03:22 PST 2017
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 147G 33G 107G 24% /
Database Partition 0 -- Active -- Up 0 days 00:00:56 -- Date 2017-11-27-07.03.22.692547
Utilities:
Address ID Type State
0x0000000200DCF1E0 1 RESTORE 0
Progress:
Address ID PhaseNum CompletedWork
0x0000000200DCF508 1 1 54304768 bytes
+++++++++++++++
如果文件系统是ext3的,不支持快速预分配