NC intermittently very slow or freezing

NC16.0.3 installed on VPS-server, Ubuntu 18.0.4, Nginx.

Since 4 days the site is intermittently freezing or not accessible. No indication of a problem in the terminal. Top is normal. Once the service has become accessible I see no errors in the log.
Today I had to restart the service. Did not help. I restored the installation from a snapshot. Did not help. The desktop client is slowly getting contact and tries to log-in. The site seems to be accessed normally from GTmetrix and Pingdon.
MTR command from my terminal (from server to my IP) shows normal times and no packets loss. From my computer to the servers IP I get one time out at the second hop but then no issues (I do not know if that indicates an issue).
The same result from my mobilephone (directly from the ISP - not WiFi).

Found an error in nexcloud.error.log
2019/09/09 09:07:09 [error] 761#761: *3 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:64
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(448): OC\DB\Connection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(410): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(354): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(710): 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(181): OC\DB\Connection->__construct(Array, Objec…PHP message: PHP Fatal error: Uncaught Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/nextcloud/lib/private/DB/Connection.php:64
S
2019/09/09 09:15:33 [warn] 754#754: *245 a client request body is buffered to a temporary file /var/lib/nginx/body/0000000001, client: XXXXXXXXXX, server: mydomainintra.se, request: “POST /lool/convert-to/png HTTP/1.1”, host: “mydomain-intra.se”

How can I troubleshooting this?

Check why nextcloud can’t connect to your database.
For displaying mysql infos on your database server :
sudo service mysql status
And check your network too, if it is on another machine.
The following linux command allows you to test a connection to your database:
mysql -B --connect-timeout=5 -u NEXTCLOUD_DB_USER -p NEXTCLOUD_DB_PASSWORD -h SERVER_DB_IP -P 3306 -e "quit" >/dev/null 2>/dev/null && echo 'Successfull: your database is online and connection is working' || echo 'Connection to database FAIL'

Thanks

Sudo service mysql status gave this result
mariadb.service - MariaDB 10.3.15 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Mon 2019-09-09 09:07:09 CEST; 5h 49min ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 1009 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 1004 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Process: 612 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=/usr/bin/galera_recovery; [ $? -eq 0 ]
Process: 599 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 590 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Main PID: 949 (mysqld)
Status: “Taking your SQL requests now…”
Tasks: 34 (limit: 4915)
CGroup: /system.slice/mariadb.service
└─949 /usr/sbin/mysqld

Sep 09 09:07:07 server systemd[1]: Starting MariaDB 10.3.15 database server…
Sep 09 09:07:08 myserver: 2019-09-09 9:07:08 0 [Note] /usr/sbin/mysqld (mysqld 10.3.15-MariaDB-1:1
Sep 09 09:07:09 myserver/etc/mysql/debian-start[1012]: /usr/bin/mysql_upgrade: the ‘–basedir’ option is alway
Sep 09 09:07:09 myserver /etc/mysql/debian-start[1012]: Looking for ‘mysql’ as: /usr/bin/mysql
Sep 09 09:07:09 myserver /etc/mysql/debian-start[1012]: Looking for ‘mysqlcheck’ as: /usr/bin/mysqlcheck
Sep 09 09:07:09 myserver /etc/mysql/debian-start[1012]: This installation of MySQL is already upgraded to 10.3.
Sep 09 09:07:09 myserver systemd[1]: Started MariaDB 10.3.15 database server.
~
I do not know if the 2019-09-09 9:07:08 0 [Note] /usr/sbin/mysqld (mysqld 10.3.15-MariaDB-1:10.3.15+maria~bionic-log) starting as process 949 …
indicates a problem.

Roland

No their is nothing.

The same address than indicate in your nextcloud/config/config.php for “dbhost”. If your nextcloud is on the same machine than your database, it’s localhost or 127.0.0.1

But i have often same problem than you (intermittent freeze) but the error indicate is “mysql is gone away”. Investigating for more than a year has not provided me any answer to this problem.

PS : when you copy-paste information, remove IP adresse, hostname and other sensitives informations :wink: Just indicate if it’s local machine or on remote server when it’s necessary for helping.