Обсуждение: pg_restore -t table doesn't restore PKEY

Поиск
Список
Период
Сортировка

pg_restore -t table doesn't restore PKEY

От
"Jan C."
Дата:
Hello,
I have dump of an entire database and I'm trying to restore only one named table:

> pg_restore  --format=c -C -U myUser -d myDB /tmp/mydump -t my_table

The command completes without errors/warnings but the resulting table in the database is missing the PKEY constraint !

Is this done on purpose ? What is the correct way to restore a named table ? 

I know I can use the -t switch during the dump and then restore without using -t but I would like to avoid this solution. The files I can work on are dumps of the entire DB.

Thanks for your help,
Jan

Re: pg_restore -t table doesn't restore PKEY

От
Tom Lane
Дата:
"Jan C." <chaljan@gmail.com> writes:
> I have dump of an entire database and I'm trying to restore only one named
> table:

>> pg_restore  --format=c -C -U myUser -d myDB /tmp/mydump -t my_table

> The command completes without errors/warnings but the resulting table in the
> database is missing the PKEY constraint !

Use pg_restore -l, then extract the lines relevant to your table, then
pg_restore -L to restore just the named items.

I think there's a TODO to make pg_restore's -t switch work more like
pg_dump's, but at the moment they're really quite different animals.
pg_restore doesn't have any logic about "oh, if he asked for this
item I bet he wants that one too".

            regards, tom lane

Re: pg_restore -t table doesn't restore PKEY

От
"Jan C."
Дата:
So I'd have to do:

pg_restore  -l /tmp/mydump | grep my_table  > /tmp/mytable_lines
pg_restore  --format=c -C -U myUser -d myDB /tmp/mydump -L /tmp/mytable_lines


It looks like I have to use "grep" to look for my table and not "-t
my_table" because the PKEY constraint is NOT listed when I do
pg_restore  -l /tmp/mydump -t my_table




In any case, shouldn't the documentation describe more the pg_restore
-t command ? It's really misleading and one can discover this only by
running into problems.

Thanks for your help,

Jan



On Fri, Oct 29, 2010 at 4:30 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Jan C." <chaljan@gmail.com> writes:
>> I have dump of an entire database and I'm trying to restore only one named
>> table:
>
>>> pg_restore  --format=c -C -U myUser -d myDB /tmp/mydump -t my_table
>
>> The command completes without errors/warnings but the resulting table in the
>> database is missing the PKEY constraint !
>
> Use pg_restore -l, then extract the lines relevant to your table, then
> pg_restore -L to restore just the named items.
>
> I think there's a TODO to make pg_restore's -t switch work more like
> pg_dump's, but at the moment they're really quite different animals.
> pg_restore doesn't have any logic about "oh, if he asked for this
> item I bet he wants that one too".
>
>                        regards, tom lane
>