Overview
Oxla supportsGRANT and REVOKE to manage privileges on database objects. Privileges can be assigned to a role for tables, schemas and database.
Available Privileges
In the table below, you can read about all available privileges:| Privilege | Description | Database Objects |
|---|---|---|
| CONNECT | Allows a role to connect to the database | database |
| USAGE | Allows access to objects within the schema, provided the objects’ own privilege requirements are also met | schema |
| CREATE | Allows creating tables and types in a schema. CREATE INDEX requires ownership of the table and both CREATE and USAGE privilege on the schema | schema |
| SELECT | Allows selecting data from a table | table |
| INSERT | Allows inserting data into a table | table |
| UPDATE | Allows updating data in a table | table |
| DELETE | Allows deleting and truncating data from a table Allows | table |
USAGE privilege is required to see what objects (tables / types / indices) exist inside the schema. Unless the user has such a privilege, they will get does not exist error on accessing any objects in the schema, even if the object exists. It is also required to look up tables using search_path. In case of objects listed by tables in information_schema.tables and pg_catalog.pg_class schemas but also other metatables user can see these objects when they either have USAGE on schema or any grant on the object itself.
The only exception to this rule is information_schema.role_table_grants table - if a user has any grant on a table, but does not have USAGE grant to this table, on parent schema, this grant will still be visible in the information_schema.role_table_grants table.
There is an
ALL PRIVILEGES alias representing all available privileges for a given database object.
By default, every new role has CONNECT privilege on the database and USAGE privilege on the default public schema.
See the Default Privileges section for details.- Only superuser can read
pg_authidandpg_shadowtables frompg_catalogand can access resources inoxla_internal - Anyone can read other resources in:
pg_catalog,information_schema,system - No one can modify:
pg_catalog,information_schema,system,oxla_internal
Checking Privileges
To check privileges on tables, database or schemas, a superuser needs to execute the following commands:-
Table privileges
Example output:
-
Database privileges
Example output:
-
Schema privileges
Example output:
id: role IDdatabase: database nameschema: schema nametable: table nameprivilege: privilege granted on a given object
Granting Privilege
To grant privileges, execute the following command:privilege: one or more privileges from the available listobject_name: name of the object on which the privileges are being grantedrole_name: name of the role to which the privileges are being granted
If
TABLE, SCHEMA or DATABASE keyword is omitted, TABLE keyword is assumed.Revoking Privileges
Here’s the code that needs to be run, in order to revoke a privilege:privilege: one or more privileges from the list of available privilegesobject_name: name of the object on which the privileges are being revokedrole_name: name of the role from which the privileges are being revoked, or keyword CURRENT_ROLE/CURRENT_USER
If
TABLE, SCHEMA or DATABASE keyword is omitted, TABLE keyword is assumed.Default Privileges
By default, every created role has the following privileges:CONNECT: privilege on the default databaseUSAGE: privilege on the defaultpublicschema
- A user without the
CONNECTprivilege cannot connect to the database - A user without the
USAGEprivilege cannot access the defaultpublicschema