pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: pg_restore
Date: Thu, 11 Apr 2019 18:12:44 -0500
Message-ID: <c576d9d8-afbb-dbaa-92c9-586cfb860b68@gmail.com> (raw)
In-Reply-To: <CALm_VjjLrrWiA92HainW3pdQLRMfBQ4qE2tnd-55A7WUorgyGw@mail.gmail.com>
References: <CALm_VjjLrrWiA92HainW3pdQLRMfBQ4qE2tnd-55A7WUorgyGw@mail.gmail.com>

On 4/11/19 5:09 PM, rammohan ganapavarapu wrote:
> Hi,
>
> I have a custome database called mudb along with default databases in my 
> postgresql cluster, i am trying to restore mydb from a custom format 
> pg_dump file, what is the procedure to do it?
>
> psql -t -h localhost  -U ${RUN_USER}  -c "SELECT 
> pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE 
> pg_stat_activity.datname = 'mydb' AND pid <> pg_backend_pid();"
>
> pg_restore" -h localhost  -U ${RUN_USER}  -d mydb -j "${JOBS}" -x -O -C -c 
> --if-exist -v pgdump.dump
>
> But i am getting below error:
>
> pg_restore: connecting to database for restore
> pg_restore: dropping DATABASE mydb
> pg_restore: [archiver (db)] Error while PROCESSING TOC:
> pg_restore: [archiver (db)] Error from TOC entry 4312; 1262 16384 DATABASE 
> mydb mydb
> pg_restore: [archiver (db)] could not execute query: ERROR:  cannot drop 
> the currently open database
>     Command was: DROP DATABASE IF EXISTS mydb;
>
> So what is the best way to restore? I am using 9.6 version.

I made the same mistake you did, by doing "-d mydb".  You need to specify 
the postgres database.

This works for me:
export PGUSER=${RUN_USER}
export PGHOST=localhost
DB=mydb
pg_restore -xOvcC --if-exists --jobs=${JOBS} *-d postgres*${DB} 2> 
${DB}_restore.log


-- 
Angular momentum makes the world go 'round.

view thread (25+ messages)  latest in thread

Message-ID: <c576d9d8-afbb-dbaa-92c9-586cfb860b68@gmail.com>
Permalink:  ../c576d9d8-afbb-dbaa-92c9-586cfb860b68@gmail.com/
Also on:    postgresql.org/message-id/c576d9d8-afbb-dbaa-92c9-586cfb860b68@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: ronljohnsonjr@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: pg_restore
  In-Reply-To: <c576d9d8-afbb-dbaa-92c9-586cfb860b68@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox