Skip to content

Commit dbfe124

Browse files
authored
Add docs on session variable precedence order (#20112)
Fixes DOC-7209 NB. These changes are applied to all supported versions v24.1+
1 parent 1fd7f89 commit dbfe124

25 files changed

+200
-35
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
When a [session]({% link {{ page.version.version }}/show-sessions.md %}) starts, CockroachDB determines the initial value of each [session variable]({% link {{ page.version.version }}/session-variables.md %}) by evaluating the settings in the following order (items earlier in the list take precedence over later items):
2+
3+
1. [Connection string parameters]({% link {{ page.version.version }}/connection-parameters.md %}): A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
4+
1. [Per-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role-in-a-specific-database): A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
5+
1. [Per-role, all-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role): A value set by `ALTER ROLE {role_name} SET {var}={value}`.
6+
1. [All-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-specific-database): A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
7+
1. [Cluster-wide defaults for all roles and all databases]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users): A value set by `ALTER ROLE ALL SET {var}={value}`.
8+
9+
If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the [`root` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#root-user) is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.
10+
11+
You can also set session variables for the duration of a single transaction by using [`SET LOCAL {var}={value}`]({% link {{ page.version.version }}/set-vars.md %}#set-a-variable-for-the-duration-of-a-single-transaction).
12+
13+
{{site.data.alerts.callout_info}}
14+
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 [`SET`]({% link {{ page.version.version }}/set-vars.md %}).
15+
{{site.data.alerts.end}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
When a [session]({% link {{ page.version.version }}/show-sessions.md %}) starts, CockroachDB determines the initial value of each [session variable]({% link {{ page.version.version }}/session-variables.md %}) by evaluating the settings in the following order (items earlier in the list take precedence over later items):
2+
3+
1. [Connection string parameters]({% link {{ page.version.version }}/connection-parameters.md %}): A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
4+
1. [Per-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role-in-a-specific-database): A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
5+
1. [Per-role, all-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role): A value set by `ALTER ROLE {role_name} SET {var}={value}`.
6+
1. [All-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-specific-database): A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
7+
1. [Cluster-wide defaults for all roles and all databases]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users): A value set by `ALTER ROLE ALL SET {var}={value}`.
8+
9+
If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the [`root` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#root-user) is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.
10+
11+
You can also set session variables for the duration of a single transaction by using [`SET LOCAL {var}={value}`]({% link {{ page.version.version }}/set-vars.md %}#set-a-variable-for-the-duration-of-a-single-transaction).
12+
13+
{{site.data.alerts.callout_info}}
14+
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 [`SET`]({% link {{ page.version.version }}/set-vars.md %}).
15+
{{site.data.alerts.end}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
When a [session]({% link {{ page.version.version }}/show-sessions.md %}) starts, CockroachDB determines the initial value of each [session variable]({% link {{ page.version.version }}/session-variables.md %}) by evaluating the settings in the following order (items earlier in the list take precedence over later items):
2+
3+
1. [Connection string parameters]({% link {{ page.version.version }}/connection-parameters.md %}): A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
4+
1. [Per-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role-in-a-specific-database): A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
5+
1. [Per-role, all-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role): A value set by `ALTER ROLE {role_name} SET {var}={value}`.
6+
1. [All-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-specific-database): A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
7+
1. [Cluster-wide defaults for all roles and all databases]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users): A value set by `ALTER ROLE ALL SET {var}={value}`.
8+
9+
If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the [`root` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#root-user) is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.
10+
11+
You can also set session variables for the duration of a single transaction by using [`SET LOCAL {var}={value}`]({% link {{ page.version.version }}/set-vars.md %}#set-a-variable-for-the-duration-of-a-single-transaction).
12+
13+
{{site.data.alerts.callout_info}}
14+
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 [`SET`]({% link {{ page.version.version }}/set-vars.md %}).
15+
{{site.data.alerts.end}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
When a [session]({% link {{ page.version.version }}/show-sessions.md %}) starts, CockroachDB determines the initial value of each [session variable]({% link {{ page.version.version }}/session-variables.md %}) by evaluating the settings in the following order (items earlier in the list take precedence over later items):
2+
3+
1. [Connection string parameters]({% link {{ page.version.version }}/connection-parameters.md %}): A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
4+
1. [Per-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role-in-a-specific-database): A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
5+
1. [Per-role, all-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role): A value set by `ALTER ROLE {role_name} SET {var}={value}`.
6+
1. [All-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-specific-database): A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
7+
1. [Cluster-wide defaults for all roles and all databases]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users): A value set by `ALTER ROLE ALL SET {var}={value}`.
8+
9+
If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the [`root` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#root-user) is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.
10+
11+
You can also set session variables for the duration of a single transaction by using [`SET LOCAL {var}={value}`]({% link {{ page.version.version }}/set-vars.md %}#set-a-variable-for-the-duration-of-a-single-transaction).
12+
13+
{{site.data.alerts.callout_info}}
14+
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 [`SET`]({% link {{ page.version.version }}/set-vars.md %}).
15+
{{site.data.alerts.end}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
When a [session]({% link {{ page.version.version }}/show-sessions.md %}) starts, CockroachDB determines the initial value of each [session variable]({% link {{ page.version.version }}/session-variables.md %}) by evaluating the settings in the following order (items earlier in the list take precedence over later items):
2+
3+
1. [Connection string parameters]({% link {{ page.version.version }}/connection-parameters.md %}): A value supplied as a query parameter in the connection URL (for example, `.../movr?sslmode=disable&timezone=UTC`).
4+
1. [Per-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role-in-a-specific-database): A value set by `ALTER ROLE {role_name} IN DATABASE {db_name} SET {var}={value}`.
5+
1. [Per-role, all-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-role): A value set by `ALTER ROLE {role_name} SET {var}={value}`.
6+
1. [All-role, per-database defaults]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-a-specific-database): A value set by `ALTER ROLE ALL IN DATABASE {db_name} SET {var}={value}` or equivalently by `ALTER DATABASE {db_name} SET {var}={value}`.
7+
1. [Cluster-wide defaults for all roles and all databases]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users): A value set by `ALTER ROLE ALL SET {var}={value}`.
8+
9+
If a session variable is not modified using any of the preceding methods, the built-in system default value is used. Note that the [`root` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#root-user) is exempt from settings 3–5. The `root` user is only affected by values specified in the connection string.
10+
11+
You can also set session variables for the duration of a single transaction by using [`SET LOCAL {var}={value}`]({% link {{ page.version.version }}/set-vars.md %}#set-a-variable-for-the-duration-of-a-single-transaction).
12+
13+
{{site.data.alerts.callout_info}}
14+
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 [`SET`]({% link {{ page.version.version }}/set-vars.md %}).
15+
{{site.data.alerts.end}}

src/current/v24.1/alter-database.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ In CockroachDB, the following are aliases for `ALTER DATABASE ... SET {session v
400400

401401
For more information, refer to [`ALTER ROLE ALL ...`]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users).
402402

403+
#### Session variable precedence
404+
405+
{% include {{ page.version.version }}/sql/session-variable-precedence-order.md %}
406+
403407
### `SET PRIMARY REGION`
404408

405409
`ALTER DATABASE .. SET PRIMARY REGION` sets the primary [region]({% link {{ page.version.version }}/multiregion-overview.md %}#database-regions) of a [multi-region database]({% link {{ page.version.version }}/multiregion-overview.md %}).

src/current/v24.1/alter-role.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ You can use the keywords `ROLE` and `USER` interchangeably. [`ALTER USER`]({% li
1111

1212
## Considerations
1313

14-
- Password creation and alteration is supported only in secure clusters.
14+
### Password management
15+
16+
Password creation and alteration is supported only in secure clusters.
17+
18+
### Session variable precedence
19+
20+
{% include {{ page.version.version }}/sql/session-variable-precedence-order.md %}
1521

1622
## Required privileges
1723

src/current/v24.1/session-variables.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ toc: true
55
docs_area: reference.sql
66
---
77

8-
The [`SET`]({% link {{ page.version.version }}/set-vars.md %}) statement can modify one of the session configuration variables. These can also be queried via [`SHOW`]({% link {{ page.version.version }}/show-vars.md %}). By default, session variable values are set for the duration of the current session.
9-
10-
CockroachDB supports setting session variables for the duration of a single transaction, using [the `LOCAL` keyword]({% link {{ page.version.version }}/set-vars.md %}#set-local).
8+
The [`SET`]({% link {{ page.version.version }}/set-vars.md %}) statement can modify one of the session configuration variables. These can also be queried via [`SHOW`]({% link {{ page.version.version }}/show-vars.md %}).
119

1210
## Supported variables
1311

1412
{% include {{ page.version.version }}/misc/session-vars.md %}
1513

14+
## Considerations
15+
16+
### Session variable precedence
17+
18+
{% include {{ page.version.version }}/sql/session-variable-precedence-order.md %}
19+
1620
## See also
1721

1822
- [`SET {session variable}`]({% link {{ page.version.version }}/set-vars.md %})

src/current/v24.1/set-vars.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ toc: true
55
docs_area: reference.sql
66
---
77

8-
The `SET` [statement]({% link {{ page.version.version }}/sql-statements.md %}) can modify one of the session configuration variables. These can also be queried via [`SHOW`]({% link {{ page.version.version }}/show-vars.md %}). By default, session variable values are set for the duration of the current session.
9-
10-
CockroachDB supports setting session variables for the duration of a single transaction, using [the `LOCAL` keyword](#set-local).
8+
The `SET` [statement]({% link {{ page.version.version }}/sql-statements.md %}) can modify one of the session configuration variables. These can also be queried via [`SHOW`]({% link {{ page.version.version }}/show-vars.md %}). By default, session variable values are set for all future sessions to the database; they do not affect the current session.
119

1210
{{site.data.alerts.callout_info}}
1311
The `SET` statement for session variables is unrelated to the other [`SET TRANSACTION`]({% link {{ page.version.version }}/set-transaction.md %}) and [`SET CLUSTER SETTING`]({% link {{ page.version.version }}/cluster-settings.md %}#change-a-cluster-setting) statements.
@@ -452,6 +450,12 @@ When setting a time zone, note the following:
452450
`kv` | Same as `cluster` except that "kv messages" are collected instead of regular trace messages. See [`SHOW TRACE FOR SESSION`]({% link {{ page.version.version }}/show-trace.md %}).
453451
`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;`
454452

453+
## Considerations
454+
455+
### Session variable precedence
456+
457+
{% include {{ page.version.version }}/sql/session-variable-precedence-order.md %}
458+
455459
## Known Limitations
456460

457461
{% include {{page.version.version}}/known-limitations/set-transaction-no-rollback.md %}

src/current/v24.3/alter-database.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ In CockroachDB, the following are aliases for `ALTER DATABASE ... SET {session v
400400

401401
For more information, refer to [`ALTER ROLE ALL ...`]({% link {{ page.version.version }}/alter-role.md %}#set-default-session-variable-values-for-all-users).
402402

403+
#### Session variable precedence
404+
405+
{% include {{ page.version.version }}/sql/session-variable-precedence-order.md %}
406+
403407
### `SET PRIMARY REGION`
404408

405409
`ALTER DATABASE .. SET PRIMARY REGION` sets the primary [region]({% link {{ page.version.version }}/multiregion-overview.md %}#database-regions) of a [multi-region database]({% link {{ page.version.version }}/multiregion-overview.md %}).

0 commit comments

Comments
 (0)