DB2数据库归档日志管理方案 |
本文标签:DB2 日志管理 需求描述 由于使用了LOGRETAIN=ON数据库配置,所以数据库日志文件将不会被数据库从活动日志目录中自动删除或循环利用,活动日志目录中的日志文件将会越来越多,所以需要对该目录下的日志文件进行归档 。 问题分析 将LOGRETAIN设置为ON后,数据库将支持前滚恢复 。此时,系统中将会存在三种类型的日志文件: 活动日志:该日志包含尚未提交或回滚的事务单元的相关信息,以及已提交但尚未写入数据库文件的事务的信息 。 脱机存档日志:将联机存档日志从活动日志目录下Copy到另外的地方存档,就称为脱机存档日志 。这些日志可能在数据库前滚恢复的时候仍然需要 。 管理数据库日志的工作可以手工完成(即将联机存档日志手工拷贝到某个archive目录),也可由编写USEREXIT程序自动维护 。 由于DB2对所有平台都提供了相应的USEREXIT示例程序,而且非常易于修改和使用,所以IBM建议用户使用USEREXIT程序来管理日志文件 。 使用USEREXIT程序的方法 要使用User exit program自动化log文件的archiving和retrieval过程: 1. 设置database cfg参数logarchmeth1 为USEREXIT connect to sample 2. 创建user exit programs 。该程序必须是一个名为db2uext2的可执行文件 。DB2在各种平台上都提供了User Exit的示例程序,用户可以通过直接修改该样本文件来实现自己的user exit程序 。 在UNIX(R) based的系统中,该程序存放在sqllib/samples/c目录下. 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\\" 4. 编译该C文件 cl db2uext2.c 5. 拷贝db2uext2.exe到/SQLLIB/BIN目录下 6. 在db2cmd中键入archive log for db sample user db2admin using duan1980命令强制执行log日志归档任务 。查看c:\mylogs目录下有无日志文件归档,验证是否成功 。 (责任编辑:铭铭 mingming_ky@126.com TEL:(010)68476636) |