SQLSTATE 42501 ERROR Class 42: Syntax Error or Access Rule Violation

insufficient_privilege permission denied for function … — 42501

PostgreSQL error “permission denied for function … — 42501” (SQLSTATE 42501): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A role lacked the EXECUTE privilege required to call a function or procedure. PostgreSQL raises SQLSTATE 42501 (insufficient_privilege).

  • Missing EXECUTE on the function/procedure.
  • Common after revoking PUBLIC execute or for new roles.
  • Function privileges are separate from schema/table privileges.

What the server log shows

ERROR:  permission denied for function calculate_totals

Why PostgreSQL raises this — what the manual says

As the GRANT reference (Description) explains:

Calling a function or procedure requires the EXECUTE privilege; the role invoking it was not granted EXECUTE on that routine (and is not its owner or a superuser), so PostgreSQL refuses the call.

Calling a function requires the EXECUTE privilege on it. Without that grant (or membership in a role that has it), PostgreSQL denies the call with 42501.

Common causes

  • The role lacks EXECUTE on the function.
  • EXECUTE was revoked from PUBLIC and not granted to the role.
  • A new role not covered by default privileges.

How to fix it

  1. Grant it: GRANT EXECUTE ON FUNCTION calculate_totals() TO app_user;.
  2. Set default privileges for functions created later.
  3. Also ensure the role has USAGE on the function’s schema.

Related & next steps

Reference: PostgreSQL 18 — GRANT.

Was this helpful?