Backup a Database
sudo -u postgres --format=custom --file=<file name> <database name>
Restore a Database
First, create an empty database:
create database <database name> with encoding='utf-8';
Then grant all permissions to your user:
grant all on database <database name> to <user name>;
Then restore the dump:
sudo -u postgres pg_restore \ --schema=public \ --dbname=<database name> \ --no-owner \ --no-privileges \ --role=<user name> \ <file name>