Take the 2-minute tour ×

I've run the following command on an existing database server:

 pg_dump -C -U testuser testdb -h -F t> testdbdump

Now I'm trying to create this testdb on a new server. I tried to run the following command on the new server:

 pg_restore -h testdbdump

I've created the testuser role on the new database server. And then I also tried the following:

pg_restore -i -h -p 5432 -U postgres "testdbdump"

psql template1 postgres -f testdbdump

It did start to do some stuff, but I get a bunch of errors including:

psql:testdbdump:1720: invalid command \N
psql:testdbdump:1721: invalid command \N
psql:testdbdump:1808: ERROR:  syntax error at or near "user"
LINE 1: user=phone

Did I create the dump file incorrectly?

share|improve this question
Have you tried connecting as postgres to template1? –  Nathan L Nov 14 '13 at 21:44
I've tried connecting as postgres... but i don't know what you mean by template1 –  dot Nov 14 '13 at 21:45
template1 is the default database, if your file has the createdb commands in it, then you can run it from template1 –  Nathan L Nov 14 '13 at 21:46
psql template1 postgres -f testdbdump –  Nathan L Nov 14 '13 at 21:48
or just do a pg_restore testdbdump –  Nathan L Nov 14 '13 at 21:49
show 6 more comments

1 Answer

Look up the --create option of pg_restore. It's made for this purpose.

share|improve this answer
I have been trying the -C option... like so: # pg_restore testdbdump -C -h It seems to show the contents of my tar file... and then I get my prompt back. But when I sign into postgres, i don't have my database. Does the userID I use to create / restore matter? –  dot Nov 15 '13 at 13:13
add comment

Your Answer


