【DB2】关闭表的日志功能
2018.11.19
客户遇到一个问题,在import数据的时候,产生了大量的日志,客户的数据库是HADR模式,通过评估,这几张表是可以允许在备库上不查询的,表中的数据时临时的。
| 方案一:修改脚本,将import修改为load |
| 方案二:修改脚本,不修改导入数据的方式,临时激活表的not logged initially特性,事务级别 |
| 方案三:将相关的表重建,创建表,并激活not logged initially,该方案表将永久修改为not logged initially |
三种方案结果都是一样的,由于不写日志,均会导致备库表无法查询,报错SQL1477N
现在存在一个疑问,假如使用方案二,同时 import 时使用 commitcount,会不会存在问题呢 ? 针对该问题,得到下面结论
alter table t activate not logged initially;
import from t.del of del commitcount 10 insert into t;
通过验证 commitcount 10 会导致 activate not logged initially 失效。
所以将 commitcount 10 取消掉,这个参数对于该场景,意义不大,由于表不写日志,一旦事务失败均会导致表不可访问。
编辑m.sql文件 connect to sample;
alter table t activate not logged initially;
import from t.del of del insert into t;
commit; db2 +c -tvf m.sql
中英文
https://www.ibm.com/support/knowledgecenter/zh/SSEPGG_11.1.0/com.ibm.db2.luw.admin.ha.doc/doc/c0006079.html
https://www.ibm.com/support/knowledgecenter/da/SSEPGG_11.1.0/com.ibm.db2.luw.admin.ha.doc/doc/c0006079.html
附录1:
https://www-01.ibm.com/support/docview.wss?uid=swg21215818
Technote (FAQ)
Question
How to temporarily turn logging off for heavy change operations, such as insert, delete, update, and changes in indexes?
Answer
Tables being modified can be altered to activate the 'NOT LOGGED INITIALLY' attribute, which deactivates logging for the current unit of work. Any changes made to the table by an INSERT, DELETE, UPDATE, CREATE INDEX, DROP INDEX, or ALTER TABLE in the same unit of work after the table is altered by this statement are not logged.
At the completion of the current unit of work, the NOT LOGGED INITIALLY attribute is deactivated for the table and all operations that are done on the table in subsequent units of work are logged.
To use this option properly, the application doing the changes should NOT have AUTOCOMMIT enabled. Having AUTOCOMMIT OFF also helps define the scope of the transactions:
- For CLP, you can turn AUTOCOMMIT OFF using the registry variable DB2OPTIONS:
db2set DB2OPTIONS=+c
- If you execute a script containing update SQL statements, such as inserts, and DB2OPTIONS is not set, you can execute the script using:
db2 +c -tvf input_script.sql -z output_script.out
Example
To create table T1 with the 'not logged initially' attribute:
db2 create table T1(id int) NOT LOGGED INITIALLY
or, if tables T1 and T2 are already created, create a transaction with all the operations that are not intended to be logged:
db2 alter table T1 activate not logged initially
db2 alter table T2 activate not logged initially
db2 delete from T1 where ...
db2 update T2 set ...
db2 import from data_file.txt of del insert into T2
db2 commit
The updates in T1 and T2 within this unit of work will not be logged.
Notes
1. You can create more than one table with the NOT LOGGED INITIALLY parameter in the same unit of work.
2. Changes to the catalog tables and other user tables are still logged.
Because changes to the table are not logged, you should consider the following when deciding to use the NOT LOGGED INITIALLY table attribute:
* All changes to the table will be flushed out to disk at commit time. This means that the commit may take longer.
* If the NOT LOGGED INITIALLY attribute is activated and an activity occurs that is not logged, the entire unit of work will be rolled back if a statement fails or a ROLLBACK TO SAVEPOINT is executed (SQL1476N).
* You cannot recover these tables when rolling forward. If the rollforward operation encounters a table that was created or altered with the NOT LOGGED INITIALLY option, the table is marked as unavailable. After the database is recovered, any attempt to access the table returns SQL1477N.
- If using stored procedures, the whole stored procedure defines a transaction by default, unless an explicit COMMIT is called within the procedure code. So, the 'ALTER TABLE ... ACTIVATE NOT LOGGED INITIALLY' can be called at the beginning of the procedure, and a COMMIT statement at end of the procedure (or after the procedure has been called) will end the transaction.
- This document and suggestions given to prevent logging activity do not apply to LOAD utility, since LOAD does not do logging.
【DB2】关闭表的日志功能的更多相关文章
- 关闭ext4文件系统的日志功能
最近在帮一个研究生弄一个虚拟化环境下的基于Innodb的日志文件的读写优化的实验,实验的具体详细内容就不说了,其中有一个步骤需要将MySQL的日志文件放置在一块单独的硬盘里面,这块硬盘要么是ext2, ...
- MySQL日志功能详解
MySQL日志功能详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查询日志 它是用来保存所有跟查询相关的日志,这种日志类型默认是关闭状态的,因为MySQL的用户有很多,如果 ...
- Winform开发框架之权限管理系统改进的经验总结(4)-一行代码实现表操作日志记录
在前面介绍了几篇关于我的权限系统改进的一些经验总结,本篇继续这一系列主体,介绍如何一行代码实现重要表的操作日志记录.我们知道,在很多业务系统里面,数据是很敏感的,特别对于一些增加.修改.删除等关键的操 ...
- Spring AOP 实现写事件日志功能
什么是AOP?AOP使用场景?AOP相关概念?Spring AOP组件?如何使用Spring AOP?等等这些问题请参考博文:Spring AOP 实现原理 下面重点介绍如何写事件日志功能,把日志保存 ...
- SSIS从理论到实战,再到应用(6)----SSIS的自带日志功能
原文:SSIS从理论到实战,再到应用(6)----SSIS的自带日志功能 上期回顾: SSIS从理论到实战,再到应用(5)----流程控制之Foreach循环 博主最近新负责了一个ssis大项目的架构 ...
- 如何在通用权限管理系统中集成log4net日志功能
开发人员都知道,在系统运行中要记录各种日志,自己写一个日志功能,无论是在效率还是功能扩展上来说都不是很好,目前大多用的是第三方的日志系统,其中一个非常有名,用的最多的就是log4net.下面是关于这个 ...
- MySQL二进制日志功能介绍
二进制日志记录所有更新数据的SQL语句,其中也包含可能更新数据的SQL语句,例如DELETE语句执行过程中无匹配的行.二进制日志中还包含了与执行SQL语句相关的内容,例如SQL语句执行的时间.错误代码 ...
- 怎么关闭win10快速访问功能?关闭Windows10系统快速访问方法
怎么关闭win10快速访问功能?关闭Windows10系统快速访问方法 Windows10系统的"快速访问"功能很容易泄露电脑中的隐私,用什么方法可以让这个功能消失,避免电脑的个人 ...
- Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件
本文通过Java代码调用Shell脚本并传入参数实现DB2数据库表导出到文件,代码如下: import java.io.File; import java.io.IOException; import ...
随机推荐
- 2018.07.17 后缀自动机模板(SAM)
洛谷传送门 这是一道后缀自动机的模板题,这道题让我切身体会到了后缀自动机的方便与好写. 代码如下: #include<bits/stdc++.h> #define N 2000005 #d ...
- c++ => new/delete
new的具体使用方式如下: 类型 *变量名 = new 类型; delete 变量 / delete[] 变量; 类型包括数组.结构体和类 数组申请动态内存后,要使用delete[]才能把内存清除干净 ...
- json&pickle
用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换pickle,用于python特有的类型 和 python的数据类型间进行转换Json模块提供了四个功能:dumps.du ...
- 如何使用Java执行cmd命令
用JAVA代码实现执行CMD命令的方法! Runtime rt = Runtime.getRuntime(); Process p = rt.exec(String[] cmdarray); ...
- 简单的nginx模拟网站的负载均衡
环境:nginx1.10.3 虚拟机环境:3台centos7虚拟机 将148机器作为转发服务器配置如下 监听80端口,在http里面配置如下 将edc.com分别转发到149和150的服务器上 本地主 ...
- 3D UI场景中,把XY平面的尺寸映射为屏幕像素的数学模型推导
概述及目录(版权所有,请勿转载,欢迎读者提出错误) 之前用kanzi的3D UI引擎和cocos-2d的时候都有遇到过这个问题,就如何把3D场景中的XY平面的尺寸映射为与屏幕像素一一对应的,即XY平面 ...
- 【最大流之ek算法】HDU1532 求最大流
本来是继续加强最短路的训练,但是遇到了一个最短路 + 最大流的问题,最大流什么鬼,昨天+今天学习了一下,应该对ek算法有所了解,凭借学习后的印象,自己完成并ac了这个最大流的模板题 题目大意:都是图论 ...
- Dwz(J-UI)框架--入门
http://www.cnblogs.com/chenyongsai/p/4933982.html Dwz(J-UI)框架--入门 一.了解 概述:是中国人自己开发的基于jQuery实现的Ajax R ...
- C#数组的定义,不定长的数组?
首先,在这里我要说明的是,C#中,定义了数组,那么就必须为其指定长度,且他的长度确定,不能够更改.一旦定义一个数组,那么操作系统就在内存中给这个数组指定了一块内存,他是不支持动态分配存储空间的.能够动 ...
- C#使用MongoDb来存储文件
近期在写一个小玩意,需要保存一些图片,以前我采用的是FTP或者直接数据库保存文件,用FTP来保存文件感觉比较麻烦,用数据库吧,还要改字段类型,修改代码,修改查询语句,懒得改. 以前看过mongonDb ...