客户端安装
a)db2inst1用户创建
useradd db2inst1
passwd db2inst1
b)介质包解压
tar -xvf v9.7_linuxx64_server.tar
c) 客户端安装
cd server
./db2_install
指定安装目录,默认路径是/opt/ibm/db2/V9.7,需要修改路径输入yes:
指定安装客户端程序,输入CLIENT:
d) 实例创建
cd /opt/ibm/db2/V9.7/instance
./db2icrt db2inst1
开启归档模式
a)检查数据库是否是归档模式
db2 connect to 数据库名
db2 get db cfg for 数据库名| grep LOG
如果下面参数值为OFF,则源端日志为循环日志。
First log archive method (LOGARCHMETH1) = OFF
Second log archive method (LOGARCHMETH2) = OFF
b)修改日志模式为归档模式
创建相关路径:
mkdir -p LOGARCHMETH1路径
mkdir -p LOGARCHMETH2路径
mkdir -p OVERFLOWLOGPATH路径
db2开启归档日志:
db2 update db cfg for 数据库名 using LOGARCHMETH1 disk:LOGARCHMETH1路径
db2 update db cfg for 数据库名 using LOGARCHMETH2 disk:LOGARCHMETH2路径
db2 update db cfg for 数据库名 using OVERFLOWLOGPATH OVERFLOWLOGPATH路径
离线备份数据库
db2 backup database test to 备份日志路径
注:备份时如果如下报错,说明有连接在连着这个库,可以执行强制断开所有连接,db2 force application all,如下:
[db2inst1@zcbusdbs arch]$ db2 backup database test to /data/db2/database/arch/backup
SQL1035N The database is currently in use. SQLSTATE=57019
[db2inst1@zcbusdbs arch]$ db2 force application all
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
[db2inst1@zcbusdbs arch]$ db2 backup database test to /data/db2/database/arch/backup
Backup successful. The timestamp for this backup image is : 20210219010613
用户创建
groupadd zcbus ---添加用户组zcbus
useradd -m -g zcbus -d /home/zcbus zcbus ---添加用户zcbus
passwd zcbus ---修改zcbus的密码
用户权限
a)赋权
db2 connect to 数据库名 ---连接到数据库
db2 grant dbadm,connect,dataaccess on database to user zcbus
测试连接:db2 connect to 数据库名 user zcbus using password
当用户密码含有特殊字符时,要用\进行转义如:db2 connect to testdb user zcbus using "1qaz!QAZ"
b)权限查询
db2 get authorizations
开启data capture changes属性
注:程序会自动为发布的表添加data capture changes属性,这样表的操作才能记录到日志里,程序才能分析到。
查询表是否有data capture changes权限:
SELECT DATACAPTURE FROM SYSCAT.TABLES WHERE TABSCHEMA ='SCHEMA名' AND TABNAME='表名' AND TYPE='T'
手动开启:
Alter table SCHEMA名.表名 data capture changes
文档更新时间: 2022-03-30 20:03 作者:周风磊