Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

The Postgres container cannot write postmaster.pid because Docker is out of disk

ErrorFATAL: could not write lock file "postmaster.pid": No space left on device

Short answer

The error means the filesystem Docker stores the container on is full, not necessarily your whole disk. Run docker system df to see what takes the space, remove unused images, containers and build cache, and on Docker Desktop raise the disk usage limit if it is reached.

  • Applies to postgres Docker image 17 and 18, Docker Engine 28, Docker Desktop 4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Measure Docker's own usage and the host disk. The reclaimable column shows what can be removed safely.

    docker system df
    df -h
  2. 2Match what you see, then jump to its fix

    1. 1docker system df shows a large RECLAIMABLE number.Unused images, containers and build cache fill Docker's storageFix
    2. 2The host disk has free space, but Docker's own storage is at its maximum.Docker Desktop's disk usage limit is reachedFix
    3. 3docker system df -v lists the Postgres volume as the biggest item.The database itself has grown to fill its volumeFix

What does the error look like?

  • FATAL: could not write lock file "postmaster.pid": No space left on device
  • could not write to file ... No space left on device

Cause 1 of 3

Unused images, containers and build cache fill Docker's storage

1Check

Old images, stopped containers and build cache pile up. Volumes are listed separately.

docker system df -v

2Fix

Prune what is unused. This does not touch volumes unless you add --volumes, so do not add it for a database host.

docker system prune

3Verify

Free space grows, and the container starts.

docker system df
docker compose up -d db

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

Docker Desktop's disk usage limit is reached

1Check

Docker Desktop on Mac, Windows (Hyper-V) and Linux lets the engine use only a set amount of disk.

docker system df

2Fix

Open Settings, then Resources, then Advanced, and raise the Disk usage limit after cleaning.

# Docker Desktop > Settings > Resources > Advanced > Disk usage limit

3Verify

Restart Docker Desktop and start the database container.

docker compose up -d db && docker compose logs db | tail -n 5

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The database itself has grown to fill its volume

1Check

Look at the volume size, then at which tables are large.

docker system df -v
docker compose exec db psql -U postgres -c "select pg_size_pretty(pg_database_size(current_database()))"

2Fix

Delete data you no longer need, then give the volume more room (a bigger disk limit or host disk). Never delete files inside the data directory by hand.

docker compose exec db psql -U postgres -c 'VACUUM'

3Verify

Database size and free space look healthy.

docker system df

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Prune unused images and build cache on a schedule on build machines.
  • Alert on disk usage before it reaches 90 percent.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.