Thoughts, information and reflections about technology

Copying a Postgres Database from one laptop to another

I needed to copy a Postgres database from the dev environment on my previous laptop to my current laptop.

The Setup on both machines was Ubuntu running under Oracle virtualbox on Windows 10.

I needed to go to Ubuntu on the old machine . and run the following command in Terminal. I had to put quotes around the db name since it had hyphens in the db name.

pg_dump the_db_name > the_backup.sql

Note – you might want to make sure that the database is not being used when you do that. I decided to use my Google Drive account to move the file. It was only 300k I opened Google drive in chrome, went to the folder for that client and uploaded the SQL file.

I then went to the new machine and opened chrome and Google Drive. I downloaded the sql file to my downloads folder. The following command from terminal re-created the database on my new machine

psql the_new_dev_db < the_backup.sql

I got a bunch of key errors, probably because I had previously created the database. I believe that if the database didn’t exist, you would probably have to create the users and the associated roles.

At any rate, this trick save a LOT of time.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact me