Обсуждение: postgresql 9.0.3: parallel restore fails with comments on indices

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

postgresql 9.0.3: parallel restore fails with comments on indices

От
Arnd Hannemann
Дата:
Hi,

postgres version: 9.0.3
OS: debian squeeze 64bit

if pg_restore is used with -jN it fails if the dump has comments on indices.

Steps to reproduce (db testdb):

CREATE DATABASE testdb;
\c testdb
CREATE TABLE tab (id INT);
INSERT INTO tab VALUES (1);
CREATE INDEX idx ON tab USING btree (id);
COMMENT ON INDEX idx IS 'first index';

(pgsql-pg_9.0.3)aha@abt:~/bin$ pg_restore --version
pg_restore (PostgreSQL) 9.0.3
(pgsql-pg_9.0.3)aha@abt:~/bin$ pg_dump -F c testdb > testdb.pg_dump
(pgsql-pg_9.0.3)aha@abt:~/bin$ pg_restore -j2 -c -d testdb testdb.pg_dump
ERROR:  relation "idx" does not exist
STATEMENT:  COMMENT ON INDEX idx IS 'first index';
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 1784; 0 0 COMMENT INDEX idx aha
pg_restore: [archiver (db)] could not execute query: ERROR:  relation "idx" does not exist
    Command was: COMMENT ON INDEX idx IS 'first index';
WARNING: errors ignored on restore: 1

(pgsql-pg_9.0.3)aha@abt:~/bin$ pg_restore  -c -d testdb testdb.pg_dump
(pgsql-pg_9.0.3)aha@abt:~/bin$ echo $?
0


The problem seems to be a false assumption in pg_backup_archiver.c:

3200         for (next_work_item = AH->toc->next; next_work_item != AH->toc; next_work_item = next_work_item->next)
3201         {
3202                 /* Non-PRE_DATA items are just ignored for now */
3203                 if (next_work_item->section == SECTION_DATA ||
3204                         next_work_item->section == SECTION_POST_DATA)
3205                         continue;
3206
3207                 ahlog(AH, 1, "processing item %d %s %s\n",
3208                           next_work_item->dumpId,
3209                           next_work_item->desc, next_work_item->tag);
3210
3211                 (void) restore_toc_entry(AH, next_work_item, ropt, false);
3212
3213                 /* there should be no touch of ready_list here, so pass NULL */
3214                 reduce_dependencies(AH, next_work_item, NULL);
3215         }

Comments are in SECTION_NONE so they get restored here regardless of dependencies, which is obviously wrong
because the comment on an INDEX depends on the INDEX itself and the INDEX is in SECTION_POST_DATA


Best regards
Arnd


--
Arnd Hannemann

credativ GmbH, HRB Mönchengladbach 12080
Hohenzollernstr. 133, 41061 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz

Re: postgresql 9.0.3: parallel restore fails with comments on indices

От
Tom Lane
Дата:
Arnd Hannemann <arnd.hannemann@credativ.de> writes:
> if pg_restore is used with -jN it fails if the dump has comments on indices.

Reproduced here, thanks for the report!

> The problem seems to be a false assumption in pg_backup_archiver.c:
> ...
> Comments are in SECTION_NONE so they get restored here regardless of dependencies, which is obviously wrong

Yeah, that seems to need a bit more thought.  It's intentional that
comments that are in the PRE_DATA area get restored immediately, so as
not to eat all the overhead of a worker subprocess for them.  But we
can't do it that way for comments intermixed with POST_DATA items.

I think the simplest fix is to allow this loop to process SECTION_NONE
items only as long as it hasn't skipped any prior items.

            regards, tom lane