April 3

0 comments

Copying a Postgres Database from one laptop to another

By Christopher G Mendla

April 3, 2019

Windows 10

Last Updated on October 14, 2023 by Christopher G Mendla

I needed to copy a Postgres database from the dev environment on my previous laptop to my current laptop. The process was relatively easy.

How to copy a Postgres database between Laptops

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.

Copy a Postgres database from one laptop to another
Copy a Postgres database from one laptop to another


pg_dump the_db_name > the_backup.sql

Note – you might want to make sure that the database is not being used when you try to copy it. 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

Results

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.

Christopher G Mendla

About the author

A web developer living in Southampton, PA

Self motivated critical thinker and problem solver providing technology consulting services.

Leave a Reply

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

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}