Skip to content

Fix: Apply IncludeGlobalDBObjects when using wildcard schema ('*') #759

@tsg

Description

@tsg

Bug

In pgdumpOptions() (pg_options_generator.go), the switch statement treats wildcard schema and includeGlobalDBObjects as mutually exclusive:

switch {
case hasWildcardSchema(schemaTables):
    opts.Schemas = nil   // dumps everything, always includes global objects
case o.includeGlobalDBObjects:
    opts.ExcludeSchemas, err = o.pgdumpExcludedSchemas(ctx, schemas)
    opts.Schemas = nil
}

When wildcard schema is used, opts.Schemas = nil causes pg_dump to dump everything including global objects. The IncludeGlobalDBObjects setting is ignored — global objects are always included with wildcard schema.

Expected behavior

  • * + IncludeGlobalDBObjects: true → include global objects (current: correct by accident)
  • * + IncludeGlobalDBObjects: false → exclude global objects (current: broken, they're still included)

Fix

Replace the switch with an if/else that handles all 4 combinations:

  1. Wildcard + no global objects: discover all user schemas via DiscoverAllSchemas() and use schema inclusion filter to exclude global objects
  2. Wildcard + global objects: opts.Schemas = nil (no filter needed)
  3. Specific schemas + global objects: use exclude filter (existing behavior)
  4. Specific schemas + no global objects: use schema inclusion filter (existing behavior)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions