Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
There are multiple ways to run statements with specific settings. Settings are configured in layers, and each subsequent layer redefines the previous values of a setting.Order of priority
The order of priority for defining a setting is:-
Applying a setting to a user directly, or within a settings profile
- SQL (recommended)
- adding one or more XML or YAML files to
/etc/clickhouse-server/users.d
-
Session settings
- Send
SET setting=valuefrom the ClickHouse Cloud SQL console orclickhouse clientin interactive mode. Similarly, you can use ClickHouse sessions in the HTTP protocol. To do this, you need to specify thesession_idHTTP parameter.
- Send
-
Query settings
- When starting
clickhouse clientin non-interactive mode, set the startup parameter--setting=value. - When using the HTTP API, pass CGI parameters (
URL?setting_1=value&setting_2=value...). - Define settings in the SETTINGS clause of the SELECT query. The setting value is applied only to that query and is reset to the default or previous value after the query is executed.
- When starting
Converting a setting to its default value
If you change a setting and would like to revert it back to its default value, set the value toDEFAULT. The syntax looks like:
async_insert is 0. Suppose you change its value to 1:
Custom settings
In addition to the common settings, users can define custom settings. Custom settings enable you to pass session-specific parameters that can be referenced within queries, policies, or functions. This is useful when you need to:- Filter data based on user identity or organization
- Apply different business logic based on context
- Maintain stateful information across queries in a session
custom_settings_prefixes server setting, defined in your server configuration file.
In the example below, SQL_ is chosen as the custom prefix:
In ClickHouse Cloud it is not possible to specify a custom prefix.
All custom user settings begin with prefix
SQL_.SET command:
getSetting() function:
Examples
These examples all set the value of theasync_insert setting to 1, and
show how to examine the settings in a running system.
Using SQL to apply a setting to a user directly
This creates the useringester with the setting async_inset = 1:
Examine the settings profile and assignment
Using SQL to create a settings profile and assign to a user
This creates the profilelog_ingest with the setting async_inset = 1:
ingester and assigns the user the settings profile log_ingest:
Using XML to create a settings profile and user
/etc/clickhouse-server/users.d/users.xml
Examine the settings profile and assignment
Assign a setting to a session
Assign a setting during a query
See also
- View the Settings page for a description of the ClickHouse settings.
- Global server settings