2

My server keeps running out of memory for mysql. I keep getting. 150708 3:39:09 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258064 bytes)

When I looked in my.cnf I saw that innodb_buffer_pool_size was 134217728

I am assuming that is in bytes which would translate to 134MB. Should I change innodb_buffer_pool_size=134217728

to innodb_buffer_pool_size=500MB

When I ran Rolando's query I got 481M as the Recommended_InnoDB_Buffer_Pool_Size:

SELECT CONCAT(CEILING(RIBPS/POWER(1024,pw)),SUBSTR(' KMGT',pw+1,1))
Recommended_InnoDB_Buffer_Pool_Size FROM
(
SELECT RIBPS,FLOOR(LOG(RIBPS)/LOG(1024)) pw
FROM
(
    SELECT SUM(data_length+index_length)*1.1*growth RIBPS
    FROM information_schema.tables AAA,
    (SELECT 1.25 growth) BBB
    WHERE ENGINE='InnoDB'
) AA
) A;

Recommended_InnoDB_Buffer_Pool_Size 481M

Below is the full copy of my.cnf

[mysqld]
thread_cache_size=6
query_cache_type=2
key_buffer_size=256M
open_files_limit=10000
query_cache_size=256M
# safe-show-database
table_cache=1024
query_cache_limit=1M
default-storage-engine=MyISAM
innodb_file_per_table=1
innodb_read_io_threads=8
innodb_write_io_threads=8
# Try number of cpus*2 for thread_concurrency
thread_concurrency=12
max_allowed_packet=268435456

max_connections=200
query_cache_size=64M
thread_cache_size=16
join_buffer_size=256K
read_buffer_size=256K
sort_buffer_size=256K
tmp_table_size=512M
max_heap_table_size=512M
max_delayed_threads=0
innodb_buffer_pool_size=134217728

This is the backtrace around the time of the last crash I already fixed the thecityo_production_wp/wp_wfVulnScanners error:

I have 10 GB of ram and 180 GB Disk space along with 6 shared cores.

key_buffer_size=268435456
read_buffer_size=262144
max_used_connections=0
max_threads=200
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 366904 K  bytes of memory
Hope thats ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x35)[0x7aabf5]
/usr/sbin/mysqld(handle_fatal_signal+0x4a4)[0x686324]
/lib64/libpthread.so.0(+0xf710)[0x7fdd49402710]
/lib64/libc.so.6(gsignal+0x35)[0x7fdd485c9625]
/lib64/libc.so.6(abort+0x175)[0x7fdd485cae05]
/usr/sbin/mysqld[0x8fbd91]
/usr/sbin/mysqld[0x8b9638]
/usr/sbin/mysqld[0x926aa5]
/usr/sbin/mysqld[0x91b362]
/usr/sbin/mysqld[0x857c7a]
/usr/sbin/mysqld[0x84cbc2]
/lib64/libpthread.so.0(+0x79d1)[0x7fdd493fa9d1]
/lib64/libc.so.6(clone+0x6d)[0x7fdd4867f8fd]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
150708 03:31:13 mysqld_safe mysqld from pid file /var/lib/mysql/mo.serveroflight.com.pid ended
150708 03:36:35 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150708  3:36:35 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
150708  3:36:35 [Note] Plugin 'FEDERATED' is disabled.
150708  3:36:35 InnoDB: The InnoDB memory heap is disabled
150708  3:36:35 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150708  3:36:35 InnoDB: Compressed tables use zlib 1.2.3
150708  3:36:35 InnoDB: Using Linux native AIO
150708  3:36:35 InnoDB: Initializing buffer pool, size = 128.0M
150708  3:36:35 InnoDB: Completed initialization of buffer pool
150708  3:36:35 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 48687241371
150708  3:36:35  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 48687308434
150708  3:36:36  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 
InnoDB: Apply batch completed
150708  3:36:36  InnoDB: Error: table 'thecityo_production_wp/wp_wfNet404s'
InnoDB: in InnoDB data dictionary has tablespace id 20744,
InnoDB: but tablespace with that id or name does not exist. Have
InnoDB: you deleted or moved .ibd files?
InnoDB: This may also be a table created with CREATE TEMPORARY TABLE
InnoDB: whose .ibd and .frm files MySQL automatically removed, but the
InnoDB: table still exists in the InnoDB internal data dictionary.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue.
150708  3:36:36  InnoDB: Error: table 'thecityo_production_wp/wp_wfVulnScanners'
InnoDB: in InnoDB data dictionary has tablespace id 20745,
InnoDB: but tablespace with that id or name does not exist. Have
InnoDB: you deleted or moved .ibd files?
InnoDB: This may also be a table created with CREATE TEMPORARY TABLE
InnoDB: whose .ibd and .frm files MySQL automatically removed, but the
InnoDB: table still exists in the InnoDB internal data dictionary.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue.
150708  3:36:36  InnoDB: Waiting for the background threads to start
150708  3:36:37 InnoDB: 5.5.42 started; log sequence number 48687308434
150708  3:36:37 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
150708  3:36:37 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
150708  3:36:37 [Note] Server socket created on IP: '0.0.0.0'.
150708  3:36:37 [Note] Event Scheduler: Loaded 0 events
150708  3:36:37 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.42-cll'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
150708  3:38:40 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:43 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258104 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258640 bytes)
150708  3:38:48 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258104 bytes)
150708  3:38:49 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258104 bytes)
150708  3:38:49 InnoDB: Unable to allocate memory of size 289800.
150708  3:38:51  InnoDB: Assertion failure in thread 139869977511680 in file mem0mem.c line 361
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
07:38:51 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed, 
something is definitely wrong and this may fail.

