Database crashes regulary

Hi there,

if heavy load occurs on my server (my girlfriend uploaded 400 photos from her Canon EOS 5D with 16Mb each) the database just crashes. I think this might have something to do with the preview generation.

My error log from Nextcloud looks like this:
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /var/www/nextcloud/lib/private/DB/Connection.php(151): Doctrine\DBAL\Connection->setTransactionIsolation(2)
#5 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172):
OC\DB\Connection->__construct(Array, Object(Doctrine\DBAL…
PHP message: PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection refused in /var/www/nextcloud/lib/private/DB/Connection.php:64

Then I just restart MySQL with: “sudo service mysql restart” and everything is working again as expect.

Here my specs:
Nextcloud 13
Nginx 1.13.2
MariaDB 15.1
PHP 7.0

And this is a log from MariaDB:
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: innodb_empty_free_list_algorithm has been changed to legacy because of small buffer pool size. In order to use backoff, increase buffer pool at least up to 20MB.

2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: The InnoDB memory heap is disabled
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Compressed tables use zlib 1.2.8
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Using Linux native AIO
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Using SSE crc32 instructions
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Completed initialization of buffer pool
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Highest supported file format is Barracuda.
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Starting crash recovery from checkpoint LSN=889198160
2018-06-20 12:46:34 140683918524992 [Note] InnoDB: Restoring possible half-written data pages from the doublewrite buffer…
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 1 row operations to undo
InnoDB: Trx id counter is 10128640
2018-06-20 12:46:35 140683918524992 [Note] InnoDB: Starting final batch to recover 4 pages from redo log
2018-06-20 12:46:36 140683918524992 [Note] InnoDB: 128 rollback segment(s) are active.
2018-06-20 12:46:36 140683352467200 [Note] InnoDB: Starting in background the rollback of recovered transactions
2018-06-20 12:46:36 7ff3653fe700 InnoDB: Rolling back trx with id 10128197, 1 rows to undo
2018-06-20 12:46:36 140683918524992 [Note] InnoDB: Waiting for purge to start
2018-06-20 12:46:36 140683352467200 [Note] InnoDB: Rollback of trx with id 10128197 completed
2018-06-20 12:46:36 140683352467200 [Note] InnoDB: Rollback of non-prepared transactions completed
2018-06-20 12:46:36 140683918524992 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.36-82.1 started; log sequence number 889198866
2018-06-20 12:46:36 140683918524992 [Note] Plugin ‘FEEDBACK’ is disabled.
2018-06-20 12:46:36 140683247613696 [Note] InnoDB: Dumping buffer pool(s) not yet started
2018-06-20 12:46:36 140683918524992 [Note] Recovering after a crash using tc.log
2018-06-20 12:46:36 140683918524992 [Note] Starting crash recovery…
2018-06-20 12:46:36 140683918524992 [Note] Crash recovery finished.
2018-06-20 12:46:36 140683918524992 [Note] Server socket created on IP: ‘127.0.0.1’.
2018-06-20 12:46:36 140683918524992 [ERROR] Incorrect definition of table mysql.event: expected column ‘sql_mode’ at position 14 to have type set(‘REAL_AS_FLOAT’,‘PIPES_AS_CONCAT’,‘ANSI_QUOTES’,‘IGNORE_SPACE’,‘IGNORE_BAD_TABLE_OPTIONS’,‘ONLY_FULL_GROUP_BY’,‘NO_UNSIGNED_SUBTRACTION’,‘NO_DIR_IN_CREATE’,‘POSTGRESQL’,‘ORACLE’,‘MSSQL’,‘DB2’,‘MAXDB’,‘NO_KEY_OPTIONS’,‘NO_TABLE_OPTIONS’,‘NO_FIELD_OPTIONS’,‘MYSQL323’,‘MYSQL40’,‘ANSI’,‘NO_AUTO_VALUE_ON_ZERO’,‘NO_BACKSLASH_ESCAPES’,‘STRICT_TRANS_TABLES’,‘STRICT_ALL_TABLES’,‘NO_ZERO_IN_DATE’,‘NO_ZERO_DATE’,‘INVALID_DATES’,‘ERROR_FOR_DIVISION_BY_ZERO’,‘TRADITIONAL’,‘NO_AUTO_CREATE_USER’,‘HIGH_NOT_PRECEDENCE’,‘NO_ENGINE_SUBSTITUTION’,‘PAD_CHAR_TO_FULL_LENGTH’), found type set(‘REAL_AS_FLOAT’,‘PIPES_AS_CONCAT’,‘ANSI_QUOTES’,‘IGNORE_SPACE’,‘NOT_USED’,‘ONLY_FULL_GROUP_BY’,‘NO_UNSIGNED_SUBTRACTION’,‘NO_DIR_IN_CREATE’,‘POSTGRESQL’,‘ORACLE’,‘MSSQL’,‘DB2’,‘MAXDB’,‘NO_KEY_OPTIONS’,‘NO_TABLE_OPTIONS’,‘NO_FIELD_OPTIONS’,‘MYSQL323’,‘MYSQL40’,‘ANSI’,‘NO_AUTO_VALUE_ON_ZERO’,‘NO_BACKSLASH_ESCAPES’,‘STRICT_TRANS_TABLES’,'STRICT_A
2018-06-20 12:46:36 140683918524992 [ERROR] mysqld: Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
2018-06-20 12:46:36 140683918524992 [Note] /usr/sbin/mysqld: ready for connections.
Version: ‘10.1.26-MariaDB-0+deb9u1’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 Debian 9.1

If they give hints in the logs, did you try this? In general, the cache size settings can make a huge difference. There are also some scripts that help you to analyse the settings (tuning-primer.sh, mysqltuner).

Is this a setting I need to specify in MariaDB?
I searched for MariaDB config files on the server but did not found any.

Yes, this is for mariadb. The config files are often in the /etc/mysql/-folder, perhaps some distributions also put it in /etc/mariadb/ or something like that. Check the documentation of your distribution if in doubt.