I have one server in replication. Whenever I am executing a delete query with a limit of 10000 or 100000 on InnoDB table then it returns me Error 1206 so that's why I have started to look into engine status which may help for better performance.
mysql> delete from cdrs where billseconds=0 limit 10000;
ERROR 1206 (HY000): The total number of locks exceeds the lock table size
But still, A beginner does not get enough understanding of what value can be correct or how to calculate which variable needs to be set up properly.
So anyone please suggest which value should be recommended?
mysql> SHOW ENGINE INNODB STATUS\G;
*************************** 1. row ***************************
Type: InnoDB
Name:
Status:
=====================================
2022-06-25 08:05:35 139698390398720 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 5 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 315147 srv_active, 0 srv_shutdown, 1711532 srv_idle
srv_master_thread log flush and writes: 0
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 107425397
OS WAIT ARRAY INFO: signal count 138090595
RW-shared spins 0, rounds 0, OS waits 0
RW-excl spins 0, rounds 0, OS waits 0
RW-sx spins 0, rounds 0, OS waits 0
Spin rounds per wait: 0.00 RW-shared, 0.00 RW-excl, 0.00 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 5868831
Purge done for trx's n:o < 5868831 undo n:o < 0 state: running but idle
History list length 0
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421173985799384, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985803424, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985802616, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985801808, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985801000, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985800192, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985798576, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
---TRANSACTION 421173985797768, not started
0 lock struct(s), heap size 1128, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:
Pending flushes (fsync) log: 0; buffer pool: 193
184939997 OS file reads, 408993938 OS file writes, 191478723 OS fsyncs
0.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 3093, seg size 3095, 64998391 merges
merged operations:
insert 905575573, delete mark 16719939, delete 5094846
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 4 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 759200638267
Log buffer assigned up to 759200638267
Log buffer completed up to 759200638267
Log written up to 759200638267
Log flushed up to 759200638267
Added dirty pages up to 759200638267
Pages flushed up to 759200638267
Last checkpoint at 759200638267
205244131 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 0
Dictionary memory allocated 2465252
Buffer pool size 8192
Free buffers 5735
Database pages 2447
Old database pages 922
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 18667218, not young 4562179027
0.00 youngs/s, 0.00 non-youngs/s
Pages read 184946579, created 25133992, written 155280433
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 2447, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=17499, Main thread ID=139698522695424 , state=sleeping
Number of rows inserted 1052202547, updated 1185599, deleted 18772945, read 2858392871
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
Number of system rows inserted 5488, updated 2933689, deleted 72, read 2992114
0.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
My system memory :
root#ankitdoshi:/home/ankitdoshi# grep MemTotal /proc/meminfo
MemTotal: 131932092 kB
Thanks in advance for your help and suggestions.
By default, MySQL allocates 128MB of space for innodb_buffer_pool_size. To resolve the problem, you'll have to increase the size in /etc/my.cnf file
Edit /etc/my.cnf file, and add the following under the [mysqld] heading.
innodb_buffer_pool_size=256M
after that You'll have to tweak the value of innodb_buffer_pool_size as having large buffer size could introduce Fatal error: cannot allocate memory for the buffer pool problem. You'll have to restart the mysqld service in order to take this new value into effect.
service mysqld restart
Look here enter link description here
Don't delete more than 1000 rows in a chunk, else you hit issues like the one you encountered.
Even better is to avoid big deletes. There are several techniques: http://mysql.rjweb.org/doc.php/deletebig
And, yes, do increase innodb_buffer_pool_size to about 70% of available RAM.
Related
I'm currently import a large CSV file and I'm trying to understand the logs that are coming into my error.log file. The import keeps on going, so this might be nothing, but given that it's logged into the error.log file with a default set-up, and I have no idea what to make out of it, it might be time for me to learn something by reaching out to the MariaDB community.
The log I'm getting is the following:
=====================================
2021-09-30 21:03:22 0x7f0848d41640 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 20 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 564 srv_active, 0 srv_shutdown, 1068 srv_idle
srv_master_thread log flush and writes: 1632
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 309014
--Thread 139674486203968 has waited at trx0undo.cc line 777 for 436.00 seconds the semaphore:
Mutex at 0x56464c440288, Mutex REDO_RSEG created trx0rseg.cc:397, lock var 2
--Thread 139673591895616 has waited at buf0flu.cc line 1214 for 431.00 seconds the semaphore:
SX-lock on RW-latch at 0x7f085fda1ab0 created in file buf0buf.cc line 1563
a writer (thread id 139673460528704) has reserved it in mode exclusive
number of readers 0, waiters flag 1, lock_word: 0
Last time write locked in file trx0rseg.ic line 43
OS WAIT ARRAY INFO: signal count 1296199
RW-shared spins 1239237, rounds 9381718, OS waits 207220
RW-excl spins 865910, rounds 6692891, OS waits 88463
RW-sx spins 375, rounds 11083, OS waits 365
Spin rounds per wait: 7.57 RW-shared, 7.73 RW-excl, 29.55 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 429
Purge done for trx's n:o < 425 undo n:o < 87636886 state: running
History list length 1
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 428, ACTIVE 1482 sec inserting
mysql tables in use 1, locked 1
1 lock struct(s), heap size 1128, 0 row lock(s), undo log entries 51774178
MySQL thread id 48, OS thread handle 139674486203968, query id 78 localhost root Reading file
LOAD DATA INFILE 'file.csv' INTO TABLE TABLE_X
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
lines terminated by '\r\n'
IGNORE 1 LINES
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 1
452318 OS file reads, 589584 OS file writes, 172513 OS fsyncs
66.75 reads/s, 16384 avg bytes/read, 134.49 writes/s, 134.49 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 104 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 237726885168
Log flushed up to 237726880386
Pages flushed up to 237724062470
Last checkpoint at 237724062470
0 pending log flushes, 0 pending chkp writes
3473 log i/o's done, 0.95 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 405471232
Dictionary memory allocated 24640
Buffer pool size 8192
Free buffers 0
Database pages 8088
Old database pages 3003
Modified db pages 3448
Percent of dirty pages(LRU & free pages): 42.626
Max dirty pages percent: 75.000
Pending reads 0
Pending writes: LRU 0, flush list 2, single page 1
Pages made young 1119, not young 211124188
0.00 youngs/s, 200.24 non-youngs/s
Pages read 452305, created 195449, written 499116
66.75 reads/s, 0.00 creates/s, 66.75 writes/s
Buffer pool hit rate 900 / 1000, young-making rate 0 / 1000 not 298 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 8088, unzip_LRU len: 0
I/O sum[27390]:cur[946], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=37451, Main thread ID=139673583502912, state: sleeping
Number of rows inserted 51774178, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
Number of system rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
I believe this is an output due to something timing out, but I have no idea as to what "that" could be. The import doesn't stop either, it just continues on. Any help (or pointers) on dissecting this log would be greatly appreciated!
This question has been moved to dba.stackexchange.com
I managed to create a mysql InnoDB cluster with three nodes and a router everything works great but when i try to run a select query from the table below from a another server it freezes, but it works when i limit the result to a number under 26
SET NAMES utf8;
SET time_zone = '+00:00';
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `v7_addad`;
CREATE TABLE `v7_addad` (
`id` int NOT NULL AUTO_INCREMENT,
`body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`page_id` int NOT NULL,
`done` tinyint NOT NULL DEFAULT '0',
`book` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `body` (`body`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
For example :
select * from v7_addad limit 25; # this works
select * from v7_addad limit 26; # this freezes
BTW if doesn't freeze when trying from the R/W node (the server hosting the main mode).
show engine innodb status;
=====================================
2021-01-02 15:49:26 0x7f8584324700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 11 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 35520 srv_active, 0 srv_shutdown, 135529 srv_idle
srv_master_thread log flush and writes: 0
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 398
OS WAIT ARRAY INFO: signal count 589
RW-shared spins 269, rounds 269, OS waits 0
RW-excl spins 145, rounds 4321, OS waits 134
RW-sx spins 1, rounds 1, OS waits 0
Spin rounds per wait: 1.00 RW-shared, 29.80 RW-excl, 1.00 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 207413
Purge done for trx's n:o < 207412 undo n:o < 0 state: running but idle
History list length 12
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421696252934904, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252933192, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252934048, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252932336, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252931480, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252930624, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421696252929768, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 18446744073709551589
5225 OS file reads, 765431 OS file writes, 599449 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 2.91 writes/s, 2.45 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 3984439, node heap has 2 buffer(s)
Hash table size 3984439, node heap has 1 buffer(s)
Hash table size 3984439, node heap has 1 buffer(s)
Hash table size 3984439, node heap has 2 buffer(s)
Hash table size 3984439, node heap has 1 buffer(s)
Hash table size 3984439, node heap has 3 buffer(s)
Hash table size 3984439, node heap has 4 buffer(s)
Hash table size 3984439, node heap has 7 buffer(s)
0.18 hash searches/s, 1.55 non-hash searches/s
---
LOG
---
Log sequence number 2237873266
Log buffer assigned up to 2237873266
Log buffer completed up to 2237873266
Log written up to 2237873266
Log flushed up to 2237873266
Added dirty pages up to 2237873266
Pages flushed up to 2237873266
Last checkpoint at 2237873266
247265 log i/o's done, 1.18 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 16483614720
Dictionary memory allocated 1956558
Buffer pool size 983040
Free buffers 977601
Database pages 5418
Old database pages 2027
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 5153, created 265, written 361560
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 5418, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size 491520
Free buffers 488755
Database pages 2754
Old database pages 1026
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 2596, created 158, written 229420
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 2754, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size 491520
Free buffers 488846
Database pages 2664
Old database pages 1001
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 2557, created 107, written 132140
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 2664, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=3803, Main thread ID=140203552966400 , state=sleeping
Number of rows inserted 0, updated 33674, deleted 0, read 5195822
0.00 inserts/s, 0.18 updates/s, 0.00 deletes/s, 15.91 reads/s
Number of system rows inserted 33706, updated 1120, deleted 33702, read 85994
0.18 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
MariaDB, myphpadmin
I dropped a table due to issues with creating FK constraint. I am trying to recreate the table but it seems like the FK constraint is still in the DB somewhere. I cannot delete as there is no reference to it, that I can see anyway. I have no idea where to look to drop the constraint
Trying to create the table I get the following error.
=====================================
2020-03-04 18:58:15 0x14c6100cc700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 40 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 82 srv_active, 0 srv_shutdown, 53679 srv_idle
srv_master_thread log flush and writes: 53761
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 467
OS WAIT ARRAY INFO: signal count 372
RW-shared spins 0, rounds 1085, OS waits 396
RW-excl spins 0, rounds 4555, OS waits 20
RW-sx spins 3, rounds 34, OS waits 1
Spin rounds per wait: 1085.00 RW-shared, 4555.00 RW-excl, 11.33 RW-sx
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2020-03-04 18:58:14 0x14c610081700 Error in foreign key constraint of table moviesdb/movie_genre:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
CONSTRAINT `genre_id_fk` FOREIGN KEY (`genre_id`) REFERENCES `genre` (`genre_id`) ON DELETE CASCADE ON UPDATE CASCADE
------------
TRANSACTIONS
------------
Trx id counter 237460
Purge done for trx's n:o < 237460 undo n:o < 0 state: running
History list length 1
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 304315944137048, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 304315944132792, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
5389 OS file reads, 3086 OS file writes, 1050 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.55 writes/s, 0.20 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 69257, node heap has 1 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 1 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 3 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
0.07 hash searches/s, 1.10 non-hash searches/s
---
LOG
---
Log sequence number 845237404
Log flushed up to 845237404
Pages flushed up to 845237404
Last checkpoint at 845237395
0 pending log flushes, 0 pending chkp writes
673 log i/o's done, 0.10 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 285212672
Dictionary memory allocated 847024
Buffer pool size 16030
Free buffers 10583
Database pages 5432
Old database pages 2018
Modified db pages 0
Percent of dirty pages(LRU & free pages): 0.000
Max dirty pages percent: 75.000
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 5071, created 361, written 2302
0.00 reads/s, 0.10 creates/s, 0.40 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 5432, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=488, Main thread ID=22840912578304, state: sleeping
Number of rows inserted 820, updated 2, deleted 4, read 134187
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
Number of system rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
The error message is right there in the log:
Error in foreign key constraint of table moviesdb/movie_genre
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
So basically this means that
either the datatype and length of column genre_id in table movie_genre is not the same as column genre_id in table genre
or: there is no index on genre (genre_id) (or in which genre_id appears first); if so, this would indicate another flaw with your table structure as, most probably, genre_id should be the primary key of the genre table.
Cause
After run a backed up sql file to my local computer, My computer cpu run 100%.
my steps:
before run sql file
/*avoid error DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled*/
SET GLOBAL log_bin_trust_function_creators = 1;
SET GLOBAL max_allowed_packet=1073741824;
create a new database
run a sql file (backed up in mysql 5.7.17) to import structure and data at this new database
import success;
1 minute after successful import, win10 cpu usage 100%;
screenshots:
Version
win10 1909(18363.449)
MySQL 8.0.16
Troubleshoot
show full processlist;
results:
show engine innodb status
results:
=====================================
2019-10-25 09:31:09 0x3d00 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 40 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 347 srv_active, 0 srv_shutdown, 2245 srv_idle
srv_master_thread log flush and writes: 0
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 316
OS WAIT ARRAY INFO: signal count 1781
RW-shared spins 799, rounds 800, OS waits 1
RW-excl spins 9658, rounds 25501, OS waits 212
RW-sx spins 8, rounds 172, OS waits 5
Spin rounds per wait: 1.00 RW-shared, 2.64 RW-excl, 21.50 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 371410743
Purge done for trx's n:o < 371410741 undo n:o < 0 state: running but idle
History list length 37
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 282782365114120, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365113248, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365112376, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365111504, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365110632, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365109760, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365108888, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365122840, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365118480, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 282782365108016, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: wait Windows aio (insert buffer thread)
I/O thread 1 state: wait Windows aio (log thread)
I/O thread 2 state: wait Windows aio (read thread)
I/O thread 3 state: wait Windows aio (read thread)
I/O thread 4 state: wait Windows aio (read thread)
I/O thread 5 state: wait Windows aio (read thread)
I/O thread 6 state: wait Windows aio (write thread)
I/O thread 7 state: wait Windows aio (write thread)
I/O thread 8 state: wait Windows aio (write thread)
I/O thread 9 state: wait Windows aio (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
1980 OS file reads, 176203 OS file writes, 56718 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.67 writes/s, 0.42 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 462, seg size 464, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 34679, node heap has 2 buffer(s)
Hash table size 34679, node heap has 2 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 3 buffer(s)
Hash table size 34679, node heap has 4 buffer(s)
Hash table size 34679, node heap has 3 buffer(s)
Hash table size 34679, node heap has 5 buffer(s)
0.00 hash searches/s, 0.35 non-hash searches/s
---
LOG
---
Log sequence number 73725445734
Log buffer assigned up to 73725445734
Log buffer completed up to 73725445734
Log written up to 73725445734
Log flushed up to 73725445734
Added dirty pages up to 73725445734
Pages flushed up to 73725445734
Last checkpoint at 73725445734
136624 log i/o's done, 0.17 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 137363456
Dictionary memory allocated 3671937
Buffer pool size 8192
Free buffers 1024
Database pages 7147
Old database pages 2618
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 1763, not young 20320
0.00 youngs/s, 0.00 non-youngs/s
Pages read 1947, created 17850, written 33619
0.00 reads/s, 0.00 creates/s, 0.30 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 7147, unzip_LRU len: 0
I/O sum[15]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=17416, Main thread ID=0000000000003E6C , state=sleeping
Number of rows inserted 142096, updated 54521, deleted 59578, read 563375
0.00 inserts/s, 0.10 updates/s, 0.00 deletes/s, 0.40 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
Tried solutions
restart mysql service, no effect, after restart, cpu still 100%
net mysql stop
net mysql start
restart my computer, no effect, after restart, cpu still 100%
show full processlist and kill some sleep or time cost most processes, no effect
show OPEN TABLES where In_use > 0; no results;
delete this new database, everything is ok,but this is useless
Thank you so much to everyone who helped.
Edit:
The queries are executed from AWS Lambda and it is a AWS Aurora MySQL compatible database.
It is a M5.large database that has about 70 database connections and around 7% cpu load.
End Edit.
We have a dead lock that we are struggling to understand. It happens very rarely and of course when the requests are very close to each other in time.
How can we get better understanding when this happens?
What is best practice in cases like this? Is it ok to accept this and write your code to rerun the query?
Below is more information output from show engine innodb status
2019-07-31 10:44:08 0x2b0f9939d700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 14 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 457179 srv_active, 0 srv_shutdown, 158871 srv_idle
srv_master_thread log flush and writes: 0
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 353267
OS WAIT ARRAY INFO: signal count 363003
RW-shared spins 0, rounds 60860, OS waits 3736
RW-excl spins 0, rounds 278008, OS waits 4241
RW-sx spins 834, rounds 12583, OS waits 94
Spin rounds per wait: 60860.00 RW-shared, 278008.00 RW-excl, 15.09 RW-sx
------------------------
LATEST DETECTED DEADLOCK
------------------------
2019-07-29 00:01:57 0x2b122b42b700
*** (1) TRANSACTION:
TRANSACTION 25004785, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 7 lock struct(s), heap size 1136, 4 row lock(s), undo log entries 1
MySQL thread id 1067258, OS thread handle 47346011883264, query id 192217819 160.170.30.251 root update
INSERT INTO logs (date, time, duration, source, another_table_id, date_id) VALUES ('2019-07-29', '00:00:06', 20047, 0, 6793, 3629) ON DUPLICATE KEY UPDATE duration = VALUES(duration)
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 252 page no 15293 n bits 0 index logs_another_table__c5da8410_uniq of table `database`.`logs` trx id 25004785 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len=8; bufptr=0x2b1111b00070; hex= 73757072656d756d; asc supremum;;
*** (2) TRANSACTION:
TRANSACTION 25004783, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 8 lock struct(s), heap size 1136, 5 row lock(s), undo log entries 1
MySQL thread id 1067257, OS thread handle 47345995474688, query id 192217812 160.170.10.38 root update
INSERT INTO logs (date, time, duration, source, another_table_id, date_id) VALUES ('2019-07-28', '23:59:05', 20047, 0, 6792, 3631) ON DUPLICATE KEY UPDATE duration = VALUES(duration)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 252 page no 15293 n bits 0 index logs_another_table__c5da1234_uniq of table `database`.`logs` trx id 25004783 lock_mode X
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len=8; bufptr=0x2b1111b00070; hex= 73757072656d756d; asc supremum;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 252 page no 15293 n bits 0 index logs_another_table__c5da1234_uniq of table `database`.`logs` trx id 25004783 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len=8; bufptr=0x2b1111b00070; hex= 73757072656d756d; asc supremum;;
------------
TRANSACTIONS
------------
Trx id counter 30159757
Purge done for trx's n:o < 30159757 undo n:o < 0 state: running but idle
History list length 2976
--------
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] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
0 OS file reads, 0 OS file writes, 0 OS fsyncs
0.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 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
Hash table size 2303461, node heap has 0 buffer(s)
0.00 hash searches/s, 1.00 non-hash searches/s
---
LOG
---
Log sequence number 8204
Log flushed up to 0
Pages flushed up to 8204
Last checkpoint at 8192
0 pending log flushes, 0 pending chkp writes
0 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 0
Dictionary memory allocated 4272484
Buffer pool size 510568
Free buffers 271669
Database pages 238899
Old database pages 88146
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 2287, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 49550, created 189349, written 4828
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 238899, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size 255284
Free buffers 136125
Database pages 119159
Old database pages 43966
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 1238, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 24722, created 94437, written 68
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 119159, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size 255284
Free buffers 135544
Database pages 119740
Old database pages 44180
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 1049, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 24828, created 94912, written 4760
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 119740, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=8465, Main thread ID=47357039400704, state: sleeping
Number of rows inserted 3672324, updated 8861306, deleted 2146, read 1562714829
0.00 inserts/s, 0.50 updates/s, 0.00 deletes/s, 0.64 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================