key_buffer_size=268435456
read_buffer_size=262144
max_used_connections=181
max_threads=200
thread_count=164
connection_count=164
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 366904 K  bytes of memory
Hope thats ok; if not, decrease some variables in the equation.

Thread pointer: 0x3aef460
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7f70e2625e58 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x35)[0x7aabf5]
/usr/sbin/mysqld(handle_fatal_signal+0x4a4)[0x686324]
/lib64/libpthread.so.0(+0xf710)[0x7f7120768710]
/lib64/libc.so.6(gsignal+0x35)[0x7f711f92f625]
/lib64/libc.so.6(abort+0x175)[0x7f711f930e05]
/usr/sbin/mysqld[0x8fbd91]
/usr/sbin/mysqld[0x8fbdee]
/usr/sbin/mysqld[0x881fc7]
/usr/sbin/mysqld[0x83c104]
/usr/sbin/mysqld[0x83efa5]
/usr/sbin/mysqld[0x81819b]
/usr/sbin/mysqld(_Z13rr_sequentialP11READ_RECORD+0x1f)[0x74de7f]
/usr/sbin/mysqld(_Z10sub_selectP4JOINP13st_join_tableb+0x79)[0x5ace99]
/usr/sbin/mysqld[0x5b16c7]
/usr/sbin/mysqld(_ZN4JOIN4execEv+0xc81)[0x5c6f41]
/usr/sbin/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x12c)[0x5c873c]
/usr/sbin/mysqld(_Z13handle_selectP3THDP3LEXP13select_resultm+0x165)[0x5c9175]
/usr/sbin/mysqld[0x584392]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x144d)[0x5894cd]
150708  3:39:09 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258064 bytes)
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x330)[0x58ce20]
/usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x1af3)[0x58f1e3]
/usr/sbin/mysqld(_Z24do_handle_one_connectionP3THD+0xd7)[0x629297]
/usr/sbin/mysqld(handle_one_connection+0x51)[0x6293d1]
/lib64/libpthread.so.0(+0x79d1)[0x7f71207609d1]
/lib64/libc.so.6(clone+0x6d)[0x7f711f9e58fd]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7f70e40187c0): is an invalid pointer
Connection ID (thread ID): 234
Status: NOT_KILLED

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
150708 03:39:11 mysqld_safe Number of processes running now: 0
150708 03:39:11 mysqld_safe mysqld restarted
150708  3:39:11 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
150708  3:39:12 [Note] Plugin 'FEDERATED' is disabled.
150708  3:39:12 InnoDB: The InnoDB memory heap is disabled
150708  3:39:12 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150708  3:39:12 InnoDB: Compressed tables use zlib 1.2.3
150708  3:39:12 InnoDB: Using Linux native AIO
150708  3:39:12 InnoDB: Initializing buffer pool, size = 128.0M
150708  3:39:12 InnoDB: Completed initialization of buffer pool
150708  3:39:12 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 48687567559
150708  3:39:12  InnoDB: Database was not shut down n
2

I am not totally convinced MySQL is running out of memory. Here is why:

ASPECT #1

When you use mysqltuner.pl, it calculates the total usage in the worst case scenario. It does it by adding 3 figures together

  • key_buffer_size
  • innodb_buffer_pool_size
  • thread_memory : max_connections * the sum of
    • sort_buffer_size
    • join_buffer_size
    • read_buffer_size
    • read_rnd_buffer_size

In your case, given your current settings, that would be the sum of

  • key_buffer_size (256M)
  • innodb_buffer_pool_size (128M)
  • thread_memory (200M) : max_connections (200) * the sum of

    • sort_buffer_size (256K)
    • join_buffer_size (256K)
    • read_buffer_size (256K)
    • read_rnd_buffer_size (256K is default)
  • With given settings, your absolute worst case memory consumption for MySQL is 584M (256M + 128M + 200M).

  • If you use RIBPS, your absolute worst case memory consumption for MySQL would become 939M (256M + 481M + 200M).
  • If you use 500M, your absolute worst case memory consumption for MySQL would become 958M (256M + 481M + 200M).

Therefore, at its very worst, MySQL would consume only 9.58% of RAM.

ASPECT #2

You did not mention if the Server is a dedicated DB Server or if you are running a full stack. If you are running a full stack, please lower any memory-sensitive settings in the other parts of the stack (Varnish (more like Vanish), PHP, Munin, Nagios, Tomcat, Hibernate, etc).

ASPECT #3

Looking at the first crash around 3:36 AM I see

