What is the difference between pg_dump and pg_dumpall?

IntermediateConceptPostgreSQL
Answer

Short answer

pg_dump backs up one database (its tables, data, schemas, functions). pg_dumpall backs up the whole cluster — every database plus global objects like roles and tablespaces, which pg_dump doesn't include.

Examples

pg_dump -U postgres -Fc shop > shop.dump              # one database, custom format
pg_dumpall -U postgres > cluster.sql                  # everything, plain SQL
pg_dumpall -U postgres --globals-only > globals.sql   # just roles + tablespaces

A common gotcha

You restore shop.dump on a new server and get errors like role "shop_app" does not exist. That's because roles aren't in pg_dump. Fix: restore globals.sql first, or use --no-owner --no-privileges on restore.

Typical backup strategy

  • pg_dumpall --globals-only (small) + pg_dump -Fc per database (flexible restores).

What to say in the interview

"pg_dump handles a single database; pg_dumpall covers all databases and cluster-wide objects like roles. I usually take globals-only with pg_dumpall plus custom-format pg_dump per database, so roles exist before restoring."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL