select ends with killed in mysql

I ran a query in mysql and it hangs for a while and then I get killed as a response.


mysql> select * from usagehistory;
Killed
SHELL:~$
SHELL:~$ date
Thu Mar 14 06:26:17 UTC 2019
SHELL:~$


Reason

The mysql process/client itself runs out of memory and is terminated by the OS. I do not have a good view of the implementation, but it appears that mysql is trying something like pulling the whole table into memory to do the select *.

You can use the --quick mysql option to not buffer the results in memory.


I also found out that the data in table is around 2 GB and Memory in my jump-box is around 1 GB.

Two more proofs that I see in my jump box (where mysql is run) system is:

1. I see OOM messages in syslog.

root@ip-XXX-XXX-XXX-XXX:~# grep mysql /var/log/syslog | less
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.301028] mysql invoked oom-killer: gfp_mask=0x24201ca, order=0, oom_score_adj=0
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.301032] mysql cpuset=/ mems_allowed=0
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.301038] CPU: 0 PID: 25553 Comm: mysql Not tainted 4.4.0-1074-aws #84-Ubuntu
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.301237] [25553]  1000 25553   235060   210811     434       3        0             0 mysql
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.301251] Out of memory: Kill process 25553 (mysql) score 832 or sacrifice child
Mar 14 06:25:40 ip-XXX-XXX-XXX-XXX kernel: [529731.306445] Killed process 25553 (mysql) total-vm:940240kB, anon-rss:842532kB, file-rss:712kB
(END)

Press :q to exit.


2. I see free memory going down when I execute the query. I use free -m command. Another command that can be used is vmstat.


SHELL:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            990          75         818           8          96         783
Swap:             0           0           0
SHELL:~#
SHELL:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            990         400         494           8          96         458
Swap:             0           0           0
SHELL:~#
SHELL:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            990         669         224           8          96         189
Swap:             0           0           0
SHELL:~#
SHELL:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            990         885          52           8          52           7
Swap:             0           0           0


NOTE: After getting the Killed response from mysql, the free memory comes back again.


SHELL:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            990          75         860           8          53         804
Swap:             0           0           0    
SHELL:~#


Some References 

MySQL Query with LARGE number of records gets Killed 

Mysql client ran out of memory 

Debug out-of-memory with /var/log/messages 

What To Do When MySQL Runs Out of Memory: Troubleshooting Guide 

Comments

Back To Top

Popular posts from this blog

How to save video from Internet Explorer

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables