Fix MariaDB Errcode 28 /tmp Full: tmpdir Runbook

Resolve MariaDB and MySQL Errcode 28 (No space left on device) crashes. Diagnose tmpfs limits, cPanel securetmp partitions, systemd PrivateTmp sandboxing, and relocate tmpdir safely.

Fix MariaDB Errcode 28 /tmp Full: tmpdir Runbook
Immediate Diagnostic Fix

To fix MariaDB Errcode 28 (Got error 28 from storage engine) immediately: Create an isolated temporary directory on your primary NVMe volume (mkdir -p /var/lib/mysql_tmp && chown mysql:mysql /var/lib/mysql_tmp && chmod 0750 /var/lib/mysql_tmp), set tmpdir = /var/lib/mysql_tmp under [mysqld] in /etc/my.cnf.d/server.cnf, and run systemctl restart mariadb.[1] Avoid placing tmpdir inside /home or /usr, which default systemd hardening mounts read-only or inaccessible.[2]

Follow the diagnostic matrix, systemd unit inspection steps, tmpdir relocation procedure, and InnoDB/Aria memory-table tuning rules below to eliminate WordPress and WooCommerce Error 28 crashes permanently.


What Causes MariaDB Errcode 28 “No Space Left on Device” in /tmp?

OS error code 28 (ENOSPC) indicates that the filesystem backing MariaDB’s temporary directory exhausted either available disk blocks or free metadata inodes.[1][3] On busy WordPress and WooCommerce sites, unindexed ORDER BY, GROUP BY, ALTER TABLE, and multi-table JOIN queries exceed in-memory table limits and spill multi-gigabyte temporary files to disk.[4]

Unlike standard database tables stored in /var/lib/mysql, internal temporary files and online DDL sort buffers default to /tmp unless explicitly overridden.[1] When /tmp sits on a capped tmpfs RAM disk (typically limited to 50% of physical RAM in Linux) or a fixed 4 GB cPanel securetmp loopback mount (/usr/tmpDSK), a single schema migration or backup dump saturates /tmp and aborts queries with Errcode: 28.[3]

Workloads executing large reporting queries benefit from deploying on dedicated NVMe volumes through Nextgen Hosting Dedicated Servers rather than oversubscribed shared pools.


Diagnostic Matrix: Root Causes of MariaDB Error 28 vs. Remedies

Failure Symptom / Log Signature Underlying Filesystem Cause Diagnostic Command Permanent Remediation
/tmp at 100% Use% in df -h Small tmpfs RAM mount or 4 GB cPanel securetmp partition saturated df -hT /tmp /var/lib/mysql Relocate tmpdir to /var/lib/mysql_tmp on main NVMe mount[1]
df -h shows free GBs, but IUse% is 100% Millions of unlinked session/cache files exhausted filesystem inodes df -ih /tmp Purge orphaned temp files and enforce tmpreaper/systemd cleanup
df -h shows /tmp nearly empty during crash PrivateTmp=true namespace fills hidden systemd tmp mount, or deleted-but-open unlinked file lsof +L1 /tmp Inspect systemd mount namespace and clean active unlinked descriptors[2]
Errcode: 30 or Errcode: 13 after moving tmpdir mariadb.service sets ProtectSystem=full and ProtectHome=true[5] systemctl show mariadb -p ProtectSystem,ProtectHome Place tmpdir under /var/lib/ or whitelist via ReadWritePaths=[2]

Why Does df -h Show Free Space While MariaDB Fails With Errcode 28?

Administrators frequently run df -h, observe 80+ GB free on /, and assume the storage engine is malfunctioning. Three distinct Linux mechanisms explain why Errcode: 28 occurs despite abundant root filesystem space:

  1. Dedicated /tmp Mount Isolation: On cloud VPS and cPanel/WHM servers, /tmp is commonly mounted separately from /—either as an in-memory tmpfs volume capped at half of system RAM[3] or a cPanel /usr/tmpDSK loopback image. Queries writing 2.5 GB of sort buffers hit the /tmp ceiling instantly without touching /.
  2. Inode Exhaustion (df -i): Filesystems with fixed inode tables can run out of inode entries long before data blocks fill up. Check inode allocation immediately across both block space and metadata tables:
    df -hT /tmp /var/tmp /var/lib/mysql
    df -ih /tmp /var/tmp /var/lib/mysql
  3. Unlinked Deleted Open Files ((deleted)): When a PHP script or crashed MariaDB worker removes a temporary file while another process still holds an open file descriptor, Linux frees the directory entry (ls shows nothing) while keeping the disk blocks allocated until the file handle closes:
    lsof +L1 /tmp

