To backup / dump entire DB (database cluster), use the following command:
pg_dumpall > outfile
or with username and gzipped
pg_dumpall -U postgres | gzip > db_backup.gz
-U usename – connect as specified database user
To restore from dump file “db_backup” use:
psql -f db_backup postgres