Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XcJW5-0000Ig-5H for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Oct 2014 19:36:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XcJW4-0000Ox-E1 for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Oct 2014 19:36:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XcJW3-0000Oi-6m for pgsql-bugs@postgresql.org; Thu, 09 Oct 2014 19:36:47 +0000 Received: from 01.zmailcloud.com ([192.198.85.104] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XcJVy-0000ii-Cl for pgsql-bugs@postgresql.org; Thu, 09 Oct 2014 19:36:45 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id 1A02A5640ED for ; Thu, 9 Oct 2014 14:36:41 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 0E2D2A04F2 for ; Thu, 9 Oct 2014 14:36:41 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ptMHJeGdy4-q for ; Thu, 9 Oct 2014 14:36:40 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id E4C25A0502 for ; Thu, 9 Oct 2014 14:36:40 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id D7719A04FF for ; Thu, 9 Oct 2014 14:36:40 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id JTg_Z5Zr6pLh for ; Thu, 9 Oct 2014 14:36:40 -0500 (CDT) Received: from [172.47.23.102] (70-36-143-82.dsl.dynamic.fusionbroadband.com [70.36.143.82]) by smtp-out-1.01.com (Postfix) with ESMTPSA id 81B71A0500 for ; Thu, 9 Oct 2014 14:36:40 -0500 (CDT) Message-ID: <5436E3C7.4070607@agliodbs.com> Date: Thu, 09 Oct 2014 12:36:39 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: schema-only -n option in pg_restore fails Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Summary: pg_restore -n attempts to restore objects to pg_catalog schema Versions Tested: 9.3.5, 9.3.0, 9.2.4 Severity: Failure Description: The -n option (or --schema) for pg_restore is supposed to allow you to restore a single schema from a custom-format pg_dump file. Instead, it attempts to restore that schema's objects to the pg_catalog schema instead. See the test case below. What's happening here is that the user is apparently expected to create the schema manually before doing a -n pg_restore. However, that's not what the documentation says, and additionally doesn't make any sense if we're not giving the user the ability to restore to an alternate schema name (and so far we aren't). If the schema does not already exist, pg_restore attempts to restore to the pg_catalog schema instead, which fails. In other words, pg_restore -n is "just broken". Clearly few people use it or we'd have a bug on it before now. What should happen is that pg_restore -n should create the schema if it doesn't already exist. If for some reason you think that pg_restore shouldn't create the schema (which would be user-hostile, but at least consistent), then this should fail cleanly with a "schema does not exist" error message instead of trying to restore to pg_catalog. Test Case: 1. createdb schtest; 2. createdb schrestore; 3. psql schtest 4. create schema schem_a; create table schem_a.tab_a ( test text ); create schema schem_b; create table schem_b.tab_b ( test text ); create schema schem_c; create table schem_c.tab_c ( test text ); 5. pg_dump -Fc -f /tmp/schmtest.dump schtest 6. pg_restore -Fc -n schem_a -d schrestore /tmp/schmtest.dump 7. pg_restore: [archiver (db)] Error while PROCESSING TOC: pg_restore: [archiver (db)] Error from TOC entry 171; 1259 1191591 TABLE tab_a josh pg_restore: [archiver (db)] could not execute query: ERROR: permission denied to create "pg_catalog.tab_a" DETAIL: System catalog modifications are currently disallowed. Command was: CREATE TABLE tab_a ( test text ); pg_restore: [archiver (db)] could not execute query: ERROR: schema "schem_a" does not exist Command was: ALTER TABLE schem_a.tab_a OWNER TO josh; pg_restore: [archiver (db)] Error from TOC entry 2194; 0 1191591 TABLE DATA tab_a josh pg_restore: [archiver (db)] could not execute query: ERROR: relation "tab_a" does not exist Command was: COPY tab_a (test) FROM stdin; -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs