diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 796a0aa71685b96d567f5ae5c16cb30ca8d1bd9d..17a3050c30a62741ff24e4f84da3501f516426ae 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -3268,15 +3268,22 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData, bool acl_pass) /* * Avoid dumping the public schema, as it will already be created ... - * unless we are using --clean mode, in which case it's been deleted and - * we'd better recreate it. Likewise for its comment, if any. + * unless we are using --clean mode (and *not* --create mode), in which + * case we've previously issued a DROP for it so we'd better recreate it. + * + * Likewise for its comment, if any. (We could try issuing the COMMENT + * command anyway; but it'd fail if the restore is done as non-super-user, + * so let's not.) + * + * XXX it looks pretty ugly to hard-wire the public schema like this, but + * it sits in a sort of no-mans-land between being a system object and a + * user object, so it really is special in a way. */ - if (!ropt->dropSchema) + if (!(ropt->dropSchema && !ropt->createDB)) { if (strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0) return; - /* The comment restore would require super-user privs, so avoid it. */ if (strcmp(te->desc, "COMMENT") == 0 && strcmp(te->tag, "SCHEMA public") == 0) return;