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 -Fcper 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."
More on PostgreSQL
How do you set up PostgreSQL and log in with psql?BeginnerHow do you create a database, tables, users and query data in PostgreSQL?BeginnerHow do you back up and restore a PostgreSQL database?BeginnerWhat is PostgreSQL and why is it so popular?BeginnerHow is PostgreSQL organised: cluster, database, schema and table?BeginnerHow do you connect to PostgreSQL from the command line?Beginner