[db2inst1@db22 ~]$ db2 create database yynewlog
DB20000I The CREATE DATABASE command completed successfully.
####2.此时查看数据库目录
[db2inst1@db22 YYNEWLOG]$ pwd
/home/db2inst1/db2inst1/NODE0000/YYNEWLOG
[db2inst1@db22 YYNEWLOG]$ ls
T0000000 T0000001 T0000002
[db2inst1@db22 YYNEWLOG]$ ls T0000000/
C0000000.CAT
####3.先看一下此时的配置
[db2inst1@db22 YYNEWLOG]$ db2 get db cfg for yynewlog | grep -i log
Database Configuration for Database yynewlog
Log retain for recovery status = NO
User exit for logging status = NO
Changed path to log files (NEWLOGPATH) =
Path to log files = /home/db2inst1/db2inst1/NODE0000/SQL00005/LOGSTREAM0000/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
Second log archive method (LOGARCHMETH2) = OFF
Archive compression for logarchmeth2 (LOGARCHCOMPR2) = OFF
####5.开启循环日志
[root@db22 /]# mkdir /data/db2data
[root@db22 /]# chown db2inst1 /data/db2data
[db2inst1@db22 YYNEWLOG]$ db2 update db cfg for yynewlog using logarchmeth1 DISK:/data/db2data
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
####6.我们建个表
[db2inst1@db22 ~]$ db2 "create table student(id int not null,name varchar(20),sex smallint,phone varchar(12),address varchar(30))"
DB20000I The SQL command completed successfully.
#此时,可以看到logarchmeth1下面有db2inst1的路径了。
[root@db22 db2data]# ls -lh
total 4.0K
drwxr-x---. 3 db2inst1 db2iadm1 4.0K Oct 13 19:38 db2inst1
#目录展开是这样子的。
[root@db22 C0000000]# pwd
/data/db2data/db2inst1/YYNEWLOG/NODE0000/LOGSTREAM0000/C0000000
[root@db22 C0000000]# ls
####7.插入一些数据后查看logarchmeth1下的日志
[db2inst1@db22 ~]$ db2 "insert into student with t1(col1) as (values(100001) union all select t1.col1+1 from t1 where t1.col1<200000)
select t1.col1,'chaeles',0,'153387766677','JINAN' from t1"
DB20000I The SQL command completed successfully.
[root@db22 C0000000]# pwd
/data/db2data/db2inst1/YYNEWLOG/NODE0000/LOGSTREAM0000/C0000000
[root@db22 C0000000]# ls -lh
total 8.1M
-rw-r-----. 1 db2inst1 db2iadm1 4.1M Oct 13 19:51 S0000000.LOG
-rw-r-----. 1 db2inst1 db2iadm1 4.1M Oct 13 19:51 S0000001.LOG
####8.此时进入 Path to log files = /home/db2inst1/db2inst1/NODE0000/SQL00005/LOGSTREAM0000/这个路径,看一下
[db2inst1@db22 YYNEWLOG]$ cd /home/db2inst1/db2inst1/NODE0000/SQL00005/LOGSTREAM0000/
[db2inst1@db22 LOGSTREAM0000]$ ls
S0000000.LOG S0000002.LOG S0000004.LOG S0000006.LOG S0000008.LOG S0000010.LOG S0000012.LOG
S0000001.LOG S0000003.LOG S0000005.LOG S0000007.LOG S0000009.LOG S0000011.LOG
####9.分析
[db2inst1@db22 LOGSTREAM0000]$ db2 get db cfg for yynewlog | grep -i log
Database Configuration for Database yynewlog
... ... ...
Log file size (4KB) (LOGFILSIZ) = 1024
Changed path to log files (NEWLOGPATH) =
Path to log files = /home/db2inst1/db2inst1/NODE0000/SQL00005/LOGSTREAM0000/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
First active log file = S0000005.LOG
First log archive method (LOGARCHMETH1) = DISK:/data/db2data/
![logarchmeth1下的日志和path to log files下的日志](https://img-blog.csdn.net/20171016090408381?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbmF5YW5taW54aW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
从这个截图来看,就可以知道了,
Path to log files里面的是活动日志;首先分配LOGPRIMARY个活动日志,如果这些空间(LOGPRIMARY * LOGFILSIZ*4K=13*1024*4K=13*4MB=52MB)不足够支持一个事务,那么再分配LOGSECOND个日志(是一次性分配LOGSECOND个日志还是一个个的分配直至达到LOGSECOND个呢?:是一次性分配一个,直至logsecond的设置值)(一旦logsecond因为某个事务分配达到最大值了,后续的小事务不需要用到logsecond的情况logsecond个文件数目也是不会减少的吧?:)。
LOGARCHMETH1的定义是已归档的日志,就是说,活动日志最终被归档到logarchmeth1的目录下去,然后已归档的活动日志就可以被覆盖重新/循环使用了。 所以我们检查日志空间是否足够可用的时候主要是检查这个当前正在使用的活动日志的空间,也就是Path to log files所设置的路径,而NEWLOGPATH和MIRRORLOGPATH都是和这个路径相关的。
[db2inst1@db22 LOGSTREAM0000]$ db2 get db cfg for yynewlog | grep -i 'First' First active log file = S0000005.LOG
First log archive method (LOGARCHMETH1) = DISK:/data/db2data/
[db2inst1@db22 LOGSTREAM0000]$ ls
S0000005.LOG S0000007.LOG S0000009.LOG S0000011.LOG S0000013.LOG S0000015.LOG S0000017.LOG S0000019.LOG
S0000006.LOG S0000008.LOG S0000010.LOG S0000012.LOG S0000014.LOG S0000016.LOG S0000018.LOG S0000020.LOG
[db2inst1@db22 LOGSTREAM0000]$ db2 "insert into student with t1(col1) as (values(1000011) union all select t1.col1+1 from t1 where t1.col1<16000000)select t1.col1,'chakda',0,'19089076756','beij' from t1"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0964C The transaction log for the database is full. SQLSTATE=57011
[db2inst1@db22 LOGSTREAM0000]$ ls
S0000020.LOG S0000023.LOG S0000026.LOG S0000029.LOG S0000032.LOG S0000035.LOG S0000038.LOG S0000041.LOG S0000044.LOG
S0000021.LOG S0000024.LOG S0000027.LOG S0000030.LOG S0000033.LOG S0000036.LOG S0000039.LOG S0000042.LOG
S0000022.LOG S0000025.LOG S0000028.LOG S0000031.LOG S0000034.LOG S0000037.LOG S0000040.LOG S0000043.LOG
此参数定义每个主日志文件和辅助日志文件的大小。在这些日志文件已满且需要新日志文件之前,这些日志文件的大小限制可写入这些日志文件的日志记录数。
[db2inst1@db22 ~]$ db2 get db cfg for kilo | grep -i logfilsiz
Log file size (4KB) (LOGFILSIZ) = 1024
这表示每个日志文件的大小是1024个4KB,也就是每个文件大小是4MB。
此参数允许您指定最多 242 个字节的字符串,以更改存储日志文件的位置。
通过修改NEWLOGPATH的值来看一下这个位置到底存放了什么日志?是循环日志吗?
回答:是当前正在使用的循环日志,这个循环日志是活动日志,然后事务完成之后,会在恰当的时候将日志文件归档到logarchmeth1设置的路径下。