一些大表的插入更新删除等操作,会占用大量的活动日志,如果用户不希望对这些
操作不做日志记录可以使用activate not logged initially,
对于不记录事务日志的问题是:
1.db2的rollback和rollforward都依赖日志,如果没有记录日志,该事务如果rollback了(锁超时,
内存不足等),那么会导致该表不可以访问;
2.归档日志模式下的数据库的restore+rollforward,如果rollforward到不记录日志操作的
时间点后,也会导致该表不可访问,只能drop了重建,所以应当在这些不记日志操作之后
立刻对数据库或表空间做一个备份。
DB2 load导入数据的操作也是不会通过事务日志来记录变化,所以load操作提供copy yes
和copy no的参数,no是load结束后要手动备份,yes是load的过程同时对数据做了一个备份。
db2 "load from tb1.del of del insert into tb2 copy yes to /db2cfg"
db2 load query table tb2
1.事务中开启不记录日志,事务rollback后,表不可访问:
[test@demo db2cfg]$ db2 +c "alter table tb1 activate not logged initially" ---->只在该事务中tb1不记录日志
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 +c "insert into tb1 values(666,'yo666') "
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 rollback
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 "select * from tb1"
ID NAME
----------- ----------
SQL1477N For table "TEST.TB1" an object "4" in table space "4" cannot be
accessed. SQLSTATE=55019
2.前滚到不记录时间之后,表不可访问,若在不记录日志操作后立即备份,便可解决问题
1>首先做一次全备
[test@demo db2cfg]$ db2 backup db testdb online
Backup successful. The timestamp for this backup image is : 20190108183351
2>执行一个事务不记录日志,后立刻对该表空间做了备份
[test@demo db2cfg]$ db2 +c "alter table tb1 activate not logged initially"
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 +c "insert into tb1 values(666,'yo666') "
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 commit
DB20000I The SQL command completed successfully.
[test@demo db2cfg]$ db2 "backup db testdb tablespace(ts2) online"
Backup successful. The timestamp for this backup image is : 20190108183712
3>往ts2表空间的tb1表和tb2表都再插入一些数据
[test@demo db2cfg]$ db2 "select * from tb1"
ID NAME
----------- ----------
1 yo1
2 yo2
3 yo3
666 yo666
4 record(s) selected.
[test@demo db2cfg]$ db2 "select * from tb2"
ID NAME
----------- ----------
1 yo1
2 yo2
3 yo3
3 record(s) selected.
db2 "insert into tb1 values(6,'yo6'),(66,'yo66')"
db2 "insert into tb2values(6,'yo6'),(66,'yo66')"
4>恢复数据库并前滚至最新日志状态
db2 restore db testdb taken at 20190108183351
db2 rollforward db testdb to end of logs and complete
[test@demo db2cfg]$ db2 "select * from tb2" --->tb2表显示是最新状态
ID NAME
----------- ----------
1 yo1
2 yo2
3 yo3
6 yo6
66 yo66
5 record(s) selected.
[test@demo db2cfg]$ db2 "select * from tb1" --->tb1表则不可用
ID NAME
----------- ----------
SQL1477N For table "TEST.TB1" an object "4" in table space "4" cannot be
accessed. SQLSTATE=55019
5>使用不记录日志后的表空间备份再一次恢复
[test@demo db2cfg]$ db2 "restore db testdb tablespace(ts2) taken at 20190108183712"
DB20000I The RESTORE DATABASE command completed successfully.
[test@demo db2cfg]$ db2 "rollforward db testdb to end of logs and complete tablespace(ts2)"
Rollforward Status
Input database alias = testdb
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = -
Last committed transaction = 2019-01-08-10.45.13.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
[test@demo db2cfg]$ db2 "select * from tb1" ---->tb1和tb2都正常并前滚到最新状态
ID NAME
----------- ----------
1 yo1
2 yo2
3 yo3
666 yo666
6 yo6
66 yo66
6 record(s) selected.