-2

How Can I Automatically Restart MariaDB After Memory-Induced Crash.

I've encountered a recurring problem where memory spikes lead to the crash of MariaDB on my server, causing my site to go offline. I am searching for an effective method or tool that can promptly restart MariaDB after the recurring crashes to keep the website running while I work on a permanent solution to the memory overload problem.

Has anyone dealt with a similar issue or can suggest a reliable approach to automate the MariaDB service's recovery after such unexpected shutdowns?

How to Reduce Website Downtime?

Progress so far: Open the file with a text editor like nano or vim. For example:

sh

sudo nano /etc/systemd/system/mariadb.service 

In the [Service] section, I added the following lines:

ini

Restart=on-failure RestartSec=5s 

After:

sh

sudo systemctl restart mariadb.service sudo systemctl daemon-reload 

Now the question is will this work, am I doing the right thing here? Is there a way to test this without waiting for mariadb to crash again?

8
  • 1
    Configure systemd to restart a service after crash. But this is not entirely appropriate way "to keep website running while working on a permanent solution". The proper temporary solution would be to increase the memory available to the database (install more physical memory into the server, or increase the amount available to the VM or container memory limit); depending to later analysis, it might become the proper permanent solution. Commented Nov 4, 2023 at 4:44
  • well increasing memory for me is not a solution, how can I configure systemd to restart mariadb after a crash ? Commented Nov 4, 2023 at 5:41
  • I would investigate the root cause of the crash. Just restarting mariadb can probably cause databases corruption issues. Maybe you can optimize some long running queries or queries that take a lot of compute resources. And if you automatically restart make sure you have backups including transaction log backups. Instead of increasing the memory have you considered spreading the load for mariadb over two servers by creating a cluster? Commented Nov 4, 2023 at 6:50
  • I would also recommend to let atop run on the mariadb server, so you can better analyze why it's crashing from a performance side. Just restarting because of crashes is the worst idea ever. Take this opportunity to also learn and grow yourself by trouble shooting. Because what if restarting at some point doesn't solve the crashes anymore Commented Nov 4, 2023 at 6:57
  • I'm grateful for the encouragement to expand my skill set. The database crashes are occurring because I've configured an excessive number of PHP processes in www.conf. When all these processes initiate, it depletes the available memory, leading to the crash. Commented Nov 4, 2023 at 8:13

1 Answer 1

1

Based on my research the best practice is this:

# Restart crashed server only, on-failure would also restart, for example, when # my.cnf contains unknown option Restart=on-abort RestartSec=5s 

In this kind of situations you would put something like rabbitmq in between the app and the database. That way you can fire as many request in php, rabbitmq will quene them and send them in batches to the database.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.