---
title: "Prevent a Full Disk on Managed PostgreSQL"
description: "Watch the disk usage of a Managed PostgreSQL service, find what fills it, cap replication slots and temporary files, and free space."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/prevent-full-disk/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# Prevent a Full Disk on Managed PostgreSQL

Watch the disk usage of a Managed PostgreSQL service, find what fills it, put limits on the two consumers that can grow without bound, and free space before the disk runs out.

What occupies the disk, and why its usage differs from the size of your tables, is explained in
[Disk usage](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/disk-usage/index.md).

## Watch Disk Usage

The disk size comes with the plan. Read it, in bytes, from the service description:

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

Parameters:

- `SERVICE_NAME`: name of the Managed PostgreSQL service, for example `my-postgresql`.
- `ZONE`: zone the service runs in, for example `ch-gva-2`.

`exo dbaas metrics` returns the service metrics as JSON. `disk_usage` is the percentage of the disk
in use, sampled per node:

```bash
exo dbaas metrics SERVICE_NAME -z ZONE --period hour | jq '.disk_usage.data.rows[-1]'
```

```text
[
  "2026-11-10T13:58:30",
  19.950714681615757
]
```

`--period` accepts `hour`, `day`, `week`, `month` and `year`. To alert on it, forward the metrics
to a monitoring system, see
[Monitor your service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md) and
[External integrations](https://community.exoscale.com/product/dbaas/how-to/external-integrations/index.md).

Alert early, for example at 70 to 80%: freeing space or moving to a larger plan takes time, and
several of the operations that free space need free space themselves.

## Find What Uses the Space

Connect with [psql](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/connect-with-psql/index.md) and work
down from databases to relations:

```sql
SELECT datname,
       pg_size_pretty(pg_database_size(datname)) AS size
FROM pg_database
ORDER BY pg_database_size(datname) DESC;
```

The largest relations of the current database, indexes and TOAST included:

```sql
SELECT c.oid::regclass                               AS relation,
       c.relkind,
       pg_size_pretty(pg_total_relation_size(c.oid)) AS total,
       pg_size_pretty(pg_table_size(c.oid))          AS table_and_toast,
       pg_size_pretty(pg_indexes_size(c.oid))        AS indexes
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r', 'm')
  AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')
ORDER BY pg_total_relation_size(c.oid) DESC
LIMIT 20;
```

For partitioned tables, unused indexes and dead rows, see
[Check object sizes](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/check-object-sizes/index.md).

WAL and temporary files are not visible this way: `pg_ls_waldir()` and `pg_ls_tmpdir()` are denied
to `avnadmin`. Check the replication slots and temporary file statistics below instead.

## Find WAL Held Back by a Replication Slot

A replication slot keeps every WAL segment its consumer has not confirmed yet. A slot whose
consumer has stopped, such as a logical replication subscriber or a CDC connector that was
switched off, keeps WAL growing on the disk, even when you write little data:

```sql
SELECT slot_name,
       slot_type,
       active,
       wal_status,
       pg_size_pretty(pg_current_wal_lsn() - restart_lsn) AS retained_wal
FROM pg_replication_slots
ORDER BY pg_current_wal_lsn() - restart_lsn DESC NULLS LAST;
```

```text
   slot_name   | slot_type | active | wal_status | retained_wal
---------------+-----------+--------+------------+--------------
 orders_cdc    | logical   | f      | extended   | 1015 MB
 pghoard_local | physical  | t      | reserved   | 44 MB
```

`pghoard_local` belongs to the platform's backup and WAL archiver: never drop it. A slot with
`active = f` whose `retained_wal` keeps growing has no consumer. Reconnect the consumer, or drop the
slot once you are sure nothing needs it:

```sql
SELECT pg_drop_replication_slot('SLOT_NAME');
```

Parameters:

- `SLOT_NAME`: the `slot_name` from the query above.

The space is released when PostgreSQL next removes old WAL segments, at a checkpoint.
`avnadmin` cannot run `CHECKPOINT` itself.

### Cap the WAL a Slot Can Keep

`max_slot_wal_keep_size` limits how much WAL, in MB, a slot may retain. The default `-1` means no
limit. It is nested in the `wal` object of `--pg-settings` and applies without a restart:

```bash
exo dbaas update SERVICE_NAME -z ZONE -f \
  --pg-settings '{"wal":{"max_slot_wal_keep_size":10240}}'
```

Parameters:

- `max_slot_wal_keep_size`: MB of WAL a slot may retain, `-1` to `2147483647`. The example allows
  10 GiB.

A slot that goes over the limit is invalidated at the next checkpoint. Its `wal_status` becomes
`lost`, and its consumer can no longer use it:

```text
ERROR:  can no longer access replication slot "orders_cdc"
DETAIL:  This replication slot has been invalidated due to "wal_removed".
```

The replication must then be set up again from scratch. That is usually better than a full disk,
but choose a limit that covers the longest consumer outage you want to survive. Sending
`max_slot_wal_keep_size` at the top level of `--pg-settings` instead of inside `wal` is rejected
with `Additional property max_slot_wal_keep_size is not allowed`.

## Limit Temporary Files

A sort or hash that does not fit in `work_mem` writes temporary files, and so do index builds. A
single query can write gigabytes. See how much each database has written since statistics were
reset:

```sql
SELECT datname, temp_files, pg_size_pretty(temp_bytes) AS temp_written
FROM pg_stat_database
WHERE temp_files > 0
ORDER BY temp_bytes DESC;
```

`temp_file_limit` caps the temporary space each server process may use; a parallel worker counts
as a separate process. The default `-1` means unlimited. `log_temp_files` logs each temporary file
above a size, with the statement that wrote it. Both have `superuser` context, so set them on the
service:

```bash
exo dbaas update SERVICE_NAME -z ZONE -f \
  --pg-settings '{"temp_file_limit":5242880,"log_temp_files":1024}'
```

Parameters:

- `temp_file_limit`: KiB, `-1` for unlimited. The example allows 5 GiB.
- `log_temp_files`: KiB, `-1` disables the logging. A new service logs files above `100` kB.

A process that reaches the limit fails with:

```text
ERROR:  temporary file size exceeds "temp_file_limit" (5242880kB)
```

`CREATE INDEX` and `REINDEX` count too: with a low limit, an index build on a large table fails
and, with `CONCURRENTLY`, leaves an invalid index behind.

## Free Space

Start with what returns space right away.

`TRUNCATE`, `DROP TABLE` and `DROP INDEX` remove files immediately:

```sql
TRUNCATE TABLE public.events_staging;
DROP TABLE public.import_2024;
DROP INDEX CONCURRENTLY public.orders_status_idx;
```

Drop replication slots that nobody uses, as described above. On a disk filled by WAL, this is often
the largest gain.

`DELETE` does not shrink files: it leaves dead rows that `VACUUM` makes reusable by the same
table. Only rewriting the table returns the space, with `VACUUM FULL` (which blocks the table for
the whole run) or
[pg_repack](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/use-pg-repack/index.md). Both build a
complete copy before dropping the old one, so they need free space about the size of the table and
its indexes: they are not an option once the disk is almost full.

When the data genuinely does not fit, move to a plan with a larger disk. See
[Change the service plan](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/change-the-plan/index.md) and
[Scale a service](https://community.exoscale.com/product/dbaas/how-to/scaling/index.md). Leave room for WAL, temporary files, bloat and
index rebuilds on top of the data.

Contact Exoscale support if the service no longer accepts writes and you cannot free space.

## Related Pages

- [Disk usage](https://community.exoscale.com/product/dbaas/service-specific/postgresql/overview/disk-usage/index.md)
- [Check object sizes](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/check-object-sizes/index.md)
- [Monitor your service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md)
- [Set up logical replication](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/set-up-logical-replication/index.md)
- [Use pg_repack](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/use-pg-repack/index.md)
- [Change the service plan](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/change-the-plan/index.md)

