Skip to content

Instantly share code, notes, and snippets.

@rudyhuynh
Last active February 9, 2023 04:45
Show Gist options
  • Save rudyhuynh/ca9379db3ca61dc5f37b41894ba982ee to your computer and use it in GitHub Desktop.
Save rudyhuynh/ca9379db3ca61dc5f37b41894ba982ee to your computer and use it in GitHub Desktop.
Clone PSQL database to different machine

Assume you want to clone all data of table Abc into a database in a different machine.

  1. At src machine:
PGPASSWORD=password sudo pg_dump --host localhost --port 5432 --username username --format plain --verbose --file '/tmp/Abc.bak' --table Abc databasename
  1. Copy file to dst machine.

  2. At dst machine:

IMPORTANT : existing data will be erased

PGPASSWORD=password psql databasename username < Abc.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment