PostgreSQL – How to Set Default Privileges on Schemas

permissionspostgresql

According to the PostgreSQL documentation on ALTER DEFAULT PRIVILEGES, default privileges can be set on tables, sequences, functions, types.

Is there any way to set default privileges on schemas themselves, so that the privileges specified in the GRANT clause are by default applied to any new schema in the database upon its creation?

Best Answer

As mentioned by @a_horse_with_no_name, this is now implemented in PostgreSQL v10

ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be applied to objects created in the future. (It does not affect privileges assigned to already-existing objects.) Currently, only the privileges for schemas, tables (including views and foreign tables), sequences, functions, and types (including domains) can be altered.

Example,

ALTER DEFAULT PRIVILEGES
  GRANT USAGE ON SCHEMAS
  TO role;