> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SET {session variable}

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `SET` <InternalLink path="sql-statements">statement</InternalLink> can modify one of the session configuration variables. These can also be queried via <InternalLink path="show-vars">`SHOW`</InternalLink>. By default, session variable values are set for all future sessions to the database; they do not affect the current session.

<Note>
  The `SET` statement for session variables is unrelated to the other <InternalLink path="set-transaction">`SET TRANSACTION`</InternalLink> and <InternalLink path="cluster-settings#change-a-cluster-setting">`SET CLUSTER SETTING`</InternalLink> statements.
</Note>

<Danger>
  In some cases, client drivers can drop and restart the connection to the server. When this happens, any session configurations made with `SET` statements are lost. It is therefore more reliable to configure the session in the client's connection string. For examples in different languages, see the <InternalLink path="example-apps">Build an App with CockroachDB</InternalLink> tutorials.
</Danger>

## Required privileges

To set the `role` session variable, the current user must be a member of the `admin` role, or a member of the target role.

All other session variables do not require <InternalLink path="security-reference/authorization#managing-privileges">privileges</InternalLink> to modify.

## Synopsis

The `SET` statement can set a session variable for the duration of the current session ([`SET {variable}`/`SET SESSION {variable}`](#set-session)), or for the duration of a single transaction ([`SET LOCAL {variable}`](#set-local)).

### SET SESSION

<img src="https://mintcdn.com/cockroachlabs/_CYD-gPJn4sApGw_/images/sql-diagrams/v25.1/set_session.svg?fit=max&auto=format&n=_CYD-gPJn4sApGw_&q=85&s=99ef150f6eb30ccb114b0125674aa568" alt="set_session syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="589" height="125" data-path="images/sql-diagrams/v25.1/set_session.svg" />

<Note>
  By default, session variables are set for the duration of the current session. As a result, [`SET {variable}` and `SET SESSION {variable}`](#set-session) are equivalent.
</Note>

### SET LOCAL

<img src="https://mintcdn.com/cockroachlabs/_CYD-gPJn4sApGw_/images/sql-diagrams/v25.1/set_local.svg?fit=max&auto=format&n=_CYD-gPJn4sApGw_&q=85&s=b074b24c8507ae36be70d6b4408a4d63" alt="set_local syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="531" height="125" data-path="images/sql-diagrams/v25.1/set_local.svg" />

<Note>
  `SET LOCAL` is compatible with <InternalLink path="savepoint">savepoints</InternalLink>. Executing a <InternalLink path="rollback-transaction">`ROLLBACK`</InternalLink>, `ROLLBACK TO SAVEPOINT`, or `RELEASE TO SAVEPOINT` statement rolls back any variables set by `SET LOCAL`.
</Note>

## Parameters

| Parameter   | Description                                                                                             |
| ----------- | ------------------------------------------------------------------------------------------------------- |
| `var_name`  | The name of [the session variable](#supported-variables) to set. The variable name is case-insensitive. |
| `var_value` | The value, or list of values, to assign to the session variable.                                        |

### Supported variables

| Variable name                                                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Initial value                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Modify with <InternalLink path="set-vars">`SET`</InternalLink>?                                                                                                | View with <InternalLink path="show-vars">`SHOW`</InternalLink>? |     |
| ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | --- |
| <a id="always-distribute-full-scans" />                             | `always_distribute_full_scans`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | **New in v25.1:** When set to `on`, full table scans are always <InternalLink path="architecture/sql-layer#distsql">distributed</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="application-name" />                                         | `application_name`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | The current application name for statistics collection.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Empty string, or `cockroach` for sessions from the <InternalLink path="cockroach-sql">built-in SQL client</InternalLink>.                                      | Yes                                                             | Yes |
| `autocommit_before_ddl`                                             | When the <InternalLink path="set-vars">`autocommit_before_ddl` session setting</InternalLink> is set to `on`, any schema change statement that is sent during an <InternalLink path="transactions">explicit transaction</InternalLink> will cause the transaction to <InternalLink path="commit-transaction">commit</InternalLink> before executing the schema change. This is useful because <InternalLink path="online-schema-changes">CockroachDB does not fully support multiple schema changes in a single transaction</InternalLink>. **New in v25.1**: This setting is enabled by default. To disable it for all <InternalLink path="alter-role#set-default-session-variable-values-for-all-users">roles</InternalLink>, issue the following statement: `ALTER ROLE ALL SET autocommit_before_ddl = false` | `on`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Yes                                                                                                                                                            | Yes                                                             |     |
| `bytea_output`                                                      | The <InternalLink path="bytes#supported-conversions">mode for conversions from `STRING` to `BYTES`</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | hex                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Yes                                                                                                                                                            | Yes                                                             |     |
| <a id="client-min-messages" />                                      | `client_min_messages`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | The severity level of notices displayed in the <InternalLink path="cockroach-sql">SQL shell</InternalLink>. Accepted values include `debug5`, `debug4`, `debug3`, `debug2`, `debug1`, `log`, `notice`, `warning`, and `error`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `notice`                                                                                                                                                       | Yes                                                             | Yes |
| <a id="copy-from-atomic-enabled" />                                 | `copy_from_atomic_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | If set to `on`, <InternalLink path="copy">`COPY FROM`</InternalLink> statements are committed atomically, matching PostgreSQL behavior. If set to `off`, `COPY FROM` statements are segmented into batches of 100 rows unless issued within an explicit transaction, matching the CockroachDB behavior in versions prior to v22.2.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="copy-transaction-quality-of-service" />                      | `copy_transaction_quality_of_service`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | The default quality of service for <InternalLink path="copy">`COPY`</InternalLink> statements in the current session. The supported options are `regular`, `critical`, and `background`. See <InternalLink path="admission-control">Set quality of service level</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | `background`                                                                                                                                                   | Yes                                                             | Yes |
| <a id="cost-scans-with-default-col-size" />                         | `cost_scans_with_default_col_size`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Whether to prevent the optimizer from considering column size when costing plans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `false`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="crdb-version" />                                             | `crdb_version`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The version of CockroachDB.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `CockroachDB OSS version`                                                                                                                                      | No                                                              | Yes |
| `database`                                                          | The <InternalLink path="sql-name-resolution#current-database">current database</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Database in connection string, or empty if not specified.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Yes                                                                                                                                                            | Yes                                                             |     |
| <a id="datestyle" />                                                | `datestyle`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The input string format for <InternalLink path="date">`DATE`</InternalLink> and <InternalLink path="timestamp">`TIMESTAMP`</InternalLink> values. Accepted values include `ISO,MDY`, `ISO,DMY`, and `ISO,YMD`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The value set by the `sql.defaults.datestyle` <InternalLink path="cluster-settings">cluster setting</InternalLink> (`ISO,MDY`, by default).                    | Yes                                                             | Yes |
| <a id="default-int-size" />                                         | `default_int_size`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | The size, in bytes, of an <InternalLink path="int">`INT`</InternalLink> type.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `8`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="default-text-search-config" />                               | `default_text_search_config`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | The dictionary used to normalize tokens and eliminate stop words when calling a <InternalLink path="functions-and-operators">full-text search function</InternalLink> without a configuration parameter. See <InternalLink path="full-text-search">Full-Text Search</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | `english`                                                                                                                                                      | Yes                                                             | Yes |
| <a id="default-transaction-isolation" />                            | `default_transaction_isolation`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | The isolation level at which transactions in the session execute (<InternalLink path="demo-serializable">`SERIALIZABLE`</InternalLink> or <InternalLink path="read-committed">`READ COMMITTED`</InternalLink>). See <InternalLink path="transactions#isolation-levels">Isolation levels</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | `SERIALIZABLE`                                                                                                                                                 | Yes                                                             | Yes |
| <a id="default-transaction-priority" />                             | `default_transaction_priority`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The default transaction priority for the current session. The supported options are `low`, `normal`, and `high`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | `normal`                                                                                                                                                       | Yes                                                             | Yes |
| <a id="default-transaction-quality-of-service" />                   | `default_transaction_quality_of_service`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | The default transaction quality of service for the current session. The supported options are `regular`, `critical`, and `background`. See <InternalLink path="admission-control#set-quality-of-service-level-for-a-session">Set quality of service level</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `regular`                                                                                                                                                      | Yes                                                             | Yes |
| <a id="default-transaction-read-only" />                            | `default_transaction_read_only`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | The default transaction access mode for the current session. <br />If set to `on`, only read operations are allowed in transactions in the current session; if set to `off`, both read and write operations are allowed. See <InternalLink path="set-transaction">`SET TRANSACTION`</InternalLink> for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="default-transaction-use-follower-reads" />                   | `default_transaction_use_follower_reads`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | If set to on, all read-only transactions use <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME follower_read_timestamp()`</InternalLink> to allow the transaction to use follower reads. <br />If set to `off`, read-only transactions will only use follower reads if an `AS OF SYSTEM TIME` clause is specified in the statement, with an interval of at least 4.8 seconds.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="disable-changefeed-replication" />                           | `disable_changefeed_replication`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | When `true`, <InternalLink path="changefeed-messages#filtering-changefeed-messages">changefeeds</InternalLink> will not emit messages for any changes (e.g., `INSERT`, `UPDATE`) issued to watched tables during that session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `false`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="disallow-full-table-scans" />                                | `disallow_full_table_scans`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | If set to `on`, queries on "large" tables with a row count greater than [`large_full_scan_rows`](#large-full-scan-rows) will not use full table or index scans. If no other query plan is possible, queries will return an error message. This setting does not apply to internal queries, which may plan full table or index scans without checking the session variable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="distribute-group-by-row-count-threshold" />                  | `distribute_group_by_row_count_threshold`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | **New in v25.1:** Minimum number of rows that a `GROUP BY` operation must process in order to be <InternalLink path="architecture/sql-layer#distsql">distributed</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | `1000`                                                                                                                                                         | Yes                                                             | Yes |
| <a id="distribute-scan-row-count-threshold" />                      | `distribute_scan_row_count_threshold`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **New in v25.1:** Minimum number of rows that a scan operation must process in order to be <InternalLink path="architecture/sql-layer#distsql">distributed</InternalLink>. This means that full table scans will not be distributed if they read fewer than this number of rows. To always distribute full table scans, set [`always_distribute_full_scans`](#always-distribute-full-scans).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `10000`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="distribute-sort-row-count-threshold" />                      | `distribute_sort_row_count_threshold`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | **New in v25.1:** Minimum number of rows that a sort operation must process in order to be <InternalLink path="architecture/sql-layer#distsql">distributed</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `1000`                                                                                                                                                         | Yes                                                             | Yes |
| <a id="distsql" />                                                  | `distsql`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | The query distribution mode for the session. By default, CockroachDB determines which queries are faster to execute if distributed across multiple nodes. Distribution preferences for `GROUP BY`, scan, and sort operations are set with [`distribute_group_by_row_count_threshold`](#distribute-group-by-row-count-threshold), [`distribute_scan_row_count_threshold.`](#distribute-scan-row-count-threshold) and [`distribute_sort_row_count_threshold.`](#distribute-sort-row-count-threshold), respectively. All other queries are run through the gateway node.                                                                                                                                                                                                                                                                                                                                                                                                             | `auto`                                                                                                                                                         | Yes                                                             | Yes |
| <a id="enable-auto-rehoming" />                                     | `enable_auto_rehoming`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | When enabled, the <InternalLink path="alter-table">home regions</InternalLink> of rows in <InternalLink path="alter-table#set-the-table-locality-to-regional-by-row">`REGIONAL BY ROW`</InternalLink> tables are automatically set to the region of the <InternalLink path="ui-sessions-page">gateway node</InternalLink> from which any <InternalLink path="update">`UPDATE`</InternalLink> or <InternalLink path="upsert">`UPSERT`</InternalLink> statements that operate on those rows originate.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enable-create-stats-using-extremes" />                       | `enable_create_stats_using_extremes`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | If `on`, allows manual creation of <InternalLink path="cost-based-optimizer#partial-statistics">partial statistics</InternalLink> using the <InternalLink path="create-statistics#create-partial-statistics-using-extremes">`CREATE STATISTICS ... USING EXTREMES`</InternalLink> syntax.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="enable-durable-locking-for-serializable" />                  | `enable_durable_locking_for_serializable`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Indicates whether CockroachDB replicates <InternalLink path="select-for-update#lock-strengths">`FOR UPDATE` and `FOR SHARE`</InternalLink> locks via <InternalLink path="architecture/replication-layer#raft">Raft</InternalLink>, allowing locks to be preserved when leases are transferred. Note that replicating `FOR UPDATE` and `FOR SHARE` locks will add latency to those statements. This setting only affects `SERIALIZABLE` transactions and matches the default `READ COMMITTED` behavior when enabled.                                                                                                                                                                                                                                                                                                                                                                                                                                                               | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enable-implicit-fk-locking-for-serializable" />              | `enable_implicit_fk_locking_for_serializable`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Indicates whether CockroachDB uses <InternalLink path="select-for-update#lock-strengths">shared locks</InternalLink> to perform <InternalLink path="foreign-key">foreign key</InternalLink> checks. To take effect, the [`enable_shared_locking_for_serializable`](#enable-shared-locking-for-serializable) setting must also be enabled. This setting only affects `SERIALIZABLE` transactions and matches the default `READ COMMITTED` behavior when enabled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enable-implicit-select-for-update" />                        | `enable_implicit_select_for_update`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Indicates whether <InternalLink path="update">`UPDATE`</InternalLink>, <InternalLink path="upsert">`UPSERT`</InternalLink>, and <InternalLink path="delete">`DELETE`</InternalLink> statements acquire locks using the `FOR UPDATE` locking mode during their initial row scan, which improves performance for contended workloads.<br /><br />For more information about how `FOR UPDATE` locking works, see the documentation for <InternalLink path="select-for-update">`SELECT FOR UPDATE`</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="enable-implicit-transaction-for-batch-statements" />         | `enable_implicit_transaction_for_batch_statements`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Indicates whether multiple statements in a single query (a "batch statement") will all run in the same implicit transaction, which matches the PostgreSQL wire protocol.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="enable-insert-fast-path" />                                  | `enable_insert_fast_path`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Indicates whether CockroachDB will use a specialized execution operator for inserting into a table. We recommend leaving this setting `on`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="enable-shared-locking-for-serializable" />                   | `enable_shared_locking_for_serializable`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Indicates whether <InternalLink path="select-for-update#lock-strengths">shared locks</InternalLink> are enabled for `SERIALIZABLE` transactions. When `off`, `SELECT` statements using `FOR SHARE` are still permitted under `SERIALIZABLE` isolation, but silently do not lock.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enable-super-regions" />                                     | `enable_super_regions`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | When enabled, you can define a super region: a set of <InternalLink path="multiregion-overview#super-regions">database regions</InternalLink> on a multi-region cluster such that your <InternalLink path="schema-design-overview#database-schema-objects">schema objects</InternalLink> will have all of their <InternalLink path="architecture/overview">replicas</InternalLink> stored *only* in regions that are members of the super region.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enable-zigzag-join" />                                       | `enable_zigzag_join`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Indicates whether the <InternalLink path="cost-based-optimizer">cost-based optimizer</InternalLink> will plan certain queries using a <InternalLink path="cost-based-optimizer#zigzag-joins">zigzag merge join algorithm</InternalLink>, which searches for the desired intersection by jumping back and forth between the indexes based on the fact that after constraining indexes, they share an ordering.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="enforce-home-region" />                                      | `enforce_home_region`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | If set to `on`, queries return an error and in some cases a suggested resolution if they cannot run entirely in their home region. This can occur if a query has no home region (for example, if it reads from different home regions in a <InternalLink path="table-localities#regional-by-row-tables">regional by row table</InternalLink>) or a query's home region differs from the <InternalLink path="architecture/life-of-a-distributed-transaction#gateway">gateway</InternalLink> region. Note that only tables with `ZONE` <InternalLink path="multiregion-survival-goals#when-to-use-zone-vs-region-survival-goals">survivability</InternalLink> can be scanned without error when this is enabled. For more information about home regions, see <InternalLink path="multiregion-overview#table-localities">Table localities</InternalLink>.<br /><br />This feature is in preview. It is subject to change.                                                           | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="enforce-home-region-follower-reads-enabled" />               | `enforce_home_region_follower_reads_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | If `on` while the <InternalLink path="cost-based-optimizer#control-whether-queries-are-limited-to-a-single-region">`enforce_home_region`</InternalLink> setting is `on`, allows `enforce_home_region` to perform `AS OF SYSTEM TIME` <InternalLink path="follower-reads">follower reads</InternalLink> to detect and report a query's <InternalLink path="multiregion-overview#table-localities">home region</InternalLink>, if any.<br /><br />This feature is in preview. It is subject to change.                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="expect-and-ignore-not-visible-columns-in-copy" />            | `expect_and_ignore_not_visible_columns_in_copy`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | If `on`, <InternalLink path="copy">`COPY FROM`</InternalLink> with no column specifiers will assume that hidden columns are in the copy data, but will ignore them when applying `COPY FROM`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="extra-float-digits" />                                       | `extra_float_digits`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | The number of digits displayed for floating-point values. Only values between `-15` and `3` are supported.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="force-savepoint-restart" />                                  | `force_savepoint_restart`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | When set to `true`, allows the <InternalLink path="savepoint">`SAVEPOINT`</InternalLink> statement to accept any name for a savepoint.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="foreign-key-cascades-limit" />                               | `foreign_key_cascades_limit`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Limits the number of <InternalLink path="foreign-key#use-a-foreign-key-constraint-with-cascade">cascading operations</InternalLink> that run as part of a single query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | `10000`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="idle-in-session-timeout" />                                  | `idle_in_session_timeout`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Automatically terminates sessions that idle past the specified threshold.<br /><br />When set to `0`, the session will not timeout.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | The value set by the `sql.defaults.idle_in_session_timeout` <InternalLink path="cluster-settings">cluster setting</InternalLink> (`0s`, by default).           | Yes                                                             | Yes |
| <a id="idle-in-transaction-session-timeout" />                      | `idle_in_transaction_session_timeout`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Automatically terminates sessions that are idle in a transaction past the specified threshold.<br /><br />When set to `0`, the session will not timeout.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | The value set by the `sql.defaults.idle_in_transaction_session_timeout` <InternalLink path="cluster-settings">cluster setting</InternalLink> (0s, by default). | Yes                                                             | Yes |
| <a id="index-recommendations-enabled" />                            | `index_recommendations_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | If `true`, display recommendations to create indexes required to eliminate full table scans. <br />For more details, see <InternalLink path="explain#default-statement-plans">Default statement plans</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | `true`                                                                                                                                                         | Yes                                                             | Yes |
| <a id="inject-retry-errors-enabled" />                              | `inject_retry_errors_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | If `true`, any statement executed inside of an explicit transaction (with the exception of <InternalLink path="set-vars">`SET`</InternalLink> statements) will return a transaction retry error. If the client retries the transaction using the special <InternalLink path="savepoint#savepoints-for-client-side-transaction-retries">`cockroach_restart SAVEPOINT` name</InternalLink>, after the 3rd retry error, the transaction will proceed as normal. Otherwise, the errors will continue until `inject_retry_errors_enabled` is set to `false`. For more details, see <InternalLink path="transaction-retry-error-example#test-transaction-retry-logic">Test transaction retry logic</InternalLink>.                                                                                                                                                                                                                                                                      | `false`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="intervalstyle" />                                            | `intervalstyle`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | The input string format for <InternalLink path="interval">`INTERVAL`</InternalLink> values. Accepted values include `postgres`, `iso_8601`, and `sql_standard`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | The value set by the `sql.defaults.intervalstyle` <InternalLink path="cluster-settings">cluster setting</InternalLink> (`postgres`, by default).               | Yes                                                             | Yes |
| <a id="is-superuser" />                                             | `is_superuser`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | If `on` or `true`, the current user is a member of the <InternalLink path="security-reference/authorization#admin-role">`admin` role</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | User-dependent                                                                                                                                                 | No                                                              | Yes |
| <a id="large-full-scan-rows" />                                     | `large_full_scan_rows`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Determines which tables are considered "large" such that `disallow_full_table_scans` rejects full table or index scans of "large" tables. The default value is `0`, which disallows all full table or index scans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | User-dependent                                                                                                                                                 | No                                                              | Yes |
| <a id="legacy-varchar-typing" />                                    | `legacy_varchar_typing`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | **New in v25.1:** If `on`, type checking and overload resolution for <InternalLink path="string#related-types">`VARCHAR`</InternalLink> types ignore overloads that cause errors, allowing comparisons between `VARCHAR` and non-`STRING`-like placeholder values to execute successfully. If `off`, type checking of these comparisons is more strict and must be handled with explicit type casts.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `off`                                                                                                                                                          | Yes                                                             | Yes |
| `locality`                                                          | The location of the node.<br />\</br>For more information, see <InternalLink path="cockroach-start#locality">Locality</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Node-dependent                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | No                                                                                                                                                             | Yes                                                             |     |
| <a id="lock-timeout" />                                             | `lock_timeout`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The amount of time a query can spend acquiring or waiting for a single <InternalLink path="architecture/transaction-layer#concurrency-control">row-level lock</InternalLink>. <br />In CockroachDB, unlike in PostgreSQL, non-locking reads wait for conflicting locks to be released. As a result, the `lock_timeout` configuration applies to writes, and to locking and non-locking reads in read-write and read-only transactions. <br />If `lock_timeout = 0`, queries do not timeout due to lock acquisitions.                                                                                                                                                                                                                                                                                                                                                                                                                                                              | The value set by the `sql.defaults.lock_timeout` <InternalLink path="cluster-settings">cluster setting</InternalLink> (`0`, by default)                        | Yes                                                             | Yes |
| <a id="multiple-active-portals-enabled" />                          | `multiple_active_portals_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | Whether to enable the <InternalLink path="postgresql-compatibility#multiple-active-portals">multiple active portals</InternalLink> pgwire feature.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `false`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="node-id" />                                                  | `node_id`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | The ID of the node currently connected to. <br /><br />This variable is particularly useful for verifying load balanced connections.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Node-dependent                                                                                                                                                 | No                                                              | Yes |
| <a id="null-ordered-last" />                                        | `null_ordered_last`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Set the default ordering of `NULL`s. The default order is `NULL`s first for ascending order and `NULL`s last for descending order.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `false`                                                                                                                                                        | Yes                                                             | Yes |
| <a id="optimizer-merge-joins-enabled" />                            | `optimizer_merge_joins_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | If `on`, the optimizer will explore query plans with merge joins.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="optimizer-push-offset-into-index-join" />                    | `optimizer_push_offset_into_index_join`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | If `on`, the optimizer will attempt to push offset expressions into index join expressions to produce more efficient query plans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="optimizer-use-forecasts" />                                  | `optimizer_use_forecasts`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | If `on`, the optimizer uses forecasted statistics for query planning.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="optimizer-use-histograms" />                                 | `optimizer_use_histograms`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | If `on`, the optimizer uses collected histograms for cardinality estimation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `on`                                                                                                                                                           | No                                                              | Yes |
| <a id="optimizer-use-improved-multi-column-selectivity-estimate" /> | `optimizer_use_improved_multi_column_selectivity_estimate`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | If `on`, the optimizer uses an improved selectivity estimate for multi-column predicates.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="optimizer-use-improved-zigzag-join-costing" />               | `optimizer_use_improved_zigzag_join_costing`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | If `on`, the cost of <InternalLink path="cost-based-optimizer#zigzag-joins">zigzag joins</InternalLink> is updated so they will be never be chosen over scans unless they produce fewer rows. To take effect, the [`enable_zigzag_join`](#enable-zigzag-join) setting must also be enabled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="optimizer-use-lock-op-for-serializable" />                   | `optimizer_use_lock_op_for_serializable`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | If `on`, the optimizer uses a `Lock` operator to construct query plans for `SELECT` statements using the <InternalLink path="select-for-update">`FOR UPDATE` and `FOR SHARE`</InternalLink> clauses. This setting only affects `SERIALIZABLE` transactions. `READ COMMITTED` transactions are evaluated with the `Lock` operator regardless of the setting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="optimizer-use-merged-partial-statistics" />                  | `optimizer_use_merged_partial_statistics`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | If `on`, the optimizer uses <InternalLink path="cost-based-optimizer#partial-statistics">partial statistics</InternalLink> merged with existing full <InternalLink path="cost-based-optimizer#table-statistics">table statistics</InternalLink> for cardinality estimation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="optimizer-use-multicol-stats" />                             | `optimizer_use_multicol_stats`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | If `on`, the optimizer uses collected multi-column statistics for cardinality estimation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `on`                                                                                                                                                           | No                                                              | Yes |
| <a id="optimizer-use-not-visible-indexes" />                        | `optimizer_use_not_visible_indexes`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | If `on`, the optimizer uses not visible indexes for planning.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `off`                                                                                                                                                          | No                                                              | Yes |
| <a id="optimizer-use-virtual-computed-column-stats" />              | `optimizer_use_virtual_computed_column_stats`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | If `on`, the optimizer uses table statistics on <InternalLink path="computed-columns">virtual computed columns</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="plan-cache-mode" />                                          | `plan_cache_mode`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | The type of plan that is cached in the <InternalLink path="cost-based-optimizer#query-plan-cache">query plan cache</InternalLink>: `auto`, `force_generic_plan`, or `force_custom_plan`.<br /><br />For more information, refer to <InternalLink path="cost-based-optimizer#query-plan-type">Query plan type</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `force_custom_plan`                                                                                                                                            | Yes                                                             | Yes |
| <a id="plpgsql-use-strict-into" />                                  | `plpgsql_use_strict_into`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | If `on`, PL/pgSQL <InternalLink path="plpgsql#assign-a-result-to-a-variable">`SELECT ... INTO` and `RETURNING ... INTO` statements</InternalLink> behave as though the `STRICT` option is specified. This causes the SQL statement to error if it does not return exactly one row.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="pg_trgm_similarity_threshold" />                             | `pg_trgm.similarity_threshold`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The threshold above which a <InternalLink path="functions-and-operators#operators">`%`</InternalLink> string comparison returns `true`. The value must be between `0` and `1`. For more information, see <InternalLink path="trigram-indexes">Trigram Indexes</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | `0.3`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="prefer-lookup-joins-for-fks" />                              | `prefer_lookup_joins_for_fks`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | If `on`, the optimizer prefers <InternalLink path="joins#lookup-joins">`lookup joins`</InternalLink> to <InternalLink path="joins#merge-joins">`merge joins`</InternalLink> when performing <InternalLink path="foreign-key">`foreign key`</InternalLink> checks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="reorder-joins-limit" />                                      | `reorder_joins_limit`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Maximum number of joins that the optimizer will attempt to reorder when searching for an optimal query execution plan. <br /><br />For more information, see <InternalLink path="cost-based-optimizer#join-reordering">Join reordering</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | `8`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="require-explicit-primary-keys" />                            | `require_explicit_primary_keys`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | If `on`, CockroachDB throws an error for all tables created without an explicit primary key defined.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="search-path" />                                              | `search_path`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | A list of schemas that will be searched to resolve unqualified table or function names. <br />For more details, see <InternalLink path="sql-name-resolution">SQL name resolution</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | `public`                                                                                                                                                       | Yes                                                             | Yes |
| <a id="serial-normalization" />                                     | `serial_normalization`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Specifies the default handling of <InternalLink path="serial">`SERIAL`</InternalLink> in table definitions. Valid options include `'rowid'`, `'virtual_sequence'`, `sql_sequence`, `sql_sequence_cached`, and `unordered_rowid`. <br />If set to `'virtual_sequence'`, the `SERIAL` type auto-creates a sequence for [better compatibility with Hibernate sequences](https://forum.cockroachlabs.com/t/hibernate-sequence-generator-returns-negative-number-and-ignore-unique-rowid/1885). <br />If set to `sql_sequence_cached`, you can use the `sql.defaults.serial_sequences_cache_size` <InternalLink path="cluster-settings">cluster setting</InternalLink> to control the number of values to cache in a user's session, with a default of 256. <br />If set to `unordered_rowid`, the `SERIAL` type generates a globally unique 64-bit integer (a combination of the insert timestamp and the ID of the node executing the statement) that does not have unique ordering. | `'rowid'`                                                                                                                                                      | Yes                                                             | Yes |
| <a id="server-version" />                                           | `server_version`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | The version of PostgreSQL that CockroachDB emulates.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Version-dependent                                                                                                                                              | No                                                              | Yes |
| <a id="server-version-num" />                                       | `server_version_num`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | The version of PostgreSQL that CockroachDB emulates.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Version-dependent                                                                                                                                              | Yes                                                             | Yes |
| <a id="session-id" />                                               | `session_id`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | The ID of the current session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Session-dependent                                                                                                                                              | No                                                              | Yes |
| <a id="session-user" />                                             | `session_user`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The user connected for the current session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | User in connection string                                                                                                                                      | No                                                              | Yes |
| <a id="sql-safe-updates" />                                         | `sql_safe_updates`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | If `true`, the following potentially unsafe SQL statements are disallowed: <InternalLink path="drop-database">`DROP DATABASE`</InternalLink> of a non-empty database and all dependent objects; <InternalLink path="delete">`DELETE`</InternalLink> and <InternalLink path="update">`UPDATE`</InternalLink> without a `WHERE` clause, unless a <InternalLink path="limit-offset">`LIMIT`</InternalLink> clause is included; <InternalLink path="select-for-update">`SELECT ... FOR UPDATE`</InternalLink> and <InternalLink path="select-for-update">`SELECT ... FOR SHARE`</InternalLink> without a `WHERE` or <InternalLink path="limit-offset">`LIMIT`</InternalLink> clause; and <InternalLink path="alter-table#drop-column">`ALTER TABLE ... DROP COLUMN`</InternalLink>.<br />For more details, refer to <InternalLink path="cockroach-sql#allow-potentially-unsafe-sql-statements">Allow potentially unsafe SQL statements</InternalLink>.                                | `true` for interactive sessions from the <InternalLink path="cockroach-sql">built-in SQL client</InternalLink>, <br />`false` for sessions from other clients  | Yes                                                             | Yes |
| <a id="statement-timeout" />                                        | `statement_timeout`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | The amount of time a statement can run before being stopped. <br />This value can be an `int` (e.g., `10`) and will be interpreted as milliseconds. It can also be an interval or string argument, where the string can be parsed as a valid interval (e.g., `'4s'`). <br />A value of `0` turns it off.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | The value set by the `sql.defaults.statement_timeout` <InternalLink path="cluster-settings">cluster setting</InternalLink> (`0s`, by default).                 | Yes                                                             | Yes |
| <a id="stub-catalog-tables" />                                      | `stub_catalog_tables`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | If `off`, querying an unimplemented, empty <InternalLink path="pg-catalog">`pg_catalog`</InternalLink> table will result in an error, as is the case in v20.2 and earlier. If `on`, querying an unimplemented, empty `pg_catalog` table simply returns no rows.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="timezone" />                                                 | `timezone`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | The default time zone for the current session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | `UTC`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="tracing" />                                                  | `tracing`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | The trace recording state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="transaction-isolation" />                                    | `transaction_isolation`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | The isolation level at which the transaction executes (<InternalLink path="demo-serializable">`SERIALIZABLE`</InternalLink> or <InternalLink path="read-committed">`READ COMMITTED`</InternalLink>). See <InternalLink path="transactions#isolation-levels">Isolation levels</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `SERIALIZABLE`                                                                                                                                                 | Yes                                                             | Yes |
| <a id="transaction-priority" />                                     | `transaction_priority`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | The priority of the current transaction. See Transactions: Transaction priorities for more details. This session variable was called transaction priority (with a space) in CockroachDB 1.x. It has been renamed for compatibility with PostgreSQL.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | `NORMAL`                                                                                                                                                       | Yes                                                             | Yes |
| <a id="transaction-read-only" />                                    | `transaction_read_only`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | The access mode of the current transaction. See <InternalLink path="set-transaction">`SET TRANSACTION`</InternalLink> for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="transaction-rows-read-err" />                                | `transaction_rows_read_err`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The limit for the number of rows read by a SQL transaction. If this value is exceeded the transaction will fail (or the event will be logged to `SQL_INTERNAL_PERF` for internal transactions).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="transaction-rows-read-log" />                                | `transaction_rows_read_log`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The threshold for the number of rows read by a SQL transaction. If this value is exceeded, the event will be logged to `SQL_PERF` (or `SQL_INTERNAL_PERF` for internal transactions).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="transaction-rows-written-err" />                             | `transaction_rows_written_err`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The limit for the number of rows written by a SQL transaction. If this value is exceeded the transaction will fail (or the event will be logged to `SQL_INTERNAL_PERF` for internal transactions).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="transaction-rows-written-log" />                             | `transaction_rows_written_log`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | The threshold for the number of rows written by a SQL transaction. If this value is exceeded, the event will be logged to `SQL_PERF` (or `SQL_INTERNAL_PERF` for internal transactions).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="transaction-status" />                                       | `transaction_status`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | The state of the current transaction. See <InternalLink path="transactions">Transactions</InternalLink> for more details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | `NoTxn`                                                                                                                                                        | No                                                              | Yes |
| <a id="transaction-timeout" />                                      | `transaction_timeout`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Aborts an explicit <InternalLink path="transactions">transaction</InternalLink> when it runs longer than the configured duration. Stored in milliseconds; can be expressed in milliseconds or as an <InternalLink path="interval">`INTERVAL`</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `0`                                                                                                                                                            | Yes                                                             | Yes |
| <a id="troubleshooting_mode_enabled" />                             | `troubleshooting_mode_enabled`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | When enabled, avoid performing additional work on queries, such as collecting and emitting telemetry data. This session variable is particularly useful when the cluster is experiencing issues, unavailability, or failure.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | `off`                                                                                                                                                          | Yes                                                             | Yes |
| <a id="use_declarative_schema_changer" />                           | `use_declarative_schema_changer`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Whether to use the declarative schema changer for supported statements.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="vectorize" />                                                | `vectorize`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | The vectorized execution engine mode. Options include `on` and `off`. For more details, see <InternalLink path="vectorized-execution#configure-vectorized-execution">Configure vectorized execution for CockroachDB</InternalLink>.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | `on`                                                                                                                                                           | Yes                                                             | Yes |
| <a id="virtual_cluster_name" />                                     | `virtual_cluster_name`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | The name of the virtual cluster that the SQL client is connected to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | Session-dependent                                                                                                                                              | No                                                              | Yes |

The following session variables are exposed only for backwards compatibility with earlier CockroachDB releases and have no impact on how CockroachDB runs:

| Variable name                                       | Initial value                              | Modify with <InternalLink path="set-vars">`SET`</InternalLink>? | View with <InternalLink path="show-vars">`SHOW`</InternalLink>? |     |
| --------------------------------------------------- | ------------------------------------------ | --------------------------------------------------------------- | --------------------------------------------------------------- | --- |
| <a id="backslash-quote" />                          | `backslash_quote`                          | `safe_encoding`                                                 | No                                                              | Yes |
| <a id="client-encoding" />                          | `client_encoding`                          | `UTF8`                                                          | No                                                              | Yes |
| <a id="default-tablespace" />                       | `default_tablespace`                       |                                                                 | No                                                              | Yes |
| <a id="enable-drop-enum-value" />                   | `enable_drop_enum_value`                   | `off`                                                           | Yes                                                             | Yes |
| <a id="enable-seqscan" />                           | `enable_seqscan`                           | `on`                                                            | Yes                                                             | Yes |
| <a id="escape-string-warning" />                    | `escape_string_warning`                    | `on`                                                            | No                                                              | Yes |
| <a id="experimental-enable-hash-sharded-indexes" /> | `experimental_enable_hash_sharded_indexes` | `off`                                                           | Yes                                                             | Yes |
| <a id="integer-datetimes" />                        | `integer_datetimes`                        | `on`                                                            | No                                                              | Yes |
| <a id="max-identifier-length" />                    | `max_identifier_length`                    | `128`                                                           | No                                                              | Yes |
| <a id="max-index-keys" />                           | `max_index_keys`                           | `32`                                                            | No                                                              | Yes |
| <a id="row-security" />                             | `row_security`                             | `off`                                                           | No                                                              | Yes |
| <a id="standard-conforming-strings" />              | `standard_conforming_strings`              | `on`                                                            | No                                                              | Yes |
| <a id="server-encoding" />                          | `server_encoding`                          | `UTF8`                                                          | Yes                                                             | Yes |
| <a id="synchronize-seqscans" />                     | `synchronize_seqscans`                     | `on`                                                            | No                                                              | Yes |
| <a id="synchronous-commit" />                       | `synchronous_commit`                       | `on`                                                            | Yes                                                             | Yes |

### Special syntax cases

CockroachDB supports the following syntax cases, for compatibility with common SQL syntax patterns:

| Syntax                                                           | Equivalent to                                   | Notes                                                                    |
| ---------------------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------ |
| `USE ...`                                                        | `SET database = ...`                            | This is provided as convenience for users with a MySQL/MSSQL background. |
| `SET NAMES ...`                                                  | `SET client_encoding = ...`                     | This is provided for compatibility with PostgreSQL clients.              |
| `SET ROLE <role>`                                                | `SET role = <role>`                             | This is provided for compatibility with PostgreSQL clients.              |
| `RESET ROLE`                                                     | `SET role = 'none'`/`SET role = current_user()` | This is provided for compatibility with PostgreSQL clients.              |
| `SET SCHEMA <name>`                                              | `SET search_path = <name>`                      | This is provided for better compatibility with PostgreSQL.               |
| `SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ...` | `SET default_transaction_isolation = ...`       | This is provided for compatibility with standard SQL.                    |
| `SET TIME ZONE ...`                                              | `SET timezone = ...`                            | This is provided for compatibility with PostgreSQL clients.              |

## Examples

### Set simple variables

The following examples demonstrate how to use `SET` to configure the default database for the current session:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET application_name = movr_app;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW application_name;
```

```
  application_name
--------------------
  movr_app
(1 row)
```

### Set variables to values containing spaces

The following demonstrates how to use quoting to use values containing spaces:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET application_name = "movr app";
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW application_name;
```

```
  application_name
--------------------
  movr app
(1 row)
```

### Set variables to a list of values

The following demonstrates how to assign a list of values:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET search_path = pg_catalog,public;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW search_path;
```

```
     search_path
----------------------
  pg_catalog, public
(1 row)
```

### Reset a variable to its default value

<Tip>
  You can use <InternalLink path="reset-vars">`RESET`</InternalLink> to reset a session variable as well.
</Tip>

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW search_path;
```

```
     search_path
----------------------
  pg_catalog, public
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET search_path = DEFAULT;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW search_path;
```

```
    search_path
-------------------
  "$user", public
(1 row)
```

### Set a variable for the duration of a single transaction

To set a variable for the duration of a single transaction, use the `SET LOCAL` statement.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW application_name;
```

```
  application_name
--------------------
  movr app
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN;
SET LOCAL application_name = demo;
SHOW application_name;
```

```
  application_name
--------------------
  demo
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
COMMIT;
SHOW application_name;
```

```
  application_name
--------------------
  movr app
(1 row)
```

### Roll back session variables set for a transaction

You can roll back session variable settings to <InternalLink path="savepoint">savepoints</InternalLink>.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW timezone;
```

```
  timezone
------------
  UTC
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN;
SET timezone = '+3';
SAVEPOINT s1;
SHOW timezone;
```

```
  timezone
------------
  +3
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET LOCAL timezone = '+1';
SHOW timezone;
```

```
  timezone
------------
  +1
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ROLLBACK TO SAVEPOINT s1;
SHOW timezone;
```

```
  timezone
------------
  +3
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
COMMIT;
SHOW timezone;
```

```
  timezone
------------
  +3
(1 row)
```

### Assume another role

To assume another <InternalLink path="security-reference/authorization#roles">role</InternalLink> for the duration of a session, use `SET ROLE <role>`. `SET ROLE <role>` is equivalent to `SET role = <role>`.

<Note>
  To assume a new role, the current user must be a member of the `admin` role, or a member of the target role.
</Note>

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW role;
```

```
  role
--------
  root
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE ROLE new_role;
SHOW ROLES;
```

```
  username | options | member_of
-----------+---------+------------
  admin    |         | {}
  new_role | NOLOGIN | {}
  root     |         | {admin}
(3 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET ROLE new_role;
SHOW role;
```

```
    role
------------
  new_role
(1 row)
```

To reset the role of the current user, use a <InternalLink path="reset-vars">`RESET`</InternalLink> statement. `RESET ROLE` is equivalent to `SET role = 'none'` and `SET role = current_user()`.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
RESET ROLE;
SHOW role;
```

```
  role
--------
  root
(1 row)
```

To assume a role for the duration of a single transaction, use `SET LOCAL ROLE`.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
BEGIN;
SET LOCAL ROLE new_role;
SHOW role;
```

```
    role
------------
  new_role
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
COMMIT;
SHOW role;
```

```
  role
--------
  root
(1 row)
```

## `SET TIME ZONE`

<Danger>
  As a best practice, we recommend not using this setting and avoid setting a session time for your database. We instead recommend converting UTC values to the appropriate time zone on the client side.
</Danger>

You can control the default time zone for a session with `SET TIME ZONE`. This will apply an offset to all <InternalLink path="timestamp">`TIMESTAMPTZ`/`TIMESTAMP WITH TIME ZONE`</InternalLink> and <InternalLink path="time">`TIMETZ`/`TIME WITH TIME ZONE`</InternalLink> values in the session. By default, CockroachDB uses UTC as the time zone for `SET TIME ZONE` offsets.

### Parameters

The input passed to `SET TIME ZONE` indicates the time zone for the current session. This value can be a string representation of a local system-defined time zone (e.g., `'EST'`, `'America/New_York'`) or a positive or negative numeric offset from UTC (e.g., `-7`, `+7`, or `UTC-7`, `UTC+7`) or GMT (e.g., `GMT-7`, `GMT+7`). The numeric offset input can also be colon-delimited (e.g., `-7:00`, `GMT+7:00`).

When setting a time zone, note the following:

* Timezone abbreviations are case-insensitive.

* To see a list of supported timezones, their nicknames, and their offsets, run the following query:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  SELECT * FROM pg_timezone_names;
  ```

* `DEFAULT`, `LOCAL`, or `0` sets the session time zone to `UTC`.

* Only offsets specified by integers (e.g., `-7`, `7`) use the [ISO 8601 time offset](https://wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC) (i.e., the offset input is parsed as hours *east* of UTC). If you explicitly specify `UTC` or `GMT` for the time zone offset (e.g., `UTC-7`,`GMT+7`), or if the numeric input is colon-delimited (e.g.,  `-7:00`, `GMT+7:00`), CockroachDB uses the [POSIX time offset](https://www.postgresql.org/docs/current/datetime-posix-timezone-specs.html) instead (i.e., hours *west* of the specified time zone). This means that specifying an offset of `-7` (i.e., -7 *east* of UTC) is equivalent to specifying `GMT+7` (i.e., 7 *west* of UTC).

### Example: Set the default time zone via `SET TIME ZONE`

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SET TIME ZONE 'EST'; -- same as SET "timezone" = 'EST'
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW TIME ZONE;
```

```
  timezone
+----------+
  EST
(1 row)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SET TIME ZONE DEFAULT; -- same as SET "timezone" = DEFAULT
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SHOW TIME ZONE;
```

```
  timezone
+----------+
  UTC
(1 row)
```

## `SET TRACING`

`SET TRACING` changes the trace recording state of the current session. A trace recording can be inspected with the <InternalLink path="show-trace">`SHOW TRACE FOR SESSION`</InternalLink> statement.

| Value     | Description                                                                                                                                                                                                |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `off`     | Trace recording is disabled.                                                                                                                                                                               |
| `cluster` | Trace recording is enabled; distributed traces are collected.                                                                                                                                              |
| `on`      | Same as `cluster`.                                                                                                                                                                                         |
| `kv`      | Same as `cluster` except that "kv messages" are collected instead of regular trace messages. See <InternalLink path="show-trace">`SHOW TRACE FOR SESSION`</InternalLink>.                                  |
| `results` | Result rows and row counts are copied to the session trace. This must be specified in order for the output of a query to be printed in the session trace.<br /><br />Example: `SET tracing = kv, results;` |

## Considerations

### Session variable precedence

When a <InternalLink path="show-sessions">session</InternalLink> starts, CockroachDB determines the initial value of each <InternalLink path="session-variables">session variable</InternalLink> by evaluating the settings in the following order (items earlier in the list take precedence over later items):

1. <InternalLink path="connection-parameters">Connection string parameters</InternalLink>: A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
2. <InternalLink path="alter-role#set-default-session-variable-values-for-a-role-in-a-specific-database">Per-role, per-database defaults</InternalLink>: A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
3. <InternalLink path="alter-role#set-default-session-variable-values-for-a-role">Per-role, all-database defaults</InternalLink>: A value set by `ALTER ROLE {role_name} SET {var}={value}`.
4. <InternalLink path="alter-role#set-default-session-variable-values-for-a-specific-database">All-role, per-database defaults</InternalLink>: A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
5. <InternalLink path="alter-role#set-default-session-variable-values-for-all-users">Cluster-wide defaults for all roles and all databases</InternalLink>: A value set by `ALTER ROLE ALL SET {var}={value}`.

If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the <InternalLink path="security-reference/authorization">`root` user</InternalLink> is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.

You can also set session variables for the duration of a single transaction by using <InternalLink path="set-vars#set-a-variable-for-the-duration-of-a-single-transaction">`SET LOCAL {var}={value}`</InternalLink>.

<Note>
  Changes to defaults using the preceding methods only apply to **future** sessions. This is because session variable resolution happens at session start time. To change a default value in an existing open session, set the variable explicitly with <InternalLink path="set-vars">`SET`</InternalLink>.
</Note>

## Known Limitations

`SET`  <InternalLink path="set-vars">`SET`</InternalLink>  does not properly apply <InternalLink path="rollback-transaction">`ROLLBACK`</InternalLink> within a transaction. For example, in the following transaction, showing the `TIME ZONE` <InternalLink path="set-vars#supported-variables">variable</InternalLink> does not return `2` as expected after the rollback:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET TIME ZONE +2;
BEGIN;
SET TIME ZONE +3;
ROLLBACK;
SHOW TIME ZONE;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
timezone
------------
3
```

## See also

* <InternalLink path="reset-vars">`RESET`</InternalLink>
* <InternalLink path="set-transaction">`SET TRANSACTION`</InternalLink>
* <InternalLink path="set-cluster-setting">`SET CLUSTER SETTING`</InternalLink>
* <InternalLink path="show-vars">`SHOW {session variable}`</InternalLink>
* <InternalLink path="timestamp">The `TIMESTAMP` and `TIMESTAMPTZ` data types.</InternalLink>
* <InternalLink path="show-trace">`SHOW TRACE FOR SESSION`</InternalLink>
* <InternalLink path="pg-catalog">`pg_catalog`</InternalLink>
* <InternalLink path="show-default-session-variables-for-role">`SHOW DEFAULT SESSION VARIABLES FOR ROLE`</InternalLink>
