defaultPrivileges

Return ALTER DEFAULT PRIVILEGES entries (pg_default_acl): what grants the NEXT object of each type will get, per granting role and per schema.

read-onlyany connectionsweeps instancesweeps group

Synopsis

defaultPrivileges([schema])

Description

Return ALTER DEFAULT PRIVILEGES entries (pg_default_acl): what grants the NEXT object of each type will get, per granting role and per schema. checkRoleAccess answers about the objects that exist; this is the only thing that answers about the ones that do not yet, and it is the standing cause of "the new table is not readable and every old one is" -- which presents as a broken grant and is a missing default. scope 'global' (defaclnamespace = 0) overrides the hard-wired defaults for that object type; scope 'schema' entries are ADDED to the global ones, so two entries for one type are cumulative rather than conflicting.

Note that defaults apply only to objects created by the granting role, which is why granted_by is reported beside every entry.

Parameters

schema optionalstring
restrict to one schema's entries plus the global ones, which apply there too because per-schema entries are added to them; omit for every entry. A schema that does not exist is an error

Also accepts connection, instance, group, described once under arguments every tool takes.

Output

Default privileges: what grants the NEXT object gets. An absent extension or a missing grant is reported as {error, hint} instead.

FieldType
default_privilegesarray | null

Scope

A physical replica is byte-identical here, so asking each member of a replication group adds nothing.

Example mocked data

Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "defaultPrivileges",
    "arguments": {
      "schema": "shop"
    }
  }
}

Result

{
  "default_privileges": [
    {
      "scope": "global",
      "schema": null,
      "granted_by": "migrator",
      "object_type": "function",
      "grants": {
        "PUBLIC": [
          "EXECUTE"
        ]
      }
    },
    {
      "scope": "schema",
      "schema": "shop",
      "granted_by": "migrator",
      "object_type": "table",
      "grants": {
        "reporting": [
          "SELECT"
        ]
      }
    }
  ]
}

Invented values on a fictional shop database, shaped by and checked against this tool's output schema. Real output is returned as structuredContent to clients that negotiate MCP 2025-06-18 or later.

See also

checkPrivileges, roleDependencies, checkRoleAccess