I'm looking to copy a production PostgreSQL database to a development server. What's the quickest, easiest way to go about doing this?
|
You don't need to create an intermediate file. You can do
or
Using psql or pg_dump to connect to a remote host. With a big database or a slow connection, dumping a file and transfering the file compressed may be faster. Edit As porneL said there is no need to dump to a intermediate file, if you want to work compressed you can do with a compressed tunnel .
or
But this solution also requires to get a session in both ends. |
|||||||||||||||||||||
|
Then copy the backup to your development server, restore with:
|
|||||||||||||||||
|
Use pg_dump, and later psql or pg_restore - depending whether you choose -Fp or -Fc options to pg_dump. Example of usage:
|
|||
|
|
|||||
|
For PostgreSQL you can use either of these operations
|
||||
|
I struggled quite a lot and eventually the method that allowed me to make it work with Rails 4 was: on your old server
I had to use the postgres linux user to create the dump. also i had to use -c to force the creation of the database on the new server. --inserts tells it to use the INSERT() syntax which otherwise would not work for me :( then, on the new server, simpy:
to transfer the dump.sql file between server I simply used the "cat" to print the content and than "nano" to recreate it copypasting the content. Also, the ROLE i was using on the two database was different so i had to find-replace all the owner name in the dump. |
|||
|
Run this command with database name you want to backup to take dump of DB.
Now scp this dump file to remote machine where you want to copy DB.
On remote machine run following command in ~/some/folder to restore the DB.
|
|||
|
If you are looking to migrate between versions (eg you updated postgres and have 9.1 running on localhost:5432 and 9.3 running on localhost:5434) you can run:
Check out the migration docs. |
|||
|
Another possibility would be to copy the entire data directory, but since it's not fail proof, I'd go with the safer pg_dump method. |
|||
|
protected by durron597 Sep 18 at 13:54
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?