Operations with users
-
CREATE USER— Create a new user -
ALTER USER— Change user attributes -
DROP USER— Reset user -
DESCRIBE USER— Output information about the user -
SHOW USERS— Output a list of all users -
GRANT ROLE— Assign roles to users -
REVOKE ROLE— Revoke roles from users
Create a new user
CREATE [OR REPLACE] USER [IF NOT EXISTS] <user_name>
DEFAULT WORKER POOL <pool_id>
IDENTIFIED BY (TRUST <ip_address> | PASSWORD '<user_password>')
[DEFAULT SCHEMA <schema_name>]
[SELECT LIMIT <limit>]
[QUERY TIMEOUT <timeout>]
[SPILL SIZE '<size>'];
Creates a new user with the specified name and other parameters.
Parameter SET DEFAULT WORKER POOL
The obligatory parameter SET DEFAULT WORKER POOL <pool_id> sets the default compute pool <pool_id> for the specified user.
Parameter IDENTIFIED BY
The obligatory parameter IDENTIFIED BY ... specifies authentication of the created user in one of two ways:
-
via IP address
IDENTIFIED BY TRUST <ip_address> -
via password
IDENTIFIED BY PASSWORD '<user_password>'(using theSCRAM-SHA-256algorithm)
Parameter DEFAULT SCHEMA
The optional parameter DEFAULT SCHEMA sets the default schema for the user being created. This schema will be used by default when the user being created queries tables without explicitly specifying a schema.
| The default schema can be set for the current session: Set default schema. |
Parameter SELECT LIMIT
The optional SELECT LIMIT parameter sets the default limit for the results of SELECT queries for the user being created. The default limit (if not set) is 1000.
This limit applies to all SELECT queries that don’t explicitly specify a limit, with the exception of nested SELECT queries (they have no limit).
|
| Increasing the limit can be useful, for example, for the user whose account is running a BI system if it produces large datasets for visualizations. |
Parameter QUERY TIMEOUT
The optional parameter QUERY TIMEOUT sets the timeout value for executing SQL queries for the user being created. The value is specified in seconds.
The default timeout value is 3600.
Parameter SPILL SIZE
The optional parameter SPILL SIZE sets the spill size (the amount of disk space used to store intermediate query results) for the user being created. The value is specified as a text string in quotation marks with indicated memory units.
The default spill size is 200GB.
Modifier OR REPLACE
If the optional OR REPLACE modifier is specified, this action is equivalent to deleting the current user and creating a new user with the same username.
the current user and creating a new user with the same username. The newly created user does not inherit any roles or attributes.
Modifier IF NOT EXISTS
If the optional IF NOT EXISTS modifier is specified, the query will only be executed if the user named <user_name> does not exist, otherwise nothing will happen.
The OR REPLACE and IF NOT EXISTS modifiers are mutually exclusive. Specifying them both will result in an error.
|
See example
CREATE USER tengri_user
DEFAULT WORKER POOL client_compute
IDENTIFIED BY TRUST '127.0.0.1'
DEFAULT SCHEMA demo
SELECT LIMIT 1000000
QUERY TIMEOUT 7200
SPILL SIZE '400GB';
Privileges of a newly created user
After creation, a new user has the following privileges:
-
USAGE,CREATE TABLE, andALLon all existing and future tables and views in the following schemas:-
public -
raw -
the user’s default schema (if one was specified)
-
-
USAGEandALLon all existing and future tables and views in the following schemas:-
temp -
pg_catalog -
system -
information_schema
-
-
USAGEon the user’s default compute pool
Change user attributes
ALTER USER [IF EXISTS] <user_name>
RENAME TO <new_name>;
ALTER USER [IF EXISTS] <user_name>
SET DEFAULT WORKER POOL <pool_id>;
ALTER USER [IF EXISTS] <user_name>
IDENTIFIED BY TRUST <ip_address>;
ALTER USER [IF EXISTS] <user_name>
IDENTIFIED BY PASSWORD '<user_password>';
ALTER USER [IF EXISTS] <user_name>
DEFAULT SCHEMA <schema_name>;
ALTER USER [IF EXISTS] <user_name>
SELECT LIMIT <limit>;
Modifies the user’s attributes:
-
RENAME TO <new_name>is an atomic operation that renames the user to a new name. No other properties of this user (roles granted, privileges, etc.) are changed. -
SET DEFAULT WORKER POOL <pool_id>— see ParameterSET DEFAULT WORKER POOL. -
IDENTIFIED BY TRUST <ip_address>— see ParameterIDENTIFIED BY. -
IDENTIFIED BY PASSWORD '<user_password>'— see ParameterIDENTIFIED BY. -
DEFAULT SCHEMA <schema_name>— see ParameterDEFAULT SCHEMA. -
SELECT LIMIT <limit>— see ParameterSELECT LIMIT. -
QUERY TIMEOUT <timeout>— see ParameterQUERY TIMEOUT. -
SPILL SIZE '<size>'— see ParameterSPILL SIZE.
The optional IF EXISTS modifier restricts the query to only those cases in which the specified object exists.
See example
ALTER USER tengri_user
DEFAULT WORKER POOL client_compute
IDENTIFIED BY PASSWORD 'CHANGE-ME!'
DEFAULT SCHEMA demo
SELECT LIMIT 1000000
QUERY TIMEOUT 7200
SPILL SIZE '400GB';
Reset user
DROP USER [IF EXISTS] <user_name>;
Completely removes the user from the system.
Nothing is saved, including granted roles and access rights.
| It is possible that some objects may lose access rights. |
The optional IF EXISTS modifier restricts the query to only those cases in which the specified object exists.
Output information about the user
DESC[RIBE] USER <user_name>;
Outputs all information about the user, including their attributes and default values.
Output a list of all users
SHOW USERS;
Outputs a list of all users with their attributes.
Output format:
+------+---------------------+----------------+------------------+-------------+--------+--------+---------------+------------+--------------+
| name | default_worker_pool | default_schema | active_workspace | auth_method | active | system | query_timeout | spill_size | select_limit |
+------+---------------------+----------------+------------------+-------------+--------+--------+---------------+------------+--------------+
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
+------+---------------------+----------------+------------------+-------------+--------+--------+---------------+------------+--------------+