How to Export a Remote PostgreSQL Database and Import it locally?
·1 min
Mayukh Datta
Technical
SQL
- Create a dump of the remote database using pg_dump command
pg_dump
--host=remote_host_name
--port=remote_port_number
--username=remote_database_user_name
--dbname=database_name
--password
> db_export.sql
You will get a dump SQL file of the remote database upon successful completion of this process.
- Create a database on your local setup with the same name as the remote database.
psql
--username=local_database_user_name
-c 'create database database_name;’
The database has now been created on your local machine.
- Import the data to your local database.
psql
--username=local_database_user_name
database_name < db_export.sql
And, done!