On 8 April 2015 at 05:05, David G. Johnston <david.g.johns...@gmail.com>
wrote:

> On Tue, Apr 7, 2015 at 1:33 PM, Tom Lane <t...@sss.pgh.pa.us> wrote:
>
>> Peter Eisentraut <pete...@gmx.net> writes:
>> > On 3/31/15 11:01 PM, Craig Ringer wrote:
>> >> this patch adds support for views, foreign tables, and materialised
>> >> views to the pg_restore -t flag.
>>
>> > I think this is a good change.  Any concerns?
>>
>> Are we happy with pg_dump/pg_restore not distinguishing these objects
>> by type?  It seems rather analogous to letting ALTER TABLE work on views
>> etc.  Personally I'm fine with this, but certainly some people have
>> complained about that approach so far as ALTER is concerned.  (But the
>> implication would be that we'd need four distinct switches, which is
>> not an outcome I favor.)
>>
>
> ​The pg_dump documentation for the equivalent "-t" switch states:
>
> ​"Dump only tables (or views or sequences or foreign tables) matching
> table"
>
> Does pg_dump need to be updated to address materialized views here?
>

The pg_dump code handles materialized views, the docs weren't updated. I
added mention of them in the next rev of the patch to pg_restore.


> Does pg_restore need to be updated to address sequences here?
>

I'd be against that if pg_dump didn't already behave the same way. Given
that, yes, I think so.


> ISTM that the two should mirror each other.
>

Ideally, yes, but the differences go much deeper than this.

to get the equivalent of:

    pg_restore -n myschema -t sometable

in pg_dump you need:

    pg_dump -t "\"myschema\".\"sometable\""

pg_dump -n myschema -t sometable is **not** equivalent. In fact, the -n is
ignored, and -t will match using the search_path.

so they're never really going to be the same, just similar enough to catch
people out most of the time.

I think you're right that sequences should be included by pg_restore since
they are by pg_dump, though. So v3 patch attached.


-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services
From dc8985d4aa5e995e5107fe9dcb65ec061dc378eb Mon Sep 17 00:00:00 2001
From: Craig Ringer <cr...@2ndquadrant.com>
Date: Wed, 1 Apr 2015 10:46:29 +0800
Subject: [PATCH] pg_restore -t should select views, matviews, and foreign
 tables

Currently pg_restore's '-t' option selects only tables, not other
relations. It should be able to match anything that behaves like
a relation in the relation namespace, anything that's interchangable
with a table, including:

* Normal relations
* Views
* Materialized views
* Foreign tables
* Sequences

Sequences are matched because pg_dump -t matches them, even though
their status as relations is really just an implementation detail.

Indexes are not matched because pg_dump -t doesn't match them, and
because they aren't really relations.

TOAST tables aren't matched, they're implementation detail.

See:
  http://www.postgresql.org/message-id/camsr+ygj50tvtvk4dbp66gajeoc0kap6kxfehaom+neqmhv...@mail.gmail.com
---
 doc/src/sgml/ref/pg_dump.sgml        |  2 +-
 doc/src/sgml/ref/pg_restore.sgml     | 25 ++++++++++++++++++++++---
 src/bin/pg_dump/pg_backup_archiver.c |  7 ++++++-
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index a6e7b08..7f7da9e 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -501,7 +501,7 @@ PostgreSQL documentation
       <term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
       <listitem>
        <para>
-        Dump only tables (or views or sequences or foreign tables) matching
+        Dump only tables (or views, sequences, foreign tables or materialized views) matching
         <replaceable class="parameter">table</replaceable>.  Multiple tables
         can be selected by writing multiple <option>-t</> switches.  Also, the
         <replaceable class="parameter">table</replaceable> parameter is
diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index 9f8dc00..9119e3e 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -405,9 +405,28 @@
       <term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
       <listitem>
        <para>
-        Restore definition and/or data of named table only. Multiple tables
-        may be specified with multiple <option>-t</> switches. This can be
-        combined with the <option>-n</option> option to specify a schema.
+        Restore definition and/or data of the named table (or other relation)
+        only. This flag matches views, materialized views and foreign tables as
+        well as ordinary tables. Multiple relations may be specified with
+        multiple <option>-t</> switches. This can be combined with the
+        <option>-n</option> option to specify a schema.
+        <note>
+         <para>
+          When <literal>-t</literal> is specified,
+          <application>pg_restore</application> makes no attempt to restore any
+          other database objects that the selected table(s) might depend upon.
+          Therefore, there is no guarantee that the results of a specific-table
+          restore into a clean database will succeed.
+         </para>
+        </note>
+        <note>
+         <para>
+          This flag is not entirely compatible with versions prior to
+          PostgreSQL 9.5. In 9.4 and below this flag matched only tables. It
+          also behaves differently to the flag with the same name in
+          <application>pg_dump</application>.
+         </para>
+        </note>
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index ca427de..8607dd1 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -2663,7 +2663,12 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
 	if (ropt->selTypes)
 	{
 		if (strcmp(te->desc, "TABLE") == 0 ||
-			strcmp(te->desc, "TABLE DATA") == 0)
+			strcmp(te->desc, "TABLE DATA") == 0 ||
+			strcmp(te->desc, "VIEW") == 0 ||
+			strcmp(te->desc, "FOREIGN TABLE") == 0 ||
+			strcmp(te->desc, "MATERIALIZED VIEW") == 0 ||
+			strcmp(te->desc, "MATERIALIZED VIEW DATA") == 0 ||
+			strcmp(te->desc, "SEQUENCE") == 0)
 		{
 			if (!ropt->selTable)
 				return 0;
-- 
2.1.0

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to