How to migrate postgres database

on remote

ssh [email protected]
pg_dump the_db_name > the_backup.sql

on local computer

copy from remote to local: scp [email protected]:/dir/to/the_backup.sql /dir/to/copy/

switch to postgres user and create target db:

sudo -i -u postgres
createdb target_db_name
exit

import sql file into new db with postgres user(role):

sudo -u postgres psql target_db_name < the_backup.sql