---
source: https://iinventedlight.com/library/notes/postgres-pg-dump.md
title: "Backing up PostgreSQL with pg_dump"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PostgreSQL License; prose restates cited source lines"
attribution: "Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: 25.1. SQL Dump, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: pg_dump, PostgreSQL License."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: PostgreSQL"
tags: ['postgresql', 'backup', 'pg-dump', 'pg-restore']
sources:
  - id: S1
    title: "PostgreSQL: Documentation: 18: 25.1. SQL Dump"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/backup-dump.html
    accessed: 2026-11-04
    license: "PostgreSQL License"
  - id: S2
    title: "PostgreSQL: Documentation: 18: pg_dump"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/app-pgdump.html
    accessed: 2026-11-04
    license: "PostgreSQL License"
---
# Backing up PostgreSQL with pg_dump

**Answer:** Use the custom (`-Fc`) or directory (`-Fd`) format and restore with `pg_restore`, which can run in parallel. Use `pg_dumpall --globals-only` for roles and tablespaces, which pg_dump does not include.

```bash
pg_dump -Fc -d shop -f shop.dump
pg_dumpall --globals-only > globals.sql

createdb shop_restored
pg_restore -j 4 -d shop_restored shop.dump
```

## Formats

| Format | Restore with |
|---|---|
| plain SQL (default) | `psql` |
| custom `-Fc` | `pg_restore` |
| directory `-Fd` | `pg_restore`, parallel dump with `-j` |
| tar `-Ft` | `pg_restore` |

## Useful options

- `--data-only` or `--schema-only`.
- `-t table` to dump specific tables.
- If no database is given, `PGDATABASE` or the user name is used.

## Claims
- id: C1
  claim: Non-text dumps should be restored using pg_restore.
  source: S1
  evidence: "Non-text file dumps should be restored using the pg_restore utility."
- id: C2
  claim: Cluster-wide data can be dumped with pg_dumpall --globals-only.
  source: S1
  evidence: "Cluster-wide data can be dumped alone using the pg_dumpall --globals-only option."
- id: C3
  claim: pg_restore -j restores a dump in parallel.
  source: S1
  evidence: "You can use pg_restore -j to restore a dump in parallel."
- id: C4
  claim: pg_dump only dumps a single database.
  source: S2
  evidence: "pg_dump only dumps a single database."
- id: C5
  claim: Examine pg_dump output for warnings on standard error.
  source: S2
  evidence: "one should examine the output for any warnings (printed on standard error)"

## Sources
- [S1] PostgreSQL: Documentation: 18: 25.1. SQL Dump. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/backup-dump.html . License: PostgreSQL License. Accessed 2026-11-04.
- [S2] PostgreSQL: Documentation: 18: pg_dump. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/app-pgdump.html . License: PostgreSQL License. Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
