如何使用db2ReadLog读取数据库日志文件:
1,拷贝sqllib/samples/c下的所有文件到本地文件位置:
[db2inst1@localhost ~/db2test]$ cp -R ~/sqllib/samples/c .
2,更改本地目录的权限使其能够创建修改文件
[root@localhost db2test]# pwd
/home/db2inst1-m/db2test
[root@localhost db2test]# chmod -R 777 c/
3,使用db2sampl命令创建一个示例测试库
[db2inst1@localhost ~/db2test]$db2sampl
Starting the DB2 instance...
Creating database "SAMPLE"...
Connecting to database "SAMPLE"...
Creating tables and data in schema "TEST97"...
Creating tables with XML columns and XML data in schema "TEST97"...
Stopping the DB2 instance...
'db2sampl' processing complete.
4,连接到测试数据库
[db2inst1@localhost c]$ db2 connect to sample
Database Connection Information
Database server = DB2/LINUXX8664 9.7.10
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
5,预编译:
预编译数据库文件,embprep是一个脚本文件,生成*.c和*.bnd,并且绑定到了数据库
预编译*.sqc文件生成*.c和*.bnd
[db2inst1@localhost c]$ db2 precompile dblogconn.sqc bindfile
LINE MESSAGES FOR dblogconn.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
[db2inst1@localhost c]$ db2 precompile utilemb.sqc bindfile
LINE MESSAGES FOR utilemb.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
6,绑定
绑定是从绑定文件创建包并将其存储在数据库中的过程。
[db2inst1@localhost c]$ db2 bind dblogconn.bnd
LINE MESSAGES FOR dblogconn.bnd
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
[db2inst1@localhost c]$ db2 bind utilemb.bnd
LINE MESSAGES FOR utilemb.bnd
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
[db2inst1@localhost c]$ db2 list packages
Bound Total Isolation
Package Schema Version by sections Valid Format level Blocking
----------- --------- ----------- --------- ------------- ------- -------- --------- --------
DBLOGCON DB2INST1 DB2INST1 19 Y 0 CS U
P1567770> DB2INST1 DB2INST1 10 N 0 CS U
UTILEMB DB2INST1 DB2INST1 1 Y 0 CS U
7,编译
编译是从源文件生成到目标文件的过程
[db2inst1@localhost c]$ cc -I$DB2PATH/include -c dblogconn.c
[db2inst1@localhost c]$ cc -I$DB2PATH/include -c utilemb.c
8,链接
链接是将目标文件与适当的共享库合并以执行的可执行程序的过程。
[db2inst1@localhost c]$ cc -o dblogconn dblogconn.o utilemb.o -L$DB2PATH/lib -ldb2
9,输出
[db2inst1@localhost c]$ ./dblogconn
对照dblogconn输出的例子来分析db2日志格式