Consider a PostgreSQL database with a schema named sales. The user alice has been granted USAGE on the sales schema but no other privileges. What will be the result of the following query when run by alice?
SELECT * FROM sales.orders;
GRANT USAGE ON SCHEMA sales TO alice; -- alice runs: SELECT * FROM sales.orders;
USAGE on a schema allows access to the schema itself but not to the tables inside it.
Granting USAGE on a schema allows the user to access objects in the schema if they have privileges on those objects. Since alice has no SELECT privilege on sales.orders, the query fails with a permission denied error.
In PostgreSQL, to create new tables inside an existing schema, which privilege must a user have on that schema?
Think about what permission allows adding new objects inside a schema.
The CREATE privilege on a schema allows a user to create new objects such as tables within that schema. USAGE alone does not allow creation.
Which of the following commands correctly grants SELECT privilege on all current tables in the inventory schema to user bob?
Look for the exact phrase used in PostgreSQL to grant privileges on all tables in a schema.
The correct syntax is GRANT SELECT ON ALL TABLES IN SCHEMA inventory TO bob;. Other options are either invalid or grant privileges on the schema itself, not the tables.
You want user carol to have SELECT access on all current and future tables in the reports schema. Which approach achieves this with minimal ongoing maintenance?
Think about how to automate privileges for tables created later.
Granting USAGE on the schema plus setting ALTER DEFAULT PRIVILEGES to grant SELECT on future tables ensures carol automatically gets access to new tables without manual grants.
User dave runs the following commands:
GRANT USAGE ON SCHEMA analytics TO dave; SELECT * FROM analytics.events;
But he gets an error: permission denied for relation events. Why?
Consider what USAGE on a schema actually allows.
USAGE on a schema allows access to the schema namespace but does not grant any rights on the tables inside. Dave needs explicit SELECT privilege on analytics.events to query it.