最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MariaDB Retains Unused Memory and Causes OOM Kill - Stack Overflow

programmeradmin1浏览0评论

I'm facing a memory management issue with MariaDB in one of my projects. My environment:

MariaDB version: 10.6.18
Total RAM: 4GB

Current Configuration:

[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 100
table_open_cache = 800
thread_cache_size = 24
query_cache_size = 0

Problem: At startup, MariaDB consumes less than 1GB of memory, which is expected. However, over time, memory usage grows beyond 2GB and eventually crashes due to an Out of Memory (OOM) kill, with this systemd error:

systemd[1]: mariadb.service: Failed with result 'oom-kill'.

Restarting the server every few days temporarily resolves the issue, but I’m looking for a more sustainable solution.

Question:

Is there a way to force MariaDB to release unused memory instead of holding onto it unnecessarily?
Are there configuration tweaks or commands that can help prevent memory leaks and excessive memory retention?

Any insights or best practices to manage MariaDB's memory efficiently would be greatly appreciated!

I'm facing a memory management issue with MariaDB in one of my projects. My environment:

MariaDB version: 10.6.18
Total RAM: 4GB

Current Configuration:

[mysqld]
innodb_buffer_pool_size = 256M
max_connections = 100
table_open_cache = 800
thread_cache_size = 24
query_cache_size = 0

Problem: At startup, MariaDB consumes less than 1GB of memory, which is expected. However, over time, memory usage grows beyond 2GB and eventually crashes due to an Out of Memory (OOM) kill, with this systemd error:

systemd[1]: mariadb.service: Failed with result 'oom-kill'.

Restarting the server every few days temporarily resolves the issue, but I’m looking for a more sustainable solution.

Question:

Is there a way to force MariaDB to release unused memory instead of holding onto it unnecessarily?
Are there configuration tweaks or commands that can help prevent memory leaks and excessive memory retention?

Any insights or best practices to manage MariaDB's memory efficiently would be greatly appreciated!

Share Improve this question edited Mar 4 at 0:08 ysth 98.6k6 gold badges125 silver badges217 bronze badges asked Mar 3 at 18:08 AFA MedAFA Med 2472 silver badges13 bronze badges 4
  • Have you tried to use MySQL? – i486 Commented Mar 3 at 19:38
  • No, I prefer to stick with MariaDB and find a solution to the issue since it's running in a production environment, and migrating to MySQL would require significant effort. – AFA Med Commented Mar 3 at 19:48
  • 2 MariaDB-10.11 and above will release memory on memory pressure and are more durable against OOM. Its not designed as something to be hit regularly. show global status like '%memory%'; might provide a comparison point. – danblack Commented Mar 4 at 2:27
  • 1 note that 10.6 reaches end of life in 16 months, 10.11 in 35 months, and 11.4 in 50 months. try to have an upgrade cadence in mind when making upgrade decisions – ysth Commented Mar 4 at 15:23
Add a comment  | 

1 Answer 1

Reset to default 2

Your settings seem fine, even conservative, for 4GB of RAM, so I think the problem is elsewhere.

  • No, there is no way (that I know of, other than restarting) to force MySQL/MariaDB to free up memory.

  • Are there other applications (web server, clients, etc) running on the same server?

  • Although max_connections = 100 is reasonable, I would start by cutting that in half and checking the clients (eg Apache) to see that they are not flooding MariaDB with hundreds of connections.

  • If this is Linux (or similar OS), edit /etc/sysctl.conf and add vm.swappiness = 1 to the end. This should make the OS slower to hit OOM.

  • Upgrade MariaDB. There is a tiny chance of a "memory leak" in the version you are using. (If you can narrow down what is causing the suspected leak, file a bug report.)

  • In case this Question gets closed, move to dba.stackexchange .

发布评论

评论列表(0)

  1. 暂无评论