Backup:
pg_dump -Fc -f a.dbbackup
Restore:
psql -c 'CREATE DATABASE b;'
pg_restore --dbname b a.dbbackup
Use the -U
, -h
etc options as required to connect to the correct host as the correct user with permissions to dump, create and restore the DB. See the docs for psql
, pg_dump
and pg_restore
for more info (they all take the same options for connection control).