乐众国际备用网址-超导体 手套 搭配

首页

AD联系:507867812

乐众国际备用网址

时间:2019-11-22 06:08:45 作者:新利18官网备用 浏览量:97977

乐众国际备用网址innodb中的REDO解析innodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux,见下图

innodb中的REDO解析

innodb中的REDO解析innodb中的REDO解析,见下图

innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析,如下图

innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

innodb中的REDO解析

如下图

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux,如下图

innodb中的REDO解析innodb中的REDO解析,见图

乐众国际备用网址

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析innodb中的REDO解析innodb中的REDO解析innodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析。

innodb中的REDO解析

乐众国际备用网址

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

innodb中的REDO解析

1.innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

2.innodb中的REDO解析。

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析innodb中的REDO解析

3.innodb中的REDO解析。

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

4.

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析innodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linuxinnodb中的REDO解析

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux。乐众国际备用网址

展开全文
相关文章
环亚国际备用域名

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux

明升88备用线路

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

bet36体育在线备用网址_

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

5wkcom金沙备用

innodb中的REDO解析....

新2备用网址开户

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

相关资讯
英皇国际yh备用网址

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

皇博国际备用网站

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

99真人备用网址娱乐

在innodb存储引擎中,事务日志通过重做(redo)日志文件和innodb存储引擎的日志缓冲(innodb log buffer)来实现;当开始一个事务时,会记录该事务的一个LSN(Log sequence number),当事务执行是,会往innodb存储引擎的缓冲池里插入事务日志,当事务提交是,必须将innodb粗才能引擎的日志缓冲写入磁盘(默认的实现,即innodb_flush_log_at_trx_commit=1),也就是写数据前,需要先写日志,这种方式为预写日志方式(write-ahead logging,WAL).

INNODB存储引擎的预写日志方式来保证事务的完整性。这意味着磁盘上的存储的数据页和内存缓冲池中的页是不同步的,对于内粗缓冲中的页的修改,首先是写入重做日志文件,然后再写入磁盘。因此是一种异步的方式。可以通过show engine innodb status来观察当前的磁盘和日志的差距;

mysql> create table z(a int,primary key(a)) engine=innodb;Query OK, 0 rows affected (0.01 sec)

mysql>mysql> create procedure load_test(count int) begin declare i int unsigned default 0; -> start transaction; -> while i<count do -> insert into z select i; -> set i=i+1; -> end while; -> commit; -> end; -> $$ Query OK, 0 rows affected (0.05 sec)

mysql> delimiter ;mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:41:01 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 12 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 224 1_second, 224 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 228----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F45Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F41, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 4162 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5065 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1923 OS file writes, 1010 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594246629Log flushed up to 594246629Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes649 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 0Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: waiting for server activityNumber of rows inserted 105750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

mysql> call load_test(10000);Query OK, 0 rows affected (0.50 sec)

mysql> show engine innodb status\G;*************************** 1. row *************************** Type: InnoDB Name: Status: =====================================121130 15:43:06 INNODB MONITOR OUTPUT=====================================Per second averages calculated from the last 3 seconds-----------------BACKGROUND THREAD-----------------srv_master_thread loops: 231 1_second, 230 sleeps, 18 10_second, 66 background, 66 flushsrv_master_thread log flush and writes: 234----------SEMAPHORES----------OS WAIT ARRAY INFO: reservation count 114, signal count 113Mutex spin waits 6, rounds 180, OS waits 2RW-shared spins 99, rounds 2970, OS waits 99RW-excl spins 0, rounds 390, OS waits 13Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 390.00 RW-excl------------------------LATEST DETECTED DEADLOCK------------------------121130 14:17:47*** (1) TRANSACTION:TRANSACTION 11F40, ACTIVE 71 sec starting index readmysql tables in use 1, locked 1LOCK WAIT 3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root statisticsselect * from t3 where a=2 for update*** (1) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F40 lock_mode X locks rec but not gap waitingRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) TRANSACTION:TRANSACTION 11F41, ACTIVE 42 sec starting index readmysql tables in use 1, locked 13 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 79, OS thread handle 0x33d62600, query id 4153 localhost root statisticsselect * from t3 where a=1 for update*** (2) HOLDS THE LOCK(S):RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gapRecord lock, heap no 3 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000002; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a011d; asc : ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 0 page no 3132 n bits 80 index `PRIMARY` of table `test`.`t3` trx id 11F41 lock_mode X locks rec but not gap waitingRecord lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 00: len 4; hex 80000001; asc ;;1: len 6; hex 000000011f35; asc 5;;2: len 7; hex e00000013a0110; asc : ;;

*** WE ROLL BACK TRANSACTION (2)------------TRANSACTIONS------------Trx id counter 11F46Purge done for trx's n:o < 11F35 undo n:o < 0History list length 1433LIST OF TRANSACTIONS FOR EACH SESSION:---TRANSACTION 11F45, not startedMySQL thread id 79, OS thread handle 0x33d62600, query id 34168 localhost rootshow engine innodb status---TRANSACTION 11F36, not startedMySQL thread id 77, OS thread handle 0x33d61e80, query id 4118 localhost root---TRANSACTION 11F2B, not startedMySQL thread id 75, OS thread handle 0x33d61d40, query id 4077 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 74, OS thread handle 0x33d61fc0, query id 4070 192.168.0.69 root---TRANSACTION 0, not startedMySQL thread id 23, OS thread handle 0x33d62380, query id 114 192.168.0.69 root---TRANSACTION 11F40, ACTIVE 5190 sec3 lock struct(s), heap size 320, 2 row lock(s)MySQL thread id 80, OS thread handle 0x33d62740, query id 4152 localhost root--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0Pending flushes (fsync) log: 0; buffer pool: 0691 OS file reads, 1925 OS file writes, 1012 OS fsyncs0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s-------------------------------------INSERT BUFFER AND ADAPTIVE HASH INDEX-------------------------------------Ibuf: size 1, free list len 0, seg size 2, 0 mergesmerged operations:insert 0, delete mark 0, delete 0discarded operations:insert 0, delete mark 0, delete 0Hash table size 553253, node heap has 6 buffer(s)0.00 hash searches/s, 0.00 non-hash searches/s---LOG---Log sequence number 594751037Log flushed up to 594751037Last checkpoint at 5942466290 pending log writes, 0 pending chkp writes651 log i/o's done, 0.00 log i/o's/second----------------------BUFFER POOL AND MEMORY----------------------Total memory allocated 135987200; in additional pool allocated 0Dictionary memory allocated 281610Buffer pool size 8192Free buffers 4305Database pages 3881Old database pages 1418Modified db pages 31Pending reads 0Pending writes: LRU 0, flush list 0, single page 0Pages made young 5, not young 00.00 youngs/s, 0.00 non-youngs/sPages read 633, created 3248, written 58750.00 reads/s, 0.00 creates/s, 0.00 writes/sNo buffer pool page gets since the last printoutPages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/sLRU len: 3881, unzip_LRU len: 0I/O sum[0]:cur[0], unzip sum[0]:cur[0]--------------ROW OPERATIONS--------------0 queries inside InnoDB, 0 queries in queue1 read views open inside InnoDBMain thread id 869673728, state: sleepingNumber of rows inserted 115750, updated 0, deleted 0, read 597170.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s----------------------------END OF INNODB MONITOR OUTPUT============================

1 row in set (0.00 sec)

ERROR: No query specified

mysql>

Log sequence number 表示当前的LSN;Log flushed up表示刷新到重做日志文件的LSN,Last checkpoint表示刷新到磁盘的LSN;

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux....

热门资讯