Nextcloud Database Error After an Update: What to Check First
Restore Nextcloud access after an update by diagnosing SQL errors, checking database connectivity, and safely completing interrupted migrations.
If Nextcloud starts showing a “Database Error” exception after an update, check the underlying database error in nextcloud.log before changing any tables. Restore database connectivity first; if the update stopped partway through, finish it with occ upgrade and only then use the documented repair commands when the logs justify them.
The browser message is a symptom, not a diagnosis. Nextcloud may be unable to reach MySQL/MariaDB or PostgreSQL, the database account may no longer authenticate, or the application code and schema may be at different upgrade stages. Nextcloud’s official troubleshooting reference recommends matching the failing request ID to the server log.
config/config.php. The default log file is data/nextcloud.log, but customized deployments may log elsewhere.sudo tail -n 100 /var/www/nextcloud/data/nextcloud.log
sudo journalctl -u mariadb --since '30 minutes ago'
The second command applies only to a host running MariaDB under systemd; use the PostgreSQL service or container logs for other deployments. Search for the exception’s SQLSTATE code and the first database-related cause rather than relying on the final stack-trace line.
| Log clue | First useful check |
|---|---|
SQLSTATE[HY000] [2002] | Database process, hostname, port, socket path, or SQLite file access; the driver determines the interpretation. |
SQLSTATE[HY000] [1040] | MySQL/MariaDB connection exhaustion and active sessions. |
MySQL server has gone away | Database restarts, disconnections, resource pressure, and server logs. |
| Authentication or access denied | Database account, password, network access, and permissions. |
| Missing table, relation, or column | Whether the database upgrade completed and whether the installed code matches its schema. |
The first three examples are covered in Nextcloud’s documented common errors. A missing-table message is not permission to create the table manually: identify the precise migration failure first.
Before retrying migrations, preserve a restorable database backup together with Nextcloud’s configuration and data. The official backup procedure also includes custom apps and themes when present. Confirm that the backup belongs to the same point in time; a code-only backup cannot recover a partially changed database.
Commands below assume the common Debian/Ubuntu installation at /var/www/nextcloud, with www-data as its web-server account. Run occ as the appropriate HTTP user; package, Docker, Snap, AIO, and managed installations have different paths and execution methods. The occ command reference explains these requirements.
If the logs show connection refusal, an unreachable socket, or an unavailable server, first verify that the existing database service is running. These are alternative host-level checks, not a list to execute indiscriminately:
sudo systemctl status mariadb
sudo systemctl status postgresql
For a separate database server, also check DNS, firewall rules, the selected port, and network reachability from the Nextcloud application host or container. Inspect config/config.php for dbtype, dbhost, dbname, and dbuser. The configuration parameter reference explains hostnames, ports, and Unix socket syntax. Never paste dbpassword into public tickets or shell commands that expose it in history.
If a database password was rotated or credentials changed during deployment, correct that mismatch using your secret-management workflow. If the server reports too many connections, inspect active connections and the cause of connection accumulation before considering capacity changes. An index command will not cure a connection outage.
A simultaneous PHP or database-server upgrade can break a previously working installation. Compare the target Nextcloud release with its official system requirements and release notes rather than assuming every currently installed driver and server version remains supported. As of the checked Nextcloud 35 documentation, PHP 8.3–8.5 is supported; the accepted database versions are documented there separately. Earlier releases have different limits.
Also confirm the PHP database driver required by your selected engine is enabled in both the command-line and web PHP environments. Do not blindly downgrade the database server after a schema migration: restore only from a compatible, consistent backup plan.
Once the database is reachable and a backup is secured, switch to the Nextcloud installation directory and check its state:
cd /var/www/nextcloud
sudo -E -u www-data php occ status
If Nextcloud reports that an upgrade is pending or incomplete, follow the supported upgrade path for the installed source and target versions. For a conventional manual installation, run:
sudo -E -u www-data php occ upgrade
Do not interrupt the command or run concurrent upgrade processes. Read its output: a successful migration is different from a database connection exception. Nextcloud’s manual upgrade documentation explicitly recommends occ upgrade when the web-based process stalls, and maintenance:repair if the upgrade path needs repair:
sudo -E -u www-data php occ maintenance:repair
Use maintenance:repair after analyzing the failure; it is not a substitute for fixing bad credentials, a stopped database, or a genuinely incompatible runtime. If occ upgrade fails on a specific SQL migration, save the exact exception and seek a version-specific fix or restore the complete matched backup rather than experimenting with manual DDL.
Some migrations are intentionally deferred. On a functioning instance, the admin overview may ask for optional columns, indices, or primary keys. These commands provide a dry-run preview when supported by that version:
sudo -E -u www-data php occ db:add-missing-indices --dry-run
sudo -E -u www-data php occ db:add-missing-columns --dry-run
sudo -E -u www-data php occ db:add-missing-primary-keys --dry-run
Run the corresponding command without --dry-run only if the logged problem or administrative check calls for it and the proposed change has been reviewed. These maintenance operations can take time on large databases. Nextcloud 35 additionally documents db:schema:check; do not assume it exists on older branches. See the database command reference for version-specific behavior.
sudo -E -u www-data php occ status. Confirm the installed version matches the intended release, there is no upgrade required, and no new fatal SQL exception is produced.sudo -E -u www-data php occ maintenance:mode --off.nextcloud.log during these checks for fresh database exceptions.If the same database exception returns, stop repeated migrations and collect the request ID, SQLSTATE text, database-server log, version pair, and the failing occ output. That evidence determines whether the remaining issue is connectivity, incompatible software, or a specific failed migration. A successful login alone is not proof that every background task and database query works.
Restore Nextcloud access after an update by diagnosing SQL errors, checking database connectivity, and safely completing interrupted migrations.
Use Nextcloud’s OCC command to reset an administrator password from the server shell, with guidance for usernames, permissions, and external login providers.
Clear Nextcloud’s HSTS warning by setting the header at Apache, NGINX, or your TLS proxy, then verify the public HTTPS response safely.
Trace App Store installation failures to DNS, HTTPS, proxy, TLS, or configuration issues from the Nextcloud server itself.
Move thumbnail work to a controlled background schedule, trim unused preview sizes, and verify the queue without overwhelming your Nextcloud server.
Find the file, exclusion rule, connection issue, or client database state holding up Nextcloud sync, then verify uploads and downloads safely.
Find the PHP OPcache limit triggering Nextcloud’s warning, update the correct web PHP configuration, restart safely, and verify the result.
Compare built-in and Docker-based CODE, then connect Collabora Online to Nextcloud through a secure HTTPS reverse proxy.
Plan a reliable Nextcloud HA deployment with shared storage, Redis locking, quorum-aware MariaDB routing, and practical failover checks.
Configure and verify a reachable TURN relay for Nextcloud Talk when firewalls or restrictive NAT block direct call media.