【IT168技术文档】
需求描述:
由于使用了LOGRETAIN=ON数据库
问题
将LOGRETAIN设置为ON后,数据库将支持前滚恢复。此时,系统中将会存在三种类型的日志文件:
活动日志:该日志包含尚未提交或回滚的事务单元的相关
联机存档日志:活动日志中所有改动对正常处理已不需要,即该日志中所记录的事务都已提交并写入数据库文件时,该活动日志转换为联机存档日志。称之为联机,是由于它们与活动日志存放在同一个目录下。
脱机存档日志:将联机存档日志从活动日志目录下Copy到另外的地方存档,就称为脱机存档日志。这些日志可能在数据库前滚恢复的时候仍然需要。
管理数据库日志的
由于DB2对所有平台都提供了相应的USEREXIT示例程序,而且非常易于修改和使用,所以IBM建议用户使用USEREXIT程序来管理日志文件。
使用USEREXIT程序的方法
要使用User exit program自动化log文件的archiving和retrieval过程:
1. 设置database cfg参数logarchmeth1 为USEREXIT。
connect to sample update db cfg using logarchmeth1 USEREXIT connect reset
2. 创建user exit programs。该程序必须是一个名为db2uext2的可
在UNIX(R) based的
There are four sample user exit programs for UNIX based systems: • db2uext2.ctsm This sample uses Tivoli(R) Storage Manager to archive and retrieve database log files. • db2uext2.ctape This sample uses tape media to archive and retrieve database log files . • db2uext2.cdisk This sample uses the operating system COPY command and disk media to archive and retrieve database log files. • db2uxt2.cxbsa This sample works with the XBSA Draft 0.8 published by the X/Open group. It can be used to archive and retrieve database log files. This sample is only supported on AIX. •
在Windows(R) 系统中,该文件存放在sqllib/samples/c目录下。
There are two sample user exit programs for Windows operating systems: • db2uext2.ctsm This sample uses Tivoli Storage Manager to archive and retrieve database log files. • db2uext2.cdisk This sample uses the operating system COPY command and disk media to archive and retrieve database log files.
3. 配置该示例程序,指定要将日志文件Archive到哪个系统目录中(在windows平台下,程序中默认为c:\mylogs)。
#define ARCHIVE_PATH "c:\\mylogs\\" #define RETRIEVE_PATH "c:\\mylogs\\" #define AUDIT_ERROR_PATH "c:\\mylogs\\"
4. 编译该C文件。
cl db2uext2.c
5. 拷贝db2uext2.exe到/SQLLIB/BIN目录下。
6. 在db2cmd中键入archive log for db sample user db2admin using duan1980命令强制执行log日志归档任务。查看c:\mylogs目录下有无日志文件归档,验证是否成功。