snippetsqlMinor
How do I use pg_dump and pg_restore to move a large database to another machine?
Viewed 0 times
pg_dumpmovedatabaselargeanotherhowandusepg_restoremachine
Problem
I'm a bit unclear on how to use the
Here is the command I use to dump the database (the host and username are taken from environmental variables):
I use the
When I now try to restore it, I tried this:
But I get:
I tried next with the
Finally I tried passing
But here is what I get:
What am I doing wrong here?
pg_dump/pg_restore duo to move a large-ish database.Here is the command I use to dump the database (the host and username are taken from environmental variables):
pg_dump --dbname=mydb --format=custom > mydb.dumpI use the
custom format because I do this over the network and want to use compression.When I now try to restore it, I tried this:
pg_restore --dbname=mydb --no-owner mydb.dumpBut I get:
pg_restore: [archiver (db)] connection to database "mydb" failed: FATAL: database "mydb" does not existI tried next with the
--create option, but that yields the same error message.Finally I tried passing
template1 as a --dbname option:pg_restore --dbname=template1 --no-owner --create mydb.dumpBut here is what I get:
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2125; 1262 16395 DATABASE mydb mydbuser
pg_restore: [archiver (db)] could not execute query: ERROR: invalid locale name: "en_US.utf8"
Command was: CREATE DATABASE mydb WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8';
pg_restore: [archiver (db)] could not reconnect to database: FATAL: database "mydb" does not existWhat am I doing wrong here?
Solution
When you do
You are trying to connect to the
http://www.postgresql.org/docs/current/static/app-pgrestore.html
pg_restore --dbname=mydb --no-owner mydb.dumpYou are trying to connect to the
mydb database which still does not exist. Connect to an existent one and use the --create parameter:pg_restore --dbname=existentdb --no-owner --create mydb.dumphttp://www.postgresql.org/docs/current/static/app-pgrestore.html
Code Snippets
pg_restore --dbname=mydb --no-owner mydb.dumppg_restore --dbname=existentdb --no-owner --create mydb.dumpContext
StackExchange Database Administrators Q#86386, answer score: 6
Revisions (0)
No revisions yet.