pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #13576: a weird behavior of pg_restore command
2+ messages / 2 participants
[nested] [flat]

* BUG #13576: a weird behavior of pg_restore command
@ 2015-08-17 08:24 nao-anzai@xc.jp.nec.com
  2015-08-17 08:27 ` Re: BUG #13576: a weird behavior of pg_restore command Naoya Anzai <nao-anzai@xc.jp.nec.com>
  0 siblings, 1 reply; 2+ messages in thread

From: nao-anzai@xc.jp.nec.com @ 2015-08-17 08:24 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      13576
Logged by:          Naoya Anzai
Email address:      nao-anzai@xc.jp.nec.com
PostgreSQL version: 9.5alpha2
Operating system:   Linux
Description:        

Hi hackers,

I found a little bit weird behavior of pg_restore command when specified
--no-data-for-failed-tables and -c options.

Following is a script for reproducing that cases.
---
# SQL
psql template1 <<EOF
drop database if exists db_test;
create database  db_test;
\c db_test
begin;
drop table if exists t1;
drop table if exists t2;
create table t1 as select 1::integer as id;
create table t2 as select * from t1;
commit;
EOF

# UNIX commands
pg_dump -Fc -f db_test.dmp db_test

# SQL
psql db_test <<EOF
begin;
drop table if exists t1;
drop table if exists t2;
commit;
EOF


# UNIX commands
pg_restore  -v --no-data-for-failed-tables -c db_test.dmp -d db_test


# SQL
psql db_test <<EOF
begin;
select count(*) as t1_count from t1;
select count(*) as t2_count from t2;
commit;
EOF
---

The result is following.

 t1_count 
----------
        0
(1 row)

 t2_count 
----------
        1
(1 row)

I think this result is absolutely weird because both of creation commands
are ok but t2 data is restored, and somehow t1 data is  not restored.

PostgreSQL document of --no-data-for-failed-tables is following.
---
By default, table data is restored even if the creation command for the
table failed (e.g., because it already exists). 
With this option, data for such a table is skipped. 
---

In this case, both of creation command didn't failed. So t1 data should be
restored even if --no-data-for-failed-tables option is specified.

I have analyzed pg_restore command, and modified like following.

1. 
Any DROP queries are currently in PROCESSING stage.To fix this behavior, at
least, DROP queries and others have to be split into two stages.
Tentatively, I moved Any DROP queries from PROCESSING stage to INITIALIZING
stage. And I have added lastErrorStage check in noDataForFailedTables
check.

2. 
noDataForFailedTables check is currently using AH->lastErrorTE, this doesn't
work fine because pre TOC error is overwritten by current TOC error. Each
TOC should have each own error status, so I removed AH->lastErrorTE, I added
_tocEntry->wasError instead of that.

3. and fixed a japanese word typo of pg_restore --help.


I attached a patch. Would anyone confirm this?

Regards,

Naoya
---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai@xc.jp.nec.com
---



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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #13576: a weird behavior of pg_restore command
  2015-08-17 08:24 BUG #13576: a weird behavior of pg_restore command nao-anzai@xc.jp.nec.com
@ 2015-08-17 08:27 ` Naoya Anzai <nao-anzai@xc.jp.nec.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Naoya Anzai @ 2015-08-17 08:27 UTC (permalink / raw)
  To: pgsql-bugs; +Cc: Akio Iwaasa <aki-iwaasa@vt.jp.nec.com>

Sorry, I forgot the attached.

Regards,

Naoya

---
Naoya Anzai
Engineering Department
NEC Solution Inovetors, Ltd.
E-Mail: nao-anzai@xc.jp.nec.com
---

