Privileges
Overview
Oxla supports GRANT
and REVOKE
to manage privileges on database objects. Privileges can be assigned to a role for tables, schemas and database. They cannot be granted to or revoked from a superuser.
GRANT
or REVOKE
on the superuser does not change anythingAvailable Privileges
In the table below, you can read about all available privileges:
Privilege | Description | Database Objects |
---|---|---|
SELECT | Allows SELECT on a given table | table |
INSERT | Allows INSERT to a given table | table |
UPDATE | Allows UPDATE on a given table | table |
DELETE | Allows DELETE and TRUNCATE from a given table | table |
CONNECT | Allows role to connect to the database | database |
CREATE | Allows to CREATE tables and types in a given schema. CREATE INDEX requires ownership of the table and both CREATE and USAGE privilege on the schema | schema |
USAGE | Allows to access objects within the schema, provided the objects’ own privilege requirements are also satisfied | schema |
USAGE Privilege Essentials
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.
ALL PRIVILEGES
alias, which stands for all available privileges for a given database object. By default, every new role has CONNECT
privilege to a database and USAGE
privilege to public
schema. For more details on that, please refer to the Default Privileges sectionSchemas and Tables
- Only superuser can read
pg_authid
andpg_shadow
tables frompg_catalog
and can access resources inoxla_internal
- Anyone can read other resources in:
pg_catalog
,information_schema
,system
- Nobody 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
- Database
- Schema
Here’s the breakdown of the above outputs:
id
: role iddatabase
: database nameschema
: schema nametable
: table nameprivilege
: privilege for a given object
Granting Privilege
In order to grant a privilege, one needs to execute the following command:
where:
privilege
: one or more privileges from the list of available privilegesobject_name
: name of the object on which the privileges are being grantedrole_name
: name of the role to which the privileges are being granted
TABLE
, SCHEMA
or DATABASE
keyword, TABLE
keyword is being assumedRevoking Privilege
Here’s the code that needs to be run, in order to revoke a privilege:
where:
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
TABLE
, SCHEMA
or DATABASE
keyword, TABLE
keyword is assumedDefault Privileges
By default, every created role has the following privileges:
CONNECT
: privilege to a default databaseUSAGE
: privilege to apublic
schema
Default privileges can be revoked at any time with the following query:
- User with revoked
CONNECT
privilege won’t be able to connect to the database - User with revoked
USAGE
privilege won’t be able to access thepublic
schema