$ pg_dumpall --clean -U <user> -f backup.sql
$ psql -U <user> -f backup.sql- A PostgreSQL user with administrative privileges is required.
- Using
pg_dumpinstead ofpg_dumpallresults in role privileges being reset to nothing. - If you forget the
--clean/-cflag topg_dumpall, then the backup SQL script will not be idempotent, and will collide and error with any existing databases. - Using
pg_restoreinstead ofpsqlwill reject the plain SQL backup format.