Change to postgres
user
sudo -i -u postgres
Backup
pg_dump -U [username] [db_name] > [backup_name]
Restore
psql [db_name] < [backup_file]
Login with explicit pass and hostname
psql -U youser -h 127.0.0.1 -W
Change to postgres
user
sudo -i -u postgres
Backup
pg_dump -U [username] [db_name] > [backup_name]
Restore
psql [db_name] < [backup_file]
Login with explicit pass and hostname
psql -U youser -h 127.0.0.1 -W