ownCloud stores nearly everything in its MySQL/MariaDB database: file metadata, share records, activity logs, authentication tokens, and background job state. On shared hosting, where you control the database only through phpMyAdmin and the ownCloud occ command (via cron or a terminal provided inside DirectAdmin), the database is often the first component to slow down. A sync client hammering the WebDAV endpoint, a filescan that never finished, or an activity log growing unchecked for a year can all turn a responsive instance into one that times out on login. This article walks through finding which tables are actually bloated, why queries slow down, how to repair corrupted tables, and how to restore the indexes ownCloud expects \u2014 all from an unprivileged hosting account.

Finding where the bloat actually lives

Before changing anything, identify which tables are consuming space and row count. Open DirectAdmin \u2192 Account Manager \u2192 phpMyAdmin, select your ownCloud database, and click the Structure tab. Sort by the Size column. On a healthy small-to-medium instance you expect oc_filecache to be the largest table, since it holds one row per file and folder per user. Problems usually surface in three other tables: oc_activity and oc_activity_mq (the activity stream and its mail queue), oc_authtoken (one row per sync-client session, which accumulates fast with mobile apps), and oc_jobs or oc_filecache_extended depending on your version.

To quantify the problem precisely, run a query in the phpMyAdmin SQL tab against the information_schema view, which read-only hosting users are allowed to query:

SELECT table_name,
       table_rows,
       ROUND(data_length/1024/1024, 1) AS data_mb,
       ROUND(index_length/1024/1024, 1) AS index_mb,
       ROUND(data_free/1024/1024, 1) AS free_mb
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC
LIMIT 15;

The free_mb column is the giveaway for fragmentation. A table showing hundreds of megabytes of data_free has had many rows deleted without the space being reclaimed \u2014 common after a large file deletion or a purged activity log. A high table_rows count on oc_authtoken (tens of thousands) usually means expired tokens were never cleaned. If oc_filecache row count vastly exceeds the number of files you actually store, you likely have orphaned entries from deleted users or from a storage that was unmounted without a cleanup.

Check the activity log growth directly, since it is the single most common cause of a swollen ownCloud database:

SELECT COUNT(*) AS rows, MIN(FROM_UNIXTIME(timestamp)) AS oldest
FROM oc_activity;

If the oldest entry is years old and the count is in the hundreds of thousands, that table alone can slow the admin dashboard and the activity app to a crawl.

Reclaiming space and pruning unnecessary data

ownCloud ships maintenance routines that are safer than hand-deleting rows, because they respect foreign-key relationships and application state. If your hosting plan exposes a terminal (DirectAdmin may offer one, or you can run commands through a cron job), the occ tool is the correct interface. From your ownCloud document root, usually /home/USERNAME/domains/example.com/public_html, the relevant commands are:

php occ db:add-missing-indices
php occ db:add-missing-columns
php occ db:convert-filecache-bigint
php occ app:disable activity   # only if you no longer need the log

Expired authentication tokens and stale cron job locks are cleaned automatically by the background jobs, but only if cron is actually running. In ownCloud AdminCP \u2192 Settings \u2192 Admin \u2192 General, confirm the background job mode is set to Cron and that the last run timestamp is recent. On shared hosting the correct scheduler is a DirectAdmin cron entry under Advanced Features \u2192 Cron Jobs calling php -f /home/USERNAME/domains/example.com/public_html/cron.php every 15 minutes. If that job has been failing, maintenance never happens and tables grow indefinitely.

When you must prune the activity log and occ is unavailable, do it in phpMyAdmin with a bounded delete rather than a full TRUNCATE, so you keep recent history. Always export the table first via the Export tab:

DELETE FROM oc_activity
WHERE timestamp < UNIX_TIMESTAMP(NOW() - INTERVAL 6 MONTH)
LIMIT 50000;

The LIMIT keeps each statement short so the shared database server does not kill the query for exceeding execution time. Repeat until no rows remain. After large deletions, reclaim the fragmented space with:

OPTIMIZE TABLE oc_activity, oc_authtoken, oc_filecache;

For InnoDB tables, OPTIMIZE is mapped to a table rebuild, which releases the data_free you saw earlier. This can run for a while on large tables, so do it during low-traffic hours. Never attempt to drop or alter the oc_* schema beyond what occ or OPTIMIZE performs \u2014 removing columns or indexes that ownCloud expects will break the application on the next request.

Repairing broken tables and restoring indexes

Corruption shows up as login failures, blank pages, or an error_log full of \u201cTable is marked as crashed\u201d or \u201cIncorrect key file for table\u201d messages. Your ownCloud log lives at data/owncloud.log inside the data directory, and the PHP-level errors land in the per-domain error_log you can open through DirectAdmin \u2192 File Manager. In phpMyAdmin, select the suspect table, open the Operations tab, and use the Check table and Repair table functions. Note that REPAIR TABLE only works on MyISAM/Aria tables; modern ownCloud uses InnoDB, where true repair requires restoring from a backup. This is why the rollback-ready backup procedure matters \u2014 if an InnoDB table is genuinely corrupted, your clean path is to drop it and re-import from your most recent export.

Missing or inefficient indexes produce the slowest symptom: the instance works but every folder listing and share lookup takes seconds. ownCloud ships a self-check for this. Run php occ db:add-missing-indices, which adds indexes the schema expects on tables like oc_share, oc_filecache, and oc_cards_properties. The AdminCP mirrors this: Settings \u2192 Admin \u2192 General displays a Security & setup warnings panel that explicitly lists any missing indices and the exact command to fix them. To confirm an index exists before and after, inspect the table in the SQL tab:

SHOW INDEX FROM oc_filecache;
EXPLAIN SELECT * FROM oc_filecache WHERE storage = 1 AND path_hash = 'abc';

If EXPLAIN reports a full table scan (type: ALL) on a large oc_filecache, the index is missing or unused. After adding indices, the same query should show type: ref or eq_ref.

Connection errors and keeping the database healthy

Intermittent \u201cCan\u2019t connect to local MySQL server\u201d or \u201cToo many connections\u201d errors on shared hosting are rarely about the database being down \u2014 they reflect your account hitting its concurrent connection limit, usually because sync clients and a stuck filescan all opened connections at once. You cannot raise server limits, but you can reduce pressure. Verify the datastore credentials in config/config.php (open it read-only in File Manager) match the DirectAdmin MySQL user, and confirm dbhost is localhost rather than a stale remote hostname. If you recently changed the MySQL password in DirectAdmin, the old one in config.php will cause immediate connection failures.

To stop runaway connections, enable maintenance mode during cleanup with php occ maintenance:mode --on, which blocks new client sessions while you optimize tables. Cap PHP memory and execution so a single bloated query cannot starve your account by adding a .user.ini in the document root:

memory_limit = 512M
max_execution_time = 300
default_socket_timeout = 60

Set your PHP version and extensions through DirectAdmin \u2192 PHP Selector / MultiPHP Manager, ensuring pdo_mysql is enabled \u2014 a missing PDO extension after a PHP version switch is a frequent cause of sudden database connection failures. The same diagnostic discipline of reading the local error_log applies to any PHP app; the approach in our guide to diagnosing Matomo white screens and HTTP 500s translates directly to tracing an ownCloud fatal error back to its database root cause. With a running cron, pruned activity logs, defragmented tables, and the full index set in place, an ownCloud instance on shared hosting stays responsive well into the hundreds of thousands of files.