Skip to content

Disk Usage

This page explains what occupies the disk of a Managed PostgreSQL service besides the rows you store, and how each part is measured and kept in check.

The Disk Comes with the Plan

Each plan has a fixed disk size, for example 80 GiB on startup-4 and 8 GiB on hobbyist-2. List the plans with exo dbaas type show pg --plans, and read the size of a service, in bytes, with:

exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"disk-size"'

The share in use is the disk_usage metric, a percentage, returned by exo dbaas metrics SERVICE_NAME -z ZONE --period day. To get more disk, move to a larger plan, see Change the service plan.

What Is on the Disk

ConsumerWhat it isGrows when
Tables and TOASTRows, with large values compressed and stored out of lineYou store data
IndexesOne separate structure per indexYou add indexes or rows
WALThe write-ahead log, kept until archived and no longer neededYou write, or a replication slot holds it
Dead rowsOld row versions left by UPDATE and DELETEVacuum does not keep up, or a long transaction prevents cleanup
Temporary filesSorts, hashes and index builds that do not fit in memoryLarge queries or index builds run

Only the first two are your data. The size functions such as pg_database_size() count tables, indexes and dead rows, not WAL or temporary files, so the sum of your database sizes is always lower than what the disk metric shows. How to measure each relation is described in Check object sizes.

WAL

Every change is written to the WAL before it reaches the table files. The service archives WAL continuously for backups and point-in-time recovery, and keeps a part of it on disk:

SHOW wal_keep_size;
SHOW max_wal_size;
SHOW archive_timeout;

wal_keep_size and max_wal_size depend on the plan, so a part of the disk is always taken by WAL, even on a quiet service. archive_timeout (5 minutes) makes PostgreSQL switch to a new WAL segment at least that often so that it can be archived.

Replication Slots

A replication slot guarantees that the WAL its consumer still needs stays on disk. When the consumer stops, for example a logical replication subscriber or a CDC tool that was switched off, the slot keeps every new WAL segment and disk usage grows independently of your data. A slot left behind by a consumer that is gone is one of the main causes of unexplained disk growth.

The pghoard_local slot belongs to the platform’s backup and WAL archiver; it is always present and must not be dropped. The number of slots is limited by max_replication_slots, 20 by default, configurable from 8 to 256. The WAL one slot may keep is unlimited by default and can be capped with max_slot_wal_keep_size: a slot over the limit is invalidated, which breaks that replication but protects the disk.

To list slots, see how much WAL each one retains, and set the cap, see Prevent a full disk.

Temporary Files

A sort, hash join or hash aggregate that needs more than work_mem writes temporary files, and so does an index build that needs more than maintenance_work_mem. They are deleted when the operation ends, but while it runs, a single query can write gigabytes. temp_file_limit is -1 on a new service, which means no limit. Setting it turns a disk filled by one query into one failed query. See Prevent a full disk.

Dead Rows and Bloat

PostgreSQL never overwrites a row: UPDATE writes a new version and DELETE marks the old one dead. VACUUM, run automatically by autovacuum, makes the space of dead rows reusable by the same table, but in general does not give it back to the file system. A table that was heavily updated or emptied with DELETE therefore keeps its size.

Space returns to the disk only when files are removed or rewritten: TRUNCATE, DROP, REINDEX, VACUUM FULL or pg_repack. The last three write a complete new copy before removing the old one, so they need free space about the size of what they rebuild.

Plan Ahead

Several of the operations that free space need free space, and a plan change takes time. Alert on the disk metric well before it is full, and choose a plan with room for WAL, temporary files, dead rows and index rebuilds in addition to the data.

Related Pages

Last updated on