have pg_restore create a new database?

Started by Thomas H.over 19 years ago4 messagesgeneral
Jump to latest
#1Thomas H.
me@alternize.com

i'm trying to have pg_restore create a new db and load the data.

unfortunately, pg_restore always uses the database name specified in the dump. "--create" and "--dbname=newdb" does not seem to have any effect (pg_restore yells about database being non-existant).

what is the proper method to restore data from a previous named database "olddb" into a fresh database named "newdb"? the old database still exists and i don't want to overwrite the data.

regards,
thomas

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas H. (#1)
Re: have pg_restore create a new database?

"Thomas H." <me@alternize.com> writes:

what is the proper method to restore data from a previous named database =
"olddb" into a fresh database named "newdb"? the old database still =
exists and i don't want to overwrite the data.

Create newdb by hand and then specify it as the connection target for
pg_restore. *Don't* use --create, as that tells pg_restore to create
and (re)connect to the database named in the dump.

regards, tom lane

#3Thomas H.
me@alternize.com
In reply to: Thomas H. (#1)
Re: have pg_restore create a new database?

"Thomas H." <me@alternize.com> writes:

what is the proper method to restore data from a previous named database
=
"olddb" into a fresh database named "newdb"? the old database still =
exists and i don't want to overwrite the data.

Create newdb by hand and then specify it as the connection target for
pg_restore. *Don't* use --create, as that tells pg_restore to create
and (re)connect to the database named in the dump.

i see.

but then failures will pop up: when creating a new db, it already contains
the system languages, functions and tables (for example tsearch2). as the
dump contains these as well, i'm getting lots of errors and more important,
tsearch2 custom config won't be restored.

how can i create an *empty* database?

- thomas

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas H. (#3)
Re: have pg_restore create a new database?

"Thomas H." <me@alternize.com> writes:

how can i create an *empty* database?

Clone it from template0, not template1.

regards, tom lane