Skip to main content
  1. Articles/

How to Export a Remote PostgreSQL Database and Import it locally?

·1 min
Mayukh Datta
Technical SQL
  1. 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 > db_export.sql

You will get a dump SQL file of the remote database upon successful completion of this process.

  1. 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.

  1. Import the data to your local database.
psql --username=local_database_user_name database_name < db_export.sql

And, done!