MySQL stuck in an upgrade loop with high CPU usage

OK, wow; I just found it because that huge error log line tells you what’s wrong! Specifically:

failed with error code = 1436, error message = 'Thread stack overrun: 12576 bytes used of a 131072 byte stack, and 160000 bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack.'

SOLUTION:
I found a config file which set the thread_size and edited it:
root@my_server:# nano -w /etc/mysql/mysql.conf.d/mysqld.cnf

Changed the line that says: thread_stack = 128K to: thread_stack = 256K.

I can now start the service with service mysql start and it doesn’t crash. Running apt upgrade goes through without failing, too.
END SOLUTION:

However, it’s not solved yet; mysqld is still running with >90% CPU usage.

I rebooted and CPU usage stayed high. I can run mysql now with: mysql -u root -p (enter password) and I get to the mysql> prompt.

I’ve got htop open in another window and I query what it’s doing to take the high CPU:
mysql> select * from performance_schema.threads where THREAD_OS_ID = 1881 \G
(where 1881) is the PID of the high CPU usage thread.

It says:

mysql> select * from performance_schema.threads where THREAD_OS_ID = 1881 \G
*************************** 1. row ***************************
          THREAD_ID: 34
               NAME: thread/innodb/srv_purge_thread
               TYPE: BACKGROUND
     PROCESSLIST_ID: NULL
   PROCESSLIST_USER: NULL
   PROCESSLIST_HOST: NULL
     PROCESSLIST_DB: NULL
PROCESSLIST_COMMAND: NULL
   PROCESSLIST_TIME: 111
  PROCESSLIST_STATE: NULL
   PROCESSLIST_INFO: NULL
   PARENT_THREAD_ID: NULL
               ROLE: NULL
       INSTRUMENTED: YES
            HISTORY: YES
    CONNECTION_TYPE: NULL
       THREAD_OS_ID: 1881
     RESOURCE_GROUP: SYS_default
1 row in set (0.00 sec)

So, it’s doing a purge of something. I’ll let it run a bit longer…

… and after 10 mins, the CPU usage has dropped…

2 Likes