Goal This query identifies database roles that have explicitly revoked the default EXECUTE privilege from PUBLIC for newly created routines. By default, PostgreSQL automatically grants the EXECUTE privilege to PUBLIC (all users) whenever a new function or procedure is created. Revoking this default behavior is a critical security best practice, ensuring that access to potentially sensitive database logic must be explicitly granted.
Type General Overview of some aspect of the database.
License MIT (opens in new tab)
Data Source system catalog only
SQL Query
SELECT r.rolname
FROM pg_default_acl d
JOIN pg_roles r ON r.oid = d.defaclrole
WHERE d.defaclobjtype = 'f' 
  AND d.defaclnamespace = 0 
  AND NOT EXISTS (
      SELECT 1 
      FROM unnest(d.defaclacl) AS acl 
      WHERE acl::text LIKE '=%'
  );

Fixing Suggestion

Since this query identifies securely configured roles, no corrective action is needed for the returned results. However, you should review roles that are missing from this list. To enforce this security best practice across other roles, execute the following command for those missing roles: ALTER DEFAULT PRIVILEGES FOR ROLE [role_name] REVOKE EXECUTE ON ROUTINES FROM PUBLIC;. Afterwards, explicitly grant EXECUTE privileges only to the specific users or roles that require them.

Categories

This query is classified under the following categories:

Security

Queries of this category provide information about the security measures.

User-defined routines

Queries of this category provide information about the user-defined routines

NameDescription
SecurityQueries of this category provide information about the security measures.
User-defined routinesQueries of this category provide information about the user-defined routines