How to restore to empty database

Поиск
Список
Период
Сортировка
От Andrus
Тема How to restore to empty database
Дата
Msg-id D3F14323F35F4DC4BA3E517ED11199E1@dell2
обсуждение исходный текст
Ответы Re: How to restore to empty database
Список pgsql-general
Hi!

I want to restore to new empty database using pg_restore .
pg_restore should create new empty database and restore into it.
If database exists, pg_restore should clean all data from it or drop and 
create new empty database before restore.

According to pg_restore doc, switches --clean --create --if-exists  should 
do this.

I tried

    PG_COLOR=auto
    PGHOST=localhost
    PGPASSWORD=mypass
    PGUSER=postgres
    export PGHOST  PGPASSWORD PG_COLOR PGUSER
    pg_restore --clean --create --if-exists --dbname=mydb  --jobs=4 --verbose 
"mydb.backup"

but got error

pg_restore: connecting to database for restore
pg_restore: error: connection to database "mydb" failed: FATAL:  database 
"mydb" does not exist

I also tried without --dbname=mydb but then got error

pg_restore: error: one of -d/--dbname and -f/--file must be specified

How to restore to database which does not exist to drop existing database 
before restore if it exists ?
Should I invoke

drop database if exists

and

create database

commands before calling pg_restore or can pg_restore do it itself ?

Using Postgres 12 on Debian 10

Andrus. 




В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Exclude constraint on ranges : commutative containment : allowonly complete containment
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: How to restore to empty database