Hi All,

I have a database dump that is created with the following command:
pg_dump IPADB -Ft -s -v -U postgres | gzip -9 > ${IPA_TMP_DIR}/IPADB.$(date +"%
Y%m%d.%H%M%S").tar.gz

I want to create a test database but I am having difficulty understanding how
to use pg_restore.

# pg_restore --create --dbname=IPA_TEST --schema-only --verbose -U postgres
TEST.tar
pg_restore: connecting to database for restore
pg_restore: [archiver (db)] connection to database "IPA_TEST" failed: FATAL:
Database "IPA_TEST" does not exist in the system catalog.
pg_restore: *** aborted because of error

The documentation indicates that the dumpfile is meant to be used by psql and
that I have to create the database manually prior to the restore. So what is
the purpose of pg_restore and it's --create option?

Any hints appreciated.

Kind Regards,
Keith

______________________________________________
99main Internet Services http://www.99main.com

Search Discussions

  • Tom Lane at Dec 29, 2004 at 7:05 pm

    "Keith Worthington" <keithw@narrowpathinc.com> writes:
    I want to create a test database but I am having difficulty understanding how
    to use pg_restore.
    # pg_restore --create --dbname=IPA_TEST --schema-only --verbose -U postgres
    TEST.tar
    pg_restore: connecting to database for restore
    pg_restore: [archiver (db)] connection to database "IPA_TEST" failed: FATAL:
    Database "IPA_TEST" does not exist in the system catalog.
    pg_restore: *** aborted because of error
    --dbname specifies the already-existing database to connect to
    initially. When you use --create, the only thing that connection is
    used for is to issue the CREATE DATABASE command for the target DB,
    and then pg_restore reconnects to the new target DB. So the usual
    locution is
    pg_restore --create --dbname=template1 ...etc...

    Plan B is to create the target DB by hand before running pg_restore,
    in which case you don't use --create and do specify the real target
    DB in --dbname. You have to do it this way if you wish to restore into
    a DB with a different name than you dumped from, because --create will
    always create the original DB name shown in the dump.

    regards, tom lane

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedDec 29, '04 at 6:33p
activeDec 29, '04 at 7:05p
posts2
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Keith Worthington: 1 post Tom Lane: 1 post

People

Translate

site design / logo © 2022 Grokbase