150708  3:36:36  InnoDB: Error: table 'thecityo_production_wp/wp_wfNet404s'
InnoDB: in InnoDB data dictionary has tablespace id 20744,
InnoDB: but tablespace with that id or name does not exist. Have
InnoDB: you deleted or moved .ibd files?
InnoDB: This may also be a table created with CREATE TEMPORARY TABLE
InnoDB: whose .ibd and .frm files MySQL automatically removed, but the
InnoDB: table still exists in the InnoDB internal data dictionary.

At that point, MySQL is complaining that the data dictionary entry for the table wp_wfNet404s in the thecityo_production_wp database is still inside the system tablespace.

Next, mysqld restarted and was ready for new connections

150708  3:36:37 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.42-cll'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

One minute later, it crashed again. What was in the stack trace of the second crash ?

stack_bottom = 7f70e2625e58 thread_stack 0x40000
/usr/sbin/mysqld(my_print_stacktrace+0x35)[0x7aabf5]
/usr/sbin/mysqld(handle_fatal_signal+0x4a4)[0x686324]
/lib64/libpthread.so.0(+0xf710)[0x7f7120768710]
/lib64/libc.so.6(gsignal+0x35)[0x7f711f92f625]
/lib64/libc.so.6(abort+0x175)[0x7f711f930e05]
/usr/sbin/mysqld[0x8fbd91]
/usr/sbin/mysqld[0x8fbdee]
/usr/sbin/mysqld[0x881fc7]
/usr/sbin/mysqld[0x83c104]
/usr/sbin/mysqld[0x83efa5]
/usr/sbin/mysqld[0x81819b]
/usr/sbin/mysqld(_Z13rr_sequentialP11READ_RECORD+0x1f)[0x74de7f]
/usr/sbin/mysqld(_Z10sub_selectP4JOINP13st_join_tableb+0x79)[0x5ace99]
/usr/sbin/mysqld[0x5b16c7]
/usr/sbin/mysqld(_ZN4JOIN4execEv+0xc81)[0x5c6f41]
/usr/sbin/mysqld(_Z12mysql_selectP3THDPPP4ItemP10TABLE_LISTjR4ListIS1_ES2_jP8st_orderSB_S2_SB_yP13select_resultP18st_select_lex_unitP13st_select_lex+0x12c)[0x5c873c]
/usr/sbin/mysqld(_Z13handle_selectP3THDP3LEXP13select_resultm+0x165)[0x5c9175]
/usr/sbin/mysqld[0x584392]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x144d)[0x5894cd]
150708  3:39:09 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258064 bytes)
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x330)[0x58ce20]
/usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x1af3)[0x58f1e3]
/usr/sbin/mysqld(_Z24do_handle_one_connectionP3THD+0xd7)[0x629297]
/usr/sbin/mysqld(handle_one_connection+0x51)[0x6293d1]
/lib64/libpthread.so.0(+0x79d1)[0x7f71207609d1]
/lib64/libc.so.6(clone+0x6d)[0x7f711f9e58fd]

It looks like you were doing some kind of SELECT ... JOIN query. My guess would be you were accessing the corrupt table in the SELECT ... JOIN because of this line

/usr/sbin/mysqld(_Z13rr_sequentialP11READ_RECORD+0x1f)[0x74de7f]

which might by some kind of sequential read.

If you keep seeing

150708  3:36:36  InnoDB: Error: table 'thecityo_production_wp/wp_wfNet404s'

upon every crash and restart of mysqld, you need to clean that entry out of ibdata1.

I would not be fooled by

150708  3:39:09 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 258064 bytes)

It is complaining about not allocating 252K. That's just a side affect of the error because it could allocate needed memory for an operation that cannot read from a table.

EPILOGUE

Please look into removing the pidgeon hole in the data dictionary. Also, look for other memory consuming components in the DB Server.

  • Thank you Rolando, I cleaned up the corrupted databases of 'thecityo_production_wp/wp_wfNet404s' and thecityo_production_wp/wp_wfVulnScanners after I posted this message. So I think the Data Dictionary is not corrupt anymore. If that seemed to solve the problem I will vote yours as the answer. Thank you for the response. – adjc98 Jul 10 '15 at 12:18
  • Good point on running a full stack. The database is not running on a dedicated server, although it would be good to do that. I am going to check on php and the other processes running. Thanks! – adjc98 Jul 10 '15 at 12:27
  • Cleaning up the database seemed to solve the problem. I had to use a special drop command to get the table to drop. I am having trouble finding the command I ran, but it was something like drop table '#mysql5.3#tablename'. If anyone can add the command to this forum that would be great. – adjc98 Jul 13 '15 at 16:11
0

10 GB of ram -- nothing is threatening to hit this.
open_files_limit=10000 -- Try 2000
query_cache_size=256M -- No more than 50M
default-storage-engine=MyISAM -- Unless you already have some InnoDB tables, this means that innodb_buffer_pool_size may as well be 0 -- you aren't using it.

So, I will guess one of this is the case:

  • 32-bit OS
  • 32-bit build of MySQL
  • The OS is limiting how much memory each process can have.

What OS?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.