pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: pgsql-bugs@postgresql.org
Subject: schema-only -n option in pg_restore fails
Date: Thu, 09 Oct 2014 12:36:39 -0700
Message-ID: <5436E3C7.4070607@agliodbs.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (4+ messages)  latest in thread

Message-ID: <5436E3C7.4070607@agliodbs.com>
Permalink:  ../5436E3C7.4070607@agliodbs.com/
Also on:    postgresql.org/message-id/5436E3C7.4070607@agliodbs.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: josh@agliodbs.com
  Subject: Re: schema-only -n option in pg_restore fails
  In-Reply-To: <5436E3C7.4070607@agliodbs.com>
  References: <5436E3C7.4070607@agliodbs.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