What are the pg_dump output formats and which should you use?

IntermediateConceptPostgreSQL
Answer

Short answer

pg_dump can write plain SQL (-Fp), custom (-Fc), directory (-Fd) or tar (-Ft). Custom format is the usual choice: compressed, and pg_restore can restore selectively and in parallel. Directory format adds parallel dumping for large databases.

Comparison

Format Flag Restore with Compressed Parallel dump Selective restore
Plain SQL -Fp (default) psql -f Optional (pipe to gzip) No No (edit the file)
Custom -Fc pg_restore Yes No Yes
Directory -Fd pg_restore Yes Yes (-j) Yes
Tar -Ft pg_restore No No Yes

Examples

pg_dump -Fc -U postgres shop -f shop.dump
pg_restore -l shop.dump                                  # list contents
pg_restore -d shop_new -t orders shop.dump               # restore one table
pg_dump -Fd -j 8 -U postgres bigdb -f /backups/bigdb     # 8 parallel jobs
pg_restore -j 8 -d bigdb_new /backups/bigdb

What to say in the interview

"Custom format for most backups — compressed with selective restore through pg_restore. Directory format with -j for big databases to dump and restore in parallel. Plain SQL when I need a human-readable file."

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

More on PostgreSQL