Terminating Stuck Database Queries Instead of Restarting the Database

Restarting the database service is hardly ever necessary, and is not the way to resolve database issues. The most common cause for questions about database restarts is stuck SQL queries. Terminating stuck queries allows you to address specific performance bottlenecks without taking the entire database offline. This approach is often preferred when you want to minimize downtime and impact on other processes.

Stuck and long-running database queries

Stalled queries or long-running queries can be managed in phpMyAdmin by selecting the database, then Status > Processes.

The process list displays a list of the currently running queries and can be refreshed with the “refresh” button. Database queries run in parallel, so there will usually be multiple queries running at the same time. 

You can kill specific queries from this interface. The query will not be completed but aborted and the query will return a failed response to your CMS, web app, or cron job. 

Alternative method

An alternative method of terminating/killing stuck database queries would be to run the SHOW PROCESSLIST query. From this interface, you can terminate queries by clicking the “stop symbol” on the left side. Clicking the symbol will give you a prompt before being executed.

Image from phpmyadmin showing stuck database queries
Image showing a prompt to kill a database query

When is the database server restarted?

Only when it’s needed. Servebolt restarts database servers when the database service is upgraded, and the upgrade requires a service restart. The database service will also be restarted when the server is rebooted.