> -----Original Message-----
> From: pgsql-bugs-owner@postgresql.org
> [mailto:pgsql-bugs-owner@postgresql.org] On Behalf Of
> nao-anzai@xc.jp.nec.com
> Sent: Monday, August 17, 2015 5:25 PM
> To: pgsql-bugs@postgresql.org
> Subject: [BUGS] BUG #13576: a weird behavior of pg_restore command
> 
> The following bug has been logged on the website:
> 
> Bug reference:      13576
> Logged by:          Naoya Anzai
> Email address:      nao-anzai@xc.jp.nec.com
> PostgreSQL version: 9.5alpha2
> Operating system:   Linux
> Description:
> 
> Hi hackers,
> 
> I found a little bit weird behavior of pg_restore command when specified
> --no-data-for-failed-tables and -c options.
> 
> Following is a script for reproducing that cases.
> ---
> # SQL
> psql template1 <<EOF
> drop database if exists db_test;
> create database  db_test;
> \c db_test
> begin;
> drop table if exists t1;
> drop table if exists t2;
> create table t1 as select 1::integer as id;
> create table t2 as select * from t1;
> commit;
> EOF
> 
> # UNIX commands
> pg_dump -Fc -f db_test.dmp db_test
> 
> # SQL
> psql db_test <<EOF
> begin;
> drop table if exists t1;
> drop table if exists t2;
> commit;
> EOF
> 
> 
> # UNIX commands
> pg_restore  -v --no-data-for-failed-tables -c db_test.dmp -d db_test
> 
> 
> # SQL
> psql db_test <<EOF
> begin;
> select count(*) as t1_count from t1;
> select count(*) as t2_count from t2;
> commit;
> EOF
> ---
> 
> The result is following.
> 
>  t1_count
> ----------
>         0
> (1 row)
> 
>  t2_count
> ----------
>         1
> (1 row)
> 
> I think this result is absolutely weird because both of creation commands
> are ok but t2 data is restored, and somehow t1 data is  not restored.
> 
> PostgreSQL document of --no-data-for-failed-tables is following.
> ---
> By default, table data is restored even if the creation command for the
> table failed (e.g., because it already exists).
> With this option, data for such a table is skipped.
> ---
> 
> In this case, both of creation command didn't failed. So t1 data should
> be
> restored even if --no-data-for-failed-tables option is specified.
> 
> I have analyzed pg_restore command, and modified like following.
> 
> 1.
> Any DROP queries are currently in PROCESSING stage.To fix this behavior,
> at
> least, DROP queries and others have to be split into two stages.
> Tentatively, I moved Any DROP queries from PROCESSING stage to
> INITIALIZING
> stage. And I have added lastErrorStage check in noDataForFailedTables
> check.
> 
> 2.
> noDataForFailedTables check is currently using AH->lastErrorTE, this
> doesn't
> work fine because pre TOC error is overwritten by current TOC error. Each
> TOC should have each own error status, so I removed AH->lastErrorTE, I
> added
> _tocEntry->wasError instead of that.
> 
> 3. and fixed a japanese word typo of pg_restore --help.
> 
> 
> I attached a patch. Would anyone confirm this?
> 
> Regards,
> 
> Naoya
> ---
> Naoya Anzai
> Engineering Department
> NEC Solution Inovetors, Ltd.
> E-Mail: nao-anzai@xc.jp.nec.com
> ---
> 
> 
> 
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs


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

Attachments:

pg_restore-bugfix.patch (application/octet-stream, 3.1K) download diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 8f1f6c1..2e5063a 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -439,7 +439,6 @@ RestoreArchive(Archive *AHX) */ _doSetFixedOutputState(AH); - AH->stage = STAGE_PROCESSING; /* * Drop the items at the start, in reverse order @@ -581,6 +580,8 @@ RestoreArchive(Archive *AHX) AH->currSchema = NULL; } + AH->stage = STAGE_PROCESSING; + /* * In serial mode, we now process each non-ACL TOC entry. * @@ -715,7 +716,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, if (strcmp(te->desc, "TABLE") == 0) { - if (AH->lastErrorTE == te) + if (te->wasError && AH->lastErrorStage == STAGE_PROCESSING ) { /* * We failed to create the table. If @@ -1027,6 +1028,9 @@ ArchiveEntry(Archive *AHX, newToc->formatData = NULL; + newToc->created = false; + newToc->wasError = false; + if (AH->ArchiveEntryPtr !=NULL) (*AH->ArchiveEntryPtr) (AH, newToc); } @@ -1665,15 +1669,15 @@ warn_or_exit_horribly(ArchiveHandle *AH, write_msg(modulename, "Error while FINALIZING:\n"); break; } - if (AH->currentTE != NULL && AH->currentTE != AH->lastErrorTE) + if (AH->currentTE != NULL && !AH->currentTE->wasError) { write_msg(modulename, "Error from TOC entry %d; %u %u %s %s %s\n", AH->currentTE->dumpId, AH->currentTE->catalogId.tableoid, AH->currentTE->catalogId.oid, AH->currentTE->desc, AH->currentTE->tag, AH->currentTE->owner); + AH->currentTE->wasError = true; } AH->lastErrorStage = AH->stage; - AH->lastErrorTE = AH->currentTE; va_start(ap, fmt); vwrite_msg(modulename, fmt, ap); diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index 620ada5..7e02531 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -332,7 +332,6 @@ struct _archiveHandle ArchiverStage stage; ArchiverStage lastErrorStage; struct _tocEntry *currentTE; - struct _tocEntry *lastErrorTE; }; struct _tocEntry @@ -364,6 +363,7 @@ struct _tocEntry /* working state while dumping/restoring */ teReqs reqs; /* do we need schema and/or data of object */ bool created; /* set for DATA member if TABLE was created */ + bool wasError; /* set true if Error occured in this toc. */ /* working state (needed only for parallel restore) */ struct _tocEntry *par_prev; /* list links for pending/ready items; */ diff --git a/src/bin/pg_dump/po/ja.po b/src/bin/pg_dump/po/ja.po index 980eab6..0189f3f 100644 --- a/src/bin/pg_dump/po/ja.po +++ b/src/bin/pg_dump/po/ja.po @@ -2415,7 +2415,7 @@ msgid "" " --no-data-for-failed-tables do not restore data of tables that could not be\n" " created\n" msgstr "" -" --no-data-for-failed-tables 作成できなかったテーッブルのデータはリストア\n" +" --no-data-for-failed-tables 作成できなかったテーブルのデータはリストア\n" " しません\n" #: pg_restore.c:461
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-08-17 08:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-08-17 08:24 BUG #13576: a weird behavior of pg_restore command nao-anzai@xc.jp.nec.com
2015-08-17 08:27 ` Naoya Anzai <nao-anzai@xc.jp.nec.com>

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