Not Logged Initially Tables 意思知道,翻译的话感觉有点别扭,就这么着了。
The NOT LOGGED INITIALLY clause of the CREATE TABLE statement allows you to create a table that will not be logged when an INSERT, UPDATE, DELETE, CREATE INDEX, ALTER TABLE, or DROP INDEX operation is performed in the same unit of work in which the CREATE TABLE statement was issued.
db2inst2@sles11:~> db2 get db cfg for zzdb2 |grep -i "log" Log retain for recovery status = NO User exit for logging status = YES Catalog cache size (4KB) (CATALOGCACHE_SZ) = 300 Log buffer size (4KB) (LOGBUFSZ) = 256 Log file size (4KB) (LOGFILSIZ) = 128 Number of primary log files (LOGPRIMARY) = 13 Number of secondary log files (LOGSECOND) = -1
--SecureCRT session 2 db2inst2@sles11:/db2log2> db2 get db cfg for zzdb2 |grep -i "first active" First active log file = S0000045.LOG
--创建表时指定 NOT LOGGED INITIALLY ,commit前不产生日志 --SecureCRT session 1 db2 => begin declare i int default 0; while (i<100000) do insert into t1 values('aaaaaaaaa' || char(i),'bbbbbb'||char(i) ); set i=i+1; end while; end @ db2 => COMMIT @ --SecureCRT session 2 db2inst2@sles11:/db2log2> db2 get db cfg for zzdb2 |grep -i "first active" First active log file = S0000045.LOG
--commit后,新的插入语句会产生日志 --SecureCRT session 1 db2 => begin declare i int default 100000; while (i<200000) do insert into t1 values('aaaaaaaaa' || char(i),'bbbbbb'||char(i) ); set i=i+1; end while; end @ db2 => COMMIT @
--SecureCRT session 2 db2inst2@sles11:/db2log2> db2 get db cfg for zzdb2 |grep -i "first active" First active log file = S0000058.LOG
--手动使 NOT LOGGED INITIALLY 生效,在 commti 之前,不产生日志 --SecureCRT session 1 db2 => ALTER TABLE t1 ACTIVATE NOT LOGGED INITIALLY @ db2 => begin declare i int default 200000; while (i<300000) do insert into t1 values('aaaaaaaaa' || char(i),'bbbbbb'||char(i) ); set i=i+1; end while; end@ db2 => commit@
--SecureCRT session 2 db2inst2@sles11:/db2log2> db2 get db cfg for zzdb2 |grep -i "first active" First active log file = S0000059.LOG
Any operation from the CREATE TABLE statement until the first COMMIT is not logged. Once the COMMIT is issued, any subsequent operation is logged. For this example, the INSERT and UPDATE statements after the first COMMIT are logged.
After creating the table as NOT LOGGED INITIALLY, if you would like to turn off logging temporarily again, you can use the ALTER TABLE statement with the ACTIVATE NOT LOGGED INITIALLY clause, as shown in the example. Any operations between the ALTER TABLE and the second COMMIT are not logged.
--清空表 ALTER TABLE t1 ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE
不记日志,利弊都有。
The advantage of using the NOT LOGGED INITIALLY parameter is that any changes made on a table (including insert, delete, update, or create index operations) in the same unit of work that creates the table will not be logged. This not only reduces the logging that is done, but can also increase the performance of your application. You can achieve the same result for existing tables by using the ALTER TABLE statement with the NOT LOGGED INITIALLY parameter.
An attempt was made to access a table where one of its objects is not accessible.
The table may not be accessible because of one of the following reasons:
1) The table had NOT LOGGED INITIALLY activated when the unit of work was rolled back.
2) The table is a partitioned created temporary table or declared temporary table and
one or more database partitions failed since the temporary table was instantiated or declared.
3) ROLLFORWARD encountered the activation of NOT LOGGED INITIALLY on this table or a NONRECOVERABLE load on this table.
SQL1477N 解决方案:
One of the following actions can be taken.
1) If the object is a table and it had NOT LOGGED INITIALLY activated,
drop the table. If this table is required, re-create it.
2) If the object is a data partition, detach it from the table.
If this data partition is required, add a new one.
3) If the object is a non-partitioned index, drop the index.
If this index is required, create a new one.
4) If the table is a created temporary table, disconnect from the server and connect again to
instantiate a new copy of the created temporary table.
5)If the table is a declared temporary table, drop the table.
If this table is required, declare it again.
6)Otherwise, restore from a table space or database backup.
The backup image must have been taken subsequent to the commit point following the completion of
the non-recoverable operation (NOT LOGGED INITIALLY operation, or NONRECOVERABLE load).
Because changes to the table are not logged,
you should consider the following when deciding to use the NOT LOGGED INITIALLY table attribute:
1) All changes to the table will be flushed out to disk at commit time. This means that the commit might take longer.
2) 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).
3) If you are using high availability disaster recovery (HADR) you should not use the NOT LOGGED INITIALLY table attribute.
Tables created on the primary database with the NOT LOGGED INITIALLY option specified are not replicated to the standby database.
Attempts to access such tables on an active standby database or after the standby becomes the primary
as a result of a takeover operation will result in an error (SQL1477N).
4) 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.
添加新评论7 条评论
2014-06-14 08:31
The advantage of using the NOT LOGGED INITIALLY parameter is that any changes made on a table (including insert, delete, update, or create index operations) in the same unit of work that creates the table will not be logged. This not only reduces the logging that is done, but can also increase the performance of your application. You can achieve the same result for existing tables by using the ALTER TABLE statement with the NOT LOGGED INITIALLY parameter.
2014-06-14 08:25
SQL1477N 报错解释:
An attempt was made to access a table where one of its objects is not accessible.
The table may not be accessible because of one of the following reasons:
1) The table had NOT LOGGED INITIALLY activated when the unit of work was rolled back.
2) The table is a partitioned created temporary table or declared temporary table and
one or more database partitions failed since the temporary table was instantiated or declared.
3) ROLLFORWARD encountered the activation of NOT LOGGED INITIALLY on this table or a NONRECOVERABLE load on this table.
SQL1477N 解决方案:
One of the following actions can be taken.
1) If the object is a table and it had NOT LOGGED INITIALLY activated,
drop the table. If this table is required, re-create it.
2) If the object is a data partition, detach it from the table.
If this data partition is required, add a new one.
3) If the object is a non-partitioned index, drop the index.
If this index is required, create a new one.
4) If the table is a created temporary table, disconnect from the server and connect again to
instantiate a new copy of the created temporary table.
5)If the table is a declared temporary table, drop the table.
If this table is required, declare it again.
6)Otherwise, restore from a table space or database backup.
The backup image must have been taken subsequent to the commit point following the completion of
the non-recoverable operation (NOT LOGGED INITIALLY operation, or NONRECOVERABLE load).
2014-06-14 08:22
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.admin.ha.doc/doc/c0006079.html?lang=en
Because changes to the table are not logged,
you should consider the following when deciding to use the NOT LOGGED INITIALLY table attribute:
1) All changes to the table will be flushed out to disk at commit time. This means that the commit might take longer.
2) 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).
3) If you are using high availability disaster recovery (HADR) you should not use the NOT LOGGED INITIALLY table attribute.
Tables created on the primary database with the NOT LOGGED INITIALLY option specified are not replicated to the standby database.
Attempts to access such tables on an active standby database or after the standby becomes the primary
as a result of a takeover operation will result in an error (SQL1477N).
4) 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.
2014-06-14 08:15
2014-06-12 16:59
2014-06-09 10:10
2014-06-07 22:50