How To Duplicate a PGSQL database
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.
























Steve said
am October 15 2009 @ 8:34 am
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!
~Steve
Tim Barsness said
am October 17 2009 @ 11:42 am
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.