---
title: "Monitor pg_dump backups with CronMissed"
url: "https://cronmissed.com/guides/pg-dump.md"
canonical_url: "https://cronmissed.com/guides/pg-dump"
last_updated: "2026-10-22"
type: "how-to"
summary: "A pg_dump pipeline can exit 0 after a failed dump if the shell hides the status. Use pipefail and ping CronMissed with the real exit status."
related: ["https://cronmissed.com/guides.md", "https://cronmissed.com/guides/restic.md", "https://cronmissed.com/guides/borg.md", "https://cronmissed.com/guides/rsync.md", "https://cronmissed.com/snippets/shell.md"]
---

# Monitor pg_dump backups with CronMissed

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

A pg_dump pipeline can exit 0 after a failed dump if the shell hides the status. Use pipefail and ping CronMissed with the real exit status.

pg_dump returns a non-zero exit status when a dump fails, but a pipe to gzip or an upload command can hide it. The wrapper below checks the status of the whole pipeline and pings CronMissed with the real result.

## How can a scheduled job fail silently on pg_dump database backups?

- In a shell pipeline such as pg_dump | gzip > file, the exit status is that of the last command unless pipefail is set. A failed dump can then look like a success.
- pg_dump makes a consistent export while the database is in use and does not block readers or writers, so a dump can run for a long time without anyone noticing it is late.
- The PostgreSQL manual says that, except in simple cases, pg_dump is generally not the right choice for regular backups of production databases, and points to the backup chapter for the alternatives.
- A dump only holds one database. Roles and tablespaces need pg_dumpall.
- A custom-format dump (--format=custom) can be inspected and restored selectively with pg_restore, but nobody learns it is broken until a restore is tried.

## What are the limits of pg_dump database backups?

| Limit | What the documentation says |
| --- | --- |
| Scope | One database per pg_dump; pg_dumpall covers a cluster and its global objects. |
| Consistency | Consistent export even with concurrent use. |
| Locking | Does not block other users; parallel dumps take shared locks on the objects they will dump. |
| Formats | Plain SQL script or archive formats; custom and directory formats work with pg_restore. |
| Parallel dump | The --jobs option needs synchronized snapshots on the server. |

## How do you add a CronMissed ping to pg_dump database backups?

This wrapper reports the start, runs the dump, checks that the file is not empty, and sends the exit status. The `--format=custom` file is easy to restore selectively.

```
#!/bin/sh
# pg_dump backup: reports the start, the exit status and the last 100 kB of output to CronMissed.
PING_URL="https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10"
curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null "$PING_URL/start"
output=$(pg_dump --format=custom --file="/var/backups/db-$(date +%Y-%m-%d).dump" "$DATABASE_URL" 2>&1)
status=$?
printf '%s\n' "$output" | tail -c 100000 | curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null --data-binary @- "$PING_URL/$status"
exit $status
```

If you pipe the dump through other tools, enable `pipefail` so the status covers the whole pipeline.

```bash
set -o pipefail
pg_dump --format=custom "$DATABASE_URL" | gzip > "/var/backups/db-$(date +%F).dump.gz"
status=$?
```

## Which check settings fit pg_dump database backups?

Create a cron check with the dump schedule and a grace set from the longest dump you have seen; a database that grows will need the number raised. Add a second check for the restore test you run each week or month. A dump that exists but cannot be restored is the failure the first check cannot see.

## How do you confirm the check works?

1. Run the script by hand and confirm the start and exit pings and a non-empty file.
2. Use a wrong password in a test and confirm the status is non-zero and the check goes down.
3. Restore the dump into a scratch database with pg_restore at least once, and keep that as a scheduled job with its own check.

## Questions

### Is pg_dump enough as a backup strategy?

The PostgreSQL documentation says it often is not for production, and refers to continuous archiving. CronMissed watches whichever tool you choose, whether it is pg_dump, a base backup or a managed snapshot job.

### Why check that the file is not empty?

Some failures leave a zero-byte file and still return from the next command normally. A size check in the script is a cheap second line of defense.

## Sources

- [PostgreSQL documentation: pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html), read 22 October 2026

## Related pages

- [restic backups](https://cronmissed.com/guides/restic.md)
- [BorgBackup](https://cronmissed.com/guides/borg.md)
- [rsync backups](https://cronmissed.com/guides/rsync.md)
- [Shell and curl](https://cronmissed.com/snippets/shell.md)

## Related

- [Monitor cron jobs on every platform: 24 guides](https://cronmissed.com/guides.md)
- [Monitor restic backups with exit codes](https://cronmissed.com/guides/restic.md)
- [Monitor BorgBackup runs with return codes](https://cronmissed.com/guides/borg.md)
- [Monitor rsync jobs by exit value](https://cronmissed.com/guides/rsync.md)
- [Ping CronMissed from a shell script with curl](https://cronmissed.com/snippets/shell.md)
