diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index df8a69d3b7..c61c648718 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -763,11 +763,15 @@ RestoreArchive(Archive *AHX, bool append_data) for (te = AH->toc->next; te != AH->toc; te = te->next) { + /* Skip if no item is given */ + if (!te) + continue; + if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS)) == 0) continue; /* ignore if not to be dumped at all */ /* Skip if no-tablespace is given. */ - if (ropt->noTablespace && te && te->desc && + if (ropt->noTablespace && te->desc && (strcmp(te->desc, "TABLESPACE") == 0)) continue; @@ -775,7 +779,7 @@ RestoreArchive(Archive *AHX, bool append_data) * Skip DROP DATABASE/ROLES/TABLESPACE if we didn't specify * --clean */ - if (!ropt->dropSchema && te && te->desc && + if (!ropt->dropSchema && te->desc && strcmp(te->desc, "DROP_GLOBAL") == 0) continue;