Grant access privileges on objects created in the future

suggest change

Suppose that we have three users:

  1. The administrator of the database: admin
  2. The application, with full access to its data: read_write
  3. Read-only access: read_only

ALTER DEFAULT PRIVILEGES does not change objects that already exist. Without FOR ROLE, it applies only to objects later created by the role that runs the command.

With the queries below, you can set privileges on tables created in the future in a schema:

ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT                      ON TABLES TO read_only;
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT,INSERT,DELETE,UPDATE ON TABLES TO read_write;
ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT ALL                         ON TABLES TO admin;

Or, you can set access privileges on objects created in the future by specified user.

ALTER DEFAULT PRIVILEGES FOR ROLE admin GRANT SELECT  ON TABLES TO read_only;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents