This is more a note to myself because I always have to look this up.

pg_dump -Fc -h host -U user database > ~/tmp/database.dump
pg_restore -Fc -d target_database -O -x -1 -c ~/tmp/database.dump
  • -Fc defines the PG custom format for the dump
  • -O disables some owner set stuff
  • -x disables the access right stuff
  • -1 ensures that everything is done in one transaction
  • -c removes any tables which should be created by the dump