Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEiwM-0006HH-NJ for pgsql-admin@arkaria.postgresql.org; Thu, 11 Apr 2019 23:17:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hEiwL-0006Nv-BS for pgsql-admin@arkaria.postgresql.org; Thu, 11 Apr 2019 23:17:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEiwK-0006No-V8 for pgsql-admin@lists.postgresql.org; Thu, 11 Apr 2019 23:17:05 +0000 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEiwE-0006oP-Gz for pgsql-admin@lists.postgresql.org; Thu, 11 Apr 2019 23:17:03 +0000 Received: by mail-ot1-x342.google.com with SMTP id f10so6787603otb.6 for ; Thu, 11 Apr 2019 16:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=Qlt9Nm479VLenas6RQ322ZFsU9dUxwmMa6TjUOxXKEU=; b=tWllgTR+XisTCWCEi62zbRqMm3J4mEBUEUCyhzMlhbDODhqKrCuTFSNO2xGA5lced/ J8mUeHM0m853+9eTdxgLl+oOjynOnDII4ZHVw7yCTpAFuL94lvnME7XK+yK+Swm9IiBD EDTvwzInXwySCqfV86TITjmR78p58k952cB8ZcrwiKVqyF2IoTcYLj3ti8wTXO+lWN5a vWw1zC2jzFo8wCNnqbg60CyqPkssGZ0daMQcCHOt4g4OsRO+YlqhamhLu2Frtezl7xSM wnzs+Wp5LnKvLxO0GGrnbO62hO/7NeIPRPVd0++mlYVnxMsR5V/Dwn8K/KwqGlyhVN0k I61Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Qlt9Nm479VLenas6RQ322ZFsU9dUxwmMa6TjUOxXKEU=; b=GBm9EKRdMGCS+RPoi6Gnm/z/y1s27onRQs7vVNXhwjz8JwbgIae9LCQ8FOO6G2pYVA /R72PVv+fBVvhb6jeMgIIgw+MuilSsC/0xGZLW7uHqtioa8FEDYnnzUVgRHUnlMKyJMt cQYH1jYJsRVh1aLzjF67jmMf5QEs6Ywmdk/GUG+lF7fDT6dt6F2XPfY8nCHdDiE7iRsL 6NML8zx3J1h17iGs7UI5ySUT44/S05mMJ8f3VUjpOuKofCwzt7AETzaewbeVeB98xTTl 9Y1TVtmFM6GO5Xzmf3dw7VGtlhi/qNgA+N0xw0L2LLTehcN5apF+28nH9jMd7mPwy/iY dIHQ== X-Gm-Message-State: APjAAAXN71i88ItABE+QrfAAwy91Ksw8qmXVU6/9o0mjXyDCmpoev/SZ fh7hYLrAr9ICpmi8aJwZc2i50JgDi1o= X-Google-Smtp-Source: APXvYqxaBYTYOI/TB/+GpMVa6DSgTrNEWStH8VBsvPRensGYaB8YXwgsePKhiMQdzGi6mGIxjwrGsA== X-Received: by 2002:a05:6830:1d7:: with SMTP id r23mr34577595ota.24.1555024617440; Thu, 11 Apr 2019 16:16:57 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id o5sm11841343otl.44.2019.04.11.16.16.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 16:16:56 -0700 (PDT) Subject: Re: pg_restore From: Ron To: pgsql-admin@lists.postgresql.org References: Message-ID: <7da46322-6a20-ef30-2a95-1cafbc8e5e75@gmail.com> Date: Thu, 11 Apr 2019 18:16:55 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------CA9DE6B69FBD004D80C4795D" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------CA9DE6B69FBD004D80C4795D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 4/11/19 6:12 PM, Ron wrote: > 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 But it just occurred to me that I used directory backups, not custom backups, so this probably won't work for you. -- Angular momentum makes the world go 'round. --------------CA9DE6B69FBD004D80C4795D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 4/11/19 6:12 PM, Ron wrote:
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

But it just occurred to me that I used directory backups, not custom backups, so this probably won't work for you.

--
Angular momentum makes the world go 'round.
--------------CA9DE6B69FBD004D80C4795D--