SET ROLE in the ClickHouse Cloud SQL Console, the role might appear to change for one query and then revert for the next query. Use a per-user SQL Console role when permissions must persist across queries and sessions.
Symptoms
You might observe one or more of the following:- After you run
SET ROLE sql_console_developer, later queries still run withsql_console_read_only. - The results of
currentRoles,enabledRoles, anddefaultRolesvary between queries. - Running
SET ROLEand another query together does not consistently preserve the selected role. SHOW GRANTSlists the expected roles, but their permissions are not active.
Why this happens
The SQL Console sends queries over stateless HTTP connections to a multi-replica ClickHouse Cloud service. Consecutive queries are not guaranteed to use the same connection or replica.SET ROLE changes the roles enabled for the current session. It does not persist that session state for later SQL Console requests. A subsequent query can therefore run without the role that an earlier request enabled.
For this reason, do not use SET ROLE as a persistent access-control mechanism in the SQL Console.
How SQL Console user roles work
When a user opens the SQL Console, ClickHouse Cloud provisions a database user with the following naming convention:Configure persistent permissions
Run the following statements as a user with administrative privileges on the service, such as a SQL Console user with thesql_console_admin role or another user with the ACCESS MANAGEMENT privilege.
1
Create the custom role
The following example creates a custom
sql_console_developer role and grants it permissions on my_database:sql_console_developer is an example role, not a built-in ClickHouse Cloud role. You can instead use an existing custom role with the permissions that the user requires.2
Create the per-user SQL Console role
Create a role whose name contains the user’s exact email address:The backticks are required because the role name contains special characters.
3
Grant the custom role
Grant the desired role to the per-user SQL Console role:You can grant multiple roles when needed:
4
Start a new SQL Console session
Ask the user to sign out and sign back in to the SQL Console, or refresh the browser tab. In the new session, ClickHouse Cloud applies The results should include the permissions granted through
sql-console-role:user@example.com to sql-console:user@example.com; no SET ROLE statement is required.Verify the active roles:sql-console-role:user@example.com.Avoid modifying managed roles
Do not modifysql_console_admin or sql_console_read_only to grant custom permissions. ClickHouse Cloud manages these built-in roles. Use sql-console-role:<email> for per-user permissions instead.
For general role-management examples, see Common access management queries.