Pitfall: Moving tmpdir to /home/mysql_tmp or /usr/local/tmp: Upstream MariaDB systemd unit definitions ship with ProtectSystem=full (mounting /usr, /boot, and /etc read-only) and ProtectHome=true (making /home and /root inaccessible to the daemon).[5] Relocating tmpdir under /home or /usr causes MariaDB to fail startup or abort queries with read-only / permission errors unless explicitly overridden.[2]


How Do You Relocate MariaDB tmpdir Without Breaking systemd Sandboxing?

Follow this 5-step terminal checklist to move MariaDB temporary sort space onto a writable, high-capacity /var/lib/ partition without relaxing core systemd security protections.

Step 1: Audit Active Systemd Unit Sandboxing and Current tmpdir

Inspect both the running database variable and the effective systemd unit restrictions:

mariadb -NBe "SHOW VARIABLES WHERE Variable_name IN ('tmpdir','slave_load_tmpdir','tmp_table_size','max_heap_table_size');"
systemctl show mariadb -p ProtectSystem,ProtectHome,PrivateTmp,ReadWritePaths

On AlmaLinux, Rocky Linux, and Ubuntu deployments, /var/lib/ remains writable under ProtectSystem=full, whereas /tmp is affected whenever PrivateTmp=true or /tmp uses a constrained mount.[2][5]

Step 2: Provision the Dedicated NVMe tmpdir Directory

Confirm /var/lib sits on your large NVMe storage volume, create the temporary directory, and enforce strict ownership:

mkdir -p /var/lib/mysql_tmp
chown mysql:mysql /var/lib/mysql_tmp
chmod 0750 /var/lib/mysql_tmp

On RHEL/AlmaLinux/Rocky systems enforcing SELinux, restore security contexts so the mysqld_t domain retains read/write access:

if command -v semanage >/dev/null 2>&1; then
  semanage fcontext -a -t mysqld_tmp_t "/var/lib/mysql_tmp(/.*)?"
  restorecon -Rv /var/lib/mysql_tmp
fi

Step 3: Update MariaDB Server Configuration

Edit your server configuration drop-in (commonly /etc/my.cnf.d/server.cnf on RHEL-family distributions, /etc/mysql/mariadb.conf.d/50-server.cnf on Ubuntu/Debian, or /etc/my.cnf on cPanel):

[mysqld]
tmpdir = /var/lib/mysql_tmp
slave_load_tmpdir = /var/lib/mysql_tmp

Configuring both tmpdir and slave_load_tmpdir ensures both primary query temp tables and replication LOAD DATA scratch files bypass /tmp.[1]

Step 4: Verify Path Access Under systemd Drop-In (If Using Non-/var Storage)

If your largest NVMe array is mounted outside /var (for example /mnt/nvme_tmp), declare an explicit systemd drop-in override rather than disabling ProtectSystem=full globally:[2]

systemctl edit mariadb

Add the exact allow-list directive:

[Service]
ReadWritePaths=/mnt/nvme_tmp

Step 5: Restart MariaDB and Confirm Active Runtime Values

Validate configuration syntax cleanly before restarting production database connections:

mariadbd --verbose --help >/dev/null && systemctl daemon-reload && systemctl restart mariadb
mariadb -NBe "SHOW VARIABLES WHERE Variable_name IN ('tmpdir','slave_load_tmpdir');"

Expected output confirms /var/lib/mysql_tmp across both variables with zero permission warnings in journalctl -u mariadb -n 30.


How Do tmp_table_size and max_heap_table_size Prevent /tmp Spillover?

Relocating tmpdir eliminates disk-full crashes, while sizing RAM buffer thresholds stops MariaDB from writing temporary tables to disk unnecessarily.[4] MariaDB evaluates the smaller of two variables before spilling an internal temporary table to on-disk storage:[1]

  • tmp_table_size: Maximum size of internal in-memory temporary tables (unless columns use TEXT or BLOB, which bypass memory tables immediately).[4]
  • max_heap_table_size: Caps user-created MEMORY tables and acts as the effective ceiling alongside tmp_table_size.[1]

Check your current on-disk temporary table ratio:

mariadb -NBe "SHOW GLOBAL STATUS WHERE Variable_name IN ('Created_tmp_disk_tables','Created_tmp_tables','Created_tmp_files');"

If Created_tmp_disk_tables exceeds 25% of Created_tmp_tables, align both variables evenly under [mysqld] (for example, 64M to 128M on 16 GB+ RAM servers):

[mysqld]
tmp_table_size = 64M
max_heap_table_size = 64M

Pro Tip: Never Over-Allocate tmp_table_size on High-Concurrency VPS Nodes: Unlike global caches such as innodb_buffer_pool_size, tmp_table_size is allocated per connection per query. Setting 512 MB across 100 concurrent WooCommerce checkout threads can trigger the Linux OOM killer. Keep per-thread limits conservative (32M–128M) and scale dedicated RAM on Nextgen Hosting Pakistan Dedicated Servers for heavy analytical workloads.


Frequently Asked Questions

Can I Fix MariaDB Errcode 28 Without Restarting the Database?

You cannot change tmpdir dynamically at runtime because tmpdir is a read-only startup variable in MariaDB.[1] However, you can relieve an immediate /tmp outage without restarting MariaDB by purging orphaned PHP session files or stale temporary exports inside /tmp and resizing tmp_table_size / max_heap_table_size dynamically with SET GLOBAL until a maintenance window permits systemctl restart mariadb.

Is Putting MariaDB tmpdir on tmpfs Safe for Performance?

Mounting tmpdir on tmpfs eliminates disk I/O latency for small sort files, but Linux tmpfs defaults to 50% of physical RAM and writes directly out of memory.[3] If an unindexed WordPress wp_postmeta query spills 8 GB to a 4 GB tmpfs, the query immediately aborts with Errcode: 28. Enterprise NVMe backing under /var/lib/mysql_tmp provides nearly RAM-like sequential IOPS with much higher fault tolerance.

Why Does InnoDB Need tmpdir If Buffer Pool Has Free Memory?

Even with tens of gigabytes free in innodb_buffer_pool_size, operations such as ALTER TABLE ... ADD INDEX, large GROUP BY sorts, and complex temporary tables containing TEXT/LONGTEXT WordPress columns create on-disk scratch files in tmpdir.[4]

How Does cPanel securetmp Trigger Errcode 28 on MariaDB?

cPanel’s /scripts/securetmp creates a fixed-size loopback image file (/usr/tmpDSK) mounted over /tmp with noexec,nosuid flags (often sized at just 4 GB on legacy or default installations). Rebuilding or importing a multi-gigabyte WooCommerce database quickly saturates /usr/tmpDSK, making tmpdir = /var/lib/mysql_tmp the cleanest permanent solution.

Eliminate Database Bottlenecks on Enterprise NVMe Hardware

Run MariaDB and high-traffic WordPress workloads on dedicated bare-metal NVMe storage arrays with unshared CPU cores, sub-10ms Pakistan routing, and 24/7 systems engineering support from Nextgen Hosting.

Explore Pakistan Dedicated Servers

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.

Sources & Official References
  1. MariaDB Documentation: Server System Variables (tmpdir, slave_load_tmpdir, tmp_table_size, max_heap_table_size). https://mariadb.com/kb/en/server-system-variables/#tmpdir
  2. systemd Manual Pages: systemd.exec Execution Environment Configuration (PrivateTmp=, ProtectSystem=, ReadWritePaths=). https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html
  3. The Linux Kernel Documentation: Tmpfs Filesystem Sizing and Behavior. https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html
  4. MariaDB Documentation: Internal Temporary Tables and Storage Engine Spillover. https://mariadb.com/kb/en/internal-temporary-tables/
  5. MariaDB Server 11.4 Upstream Source: mariadb.service.in Default Systemd Sandboxing Directives. https://raw.githubusercontent.com/MariaDB/server/11.4/support-files/mariadb.service.in

Disclaimer: This post is for informational and educational purposes only, accurate to the best of our knowledge at publication. It does not constitute advice. We do not guarantee accuracy or completeness and accept no liability for any decisions or losses resulting from reliance on this content.