Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

PostgreSQL ERROR: could not extend file ...: No space left on device (HINT: Check free disk space)

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

ERROR: could not extend file "base/16384/16806": No space left on device with HINT: Check free disk space. means a statement needed to add space to a table or index file and the file system that holds the file had none left. That statement fails; the page quoted below says a filled data disk "will not result in data corruption". The risk is wider: if the same file system also holds the write-ahead log (WAL), the server can panic and shut down. Find what filled the disk before you free anything.

What the error means

Reading src/backend/storage/smgr/md.c at tag REL_19_0, the storage code raises the message in these forms:

  • could not extend file "%s": %m with the hint Check free disk space. The %m stands for the errno text of the failed write. For a full file system that text is No space left on device, which the errno(3) manual page lists as ENOSPC.
  • could not extend file "%s": wrote only %d of %d bytes at block %u, raised with the error code ERRCODE_DISK_FULL and the same hint. The code raises this when the write returned fewer bytes than a block; a full file system is the likely reason; the source states none.
  • could not extend file "%s" with FileFallocate(): %m, with the same hint, when the extension uses a call that reserves space.

The PostgreSQL documentation page "Monitoring Disk Usage" states what a full disk does: "A filled data disk will not result in data corruption, but it might prevent useful activity from occurring. If the disk holding the WAL files grows full, database server panic and consequent shutdown might occur."

A disk quota produces the same failure. The page says "If your system supports per-user disk quotas, then the database will naturally be subject to whatever quota is placed on the user the server runs as. Exceeding the quota will have the same bad effects as running out of disk space entirely."

The same page points to tablespaces as a way out: "If you cannot free up additional space on the disk by deleting other things, you can move some of the database files to other file systems by making use of tablespaces."

Likely causes

Cause What you see How to confirm
The data file system is full because tables and indexes grew The error names a file under base/ and df shows no free space df -h on the data directory shows 100% use; the largest tables account for most of the data
WAL is filling the same file system The error may be followed by PANIC or shutdown messages The WAL directory size is large; PostgreSQL pg_wal Keeps Growing: Identify the Replication Slot Holding It and PostgreSQL WAL Archiving Failed: Find the Gap Before Retention Removes It cover why
Something outside PostgreSQL filled the disk (logs, dumps, backups, core files) The database directory is not the largest user du of the file system's top folders shows other large items
A quota on the server's operating system user Free space shows on df but writes fail The quota report for that user; see Linux Says No Space Left but Bytes Are Free: Check Inodes and Quotas
Free space is held by deleted files that a process still has open df shows full but du finds less Files Deleted but Linux Disk Space Is Still Used: Find Open File References covers the checks
No free inodes df -h shows free bytes but writes fail df -i shows 100% inode use

Prove the cause before changing anything

All of these only read.

1. Where is the data directory, and how full is its file system?

SHOW data_directory;

Run it at the psql prompt as a superuser. The SQL page says SHOW "will display the current setting of run-time parameters". Then, from the shell, using the path it printed (the path below is an example):

df -h /var/lib/postgresql/19/main
df -i /var/lib/postgresql/19/main

The GNU df manual says it "displays the amount of space available on the file system containing each file name argument", -h is "human-readable" and -i lists "inode information instead of block usage". A good result shows free space and free inodes. A bad result is 100% use of blocks or of inodes.

2. Which databases and tables are large?

SELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database;
SELECT relname, relpages FROM pg_class ORDER BY relpages DESC LIMIT 10;

The documentation says pg_database_size "Computes the total disk space used by the database with the specified name or OID" and pg_size_pretty converts a size in bytes to "a more easily human-readable format". The second query is the one the Monitoring Disk Usage page uses to "find your largest tables and indexes", with a LIMIT added. The same page says each page is "typically 8 kilobytes" and that relpages "is only updated by VACUUM, ANALYZE, and a few DDL commands such as CREATE INDEX".

3. How big is the WAL directory?

SELECT pg_size_pretty(sum(size)) FROM pg_ls_waldir();

The page says pg_ls_waldir() returns "the name, size, and last modification time" of each ordinary file in the WAL directory, and is "restricted to superusers and roles with privileges of the pg_monitor role by default". If this figure is a large part of the full file system, the cause is WAL growth, and PostgreSQL pg_wal Keeps Growing: Identify the Replication Slot Holding It and PostgreSQL WAL Archiving Failed: Find the Gap Before Retention Removes It cover the next steps.

4. What else is on the file system? Check the top-level folders of the same file system with du, and compare them with the database figures. If space is still used by files you deleted, see Files Deleted but Linux Disk Space Is Still Used: Find Open File References. If free bytes show but writes fail, see Linux Says No Space Left but Bytes Are Free: Check Inodes and Quotas.

Fix

The remedy depends on the cause. Do not delete files from the data directory or from a tablespace by hand. The tablespace page warns: "if you lose a tablespace (file deletion, disk failure, etc.), the database cluster might become unreadable or unable to start." PostgreSQL's documentation gives no procedure for removing WAL files by hand, so the cause that keeps the WAL is what needs fixing.

  • Space taken outside PostgreSQL (logs, dumps, old backups, core files): the PostgreSQL documentation gives no procedure. List what uses the space first, which only reads: du -xh --max-depth=1 /var/lib/postgresql (the du manual describes -x as "skip directories on different file systems"; the path is an example). Removing such files is a decision under your own retention rules, and deletion cannot be undone; df then shows whether space came back.
  • WAL growth is covered by the two WAL articles named in the table above.
  • A quota or an inode limit is covered by Linux Says No Space Left but Bytes Are Free: Check Inodes and Quotas.
  • A genuinely large table or index with no room to grow has two options: extending the volume, if your platform allows it, or moving the object to a file system that has room. The tablespace page says "if the partition or volume on which the cluster was initialized runs out of space and cannot be extended, a tablespace can be created on a different partition and used until the system can be reconfigured."

