Skip to content

Instantly share code, notes, and snippets.

@afraz-khan
Last active September 9, 2022 14:01
Show Gist options
  • Save afraz-khan/e2d8986e6811d31285b71ffcac8ab9fa to your computer and use it in GitHub Desktop.
Save afraz-khan/e2d8986e6811d31285b71ffcac8ab9fa to your computer and use it in GitHub Desktop.
Export a postgres backup and import into some other server.
  1. On the source server(remote/local), export the backup first:
pg_dump -U {username} -h {host} -p {port} -f {output-file-path}.sql {dbname to backup}

copy the backup file to the target server.

  1. On the target server(remote/local), log into the postgres using below command.
psql -h [HOST-STRING] -d [DATABASE-NAME] -U [USERNAME]
  1. Select the database with same name as you exported from source or create new if not available:
CREATE DATABASE {dbname};
\c {dbname};
  1. Import the backup file \i {backup-file-path};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment