How To Duplicate a PGSQL database

Tim Barsness

Recently I needed to create a duplicate of PGSQL database.  Being a MySQL guy, I didn’t know off hand how to do it, but here is an easy way:

pg_dump original_db > original_db.sql
createdb new_db
psql -d new_db < original_db.sql

From a bird’s eye view, you are creating a dump of the original database and outputting it to a file. From there, make sure the new database is created and use your dump file as input for that database. It wouldn’t be too hard to make this into a one-liner, but I like to see intermediate steps to make sure things are going well.

Last updated by on .

8 thoughts on "How To Duplicate a PGSQL database"

  1. Steve says:

    Hey, just wanted to let you know that this worked really well. For how much this has to be searched on Google, this little gem of three commands was a needle in a haystack. Couldn’t find it anywhere! Thanks for the help. Cheers!


  2. Tim Barsness says:

    Thanks Steve. I ran across a need for this as well and it took me a while to figure out a solution, so I figured I would share it.

  3. we prefer to honor numerous other web internet sites on the web, even if they arent linked to us, by linking to them. Underneath are some webpages worth checking out

  4. that would be the end of this post. Right here youll locate some web sites that we consider youll enjoy, just click the links over

  5. below youll discover the link to some web-sites that we believe you’ll want to visit

  6. below youll locate the link to some internet sites that we think you should visit

  7. always a big fan of linking to bloggers that I appreciate but dont get a good deal of link adore from

  8. we prefer to honor a lot of other net web sites on the net, even when they arent linked to us, by linking to them. Underneath are some webpages really worth checking out

What Are Your Thoughts?

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