The step below moves one table. Indexes are not moved with it. The ALTER TABLE page says "Indexes on the table, if any, are not moved; but they can be moved separately with additional SET TABLESPACE commands." Choose the table from step 2.

First save where the table is now:

SELECT pg_relation_filepath('reports');
SELECT spcname, spcowner::regrole, pg_tablespace_location(oid) FROM pg_tablespace;

Copy both results to your notes. The first statement returns the file path relative to the data directory (the System Administration Functions page says "relative to the database cluster's data directory"). The Monitoring Disk Usage page shows a path such as base/16384/16806. The file layout page describes base as the "Subdirectory containing per-database subdirectories" and pg_tblspc as the "Subdirectory containing symbolic links to tablespaces". A saved path that starts with base/ therefore belongs to the cluster's own default location, and the back-out below returns it there; if the saved path already starts with pg_tblspc/, the table is already in a tablespace and the back-out does not apply.

Disruptive step: the next statements register a tablespace for the whole cluster and move the table reports into it. The ALTER TABLE page says an ACCESS EXCLUSIVE lock is acquired unless explicitly noted, and it notes nothing for SET TABLESPACE, so every query on reports probably waits until the move finishes. The page does not say how much WAL the move writes. The step is only safe if the file system that holds the WAL has free space for the move: if the WAL directory is on the full file system, the move can fail or add to the problem, so do not run it then.

The directory for the tablespace must already exist on the file system that has room, should be empty, and be owned by the PostgreSQL system user. CREATE TABLESPACE says it "will not create it". As a superuser, with your own name and path:

CREATE TABLESPACE bigdata LOCATION '/mnt/pgdata2/tablespace';
ALTER TABLE reports SET TABLESPACE bigdata;

To undo it: check that the table is now in the new tablespace, make sure the original file system has free space at least as large as the table, then move it back and drop the empty tablespace. The DROP TABLESPACE page says the tablespace "must be empty of all database objects before it can be dropped".

SELECT pg_relation_filepath('reports');
ALTER TABLE reports SET TABLESPACE pg_default;
DROP TABLESPACE bigdata;

Run the second statement only if the first printed a path that starts with pg_tblspc/ and the saved path started with base/. If the move did not happen (the first statement still printed a base/ path, as when the move failed), run only DROP TABLESPACE bigdata;, which works because the tablespace is still empty, and the directory created for it is then unused. The tablespace page names pg_default as the default tablespace of template1 and template0 and so of other databases unless overridden.

Example (illustrative): On db01, df -h shows the volume holding /var/lib/postgresql/19/main at 100%, and the log has ERROR: could not extend file "base/16384/16806": No space left on device with the hint Check free disk space. The WAL directory is a separate volume, /var/lib/postgresql/19/wal, with 40 GiB free, so pg_ls_waldir() and df show the WAL has room for the move. The relpages query shows reports at 4,980,736 pages. At 8 kB per page that is 4,980,736 x 8 = 39,845,888 kB, which is 39,845,888 / 1,048,576 = 38 GiB. A third volume, /mnt/pgdata2, has 200 GiB free. The engineer checks the WAL volume, saves the path base/16384/16806, creates the tablespace and moves reports while no one needs it. The data volume then has 38 GiB more free.

Confirm the fix

  1. The statement that failed now succeeds, with no new could not extend file line in the server log.
  2. df -h on the data directory shows free space, and df -i shows free inodes.
  3. SELECT pg_relation_filepath('reports'); starts with pg_tblspc/ after a move.
  4. The application's own errors have stopped.

What to watch afterwards

  • Free space on the data file system and on the WAL file system, with an alert well before 100%.
  • pg_database_size per database over time, and the WAL directory size.
  • Growth of the moved table: the new location now needs the same monitoring, and the tablespace cannot be "attached to a different database cluster or backed up individually", as the tablespace page warns, so include it in your backup scope.

Risks and limits

  • These commands have not been run or lab-tested.
  • The error message forms are a reading of the source at tag REL_19_0; wording can differ between versions.
  • The documentation pages are for PostgreSQL 19, the current version on 1 December 2026; check the page for your version.
  • A move into a tablespace places part of the cluster on another file system. The tablespace page says losing it "might" make the cluster unreadable.
  • With the disk completely full, even the first statement of the fix can fail. The first statement needs space freed outside the database; the listing step above helps find it.

Sources

  • Monitoring Disk Usage — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • Tablespaces — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • CREATE TABLESPACE — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • DROP TABLESPACE — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • ALTER TABLE — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • System Administration Functions — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • System Catalog Information Functions — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • SHOW — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • Database File Layout — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • File Locations — PostgreSQL 19 documentation, no date shown, accessed 1 December 2026
  • src/backend/storage/smgr/md.c, tag REL_19_0 — PostgreSQL source, no date shown, accessed 1 December 2026
  • du(1) — GNU coreutils 9.11, April 2026, accessed 1 December 2026
  • errno(3) — Linux man-pages 6.19, 2026-05-28, accessed 1 December 2026
  • df(1) — GNU coreutils 9.11, April 2026, accessed 1 December 2026