ALTER SESSION POLICY

statementsupportedGovernance (policies, tags, data quality)

docs.snowflake.com ↗

Object: SESSION POLICY

Modifies the properties for an existing session policy. Any changes made to the session policy properties go into effect when the next SQL query that uses the session policy runs.

Syntax

supportedpartialnot supportednot scored

ALTER SESSION POLICY [ IF EXISTS ] <name> RENAME TO <new_name>

ALTER SESSION POLICY [ IF EXISTS ] <name> SET
  [ SESSION_IDLE_TIMEOUT_MINS = <integer> ]
  [ SESSION_UI_IDLE_TIMEOUT_MINS = <integer> ]
  [ SESSION_MAX_LIFESPAN_MINS = <integer> ]
  [ SESSION_UI_MAX_LIFESPAN_MINS = <integer> ]
  [ ALLOWED_SECONDARY_ROLES = ( [ { 'ALL' | <role_name> [ , <role_name> ... ] } ] ) ]
  [ BLOCKED_SECONDARY_ROLES = ( [ { 'ALL' | <role_name> [ , <role_name> ... ] } ] ) ]
  [ AGENT_RESTRICTED_SESSION_SCOPE = { '<predefined_scope>' | '<rss_object_name>' | $$ <yaml_definition> $$ } ]
  [ COMMENT = '<string_literal>' ]

ALTER SESSION POLICY [ IF EXISTS ] <name> SET
  TAG <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]

ALTER SESSION POLICY [ IF EXISTS ] <name> UNSET TAG <tag_name> [ , <tag_name> ... ]

ALTER SESSION POLICY [ IF EXISTS ] <name> UNSET
  [ SESSION_IDLE_TIMEOUT_MINS ]
  [ SESSION_UI_IDLE_TIMEOUT_MINS ]
  [ SESSION_MAX_LIFESPAN_MINS ]
  [ SESSION_UI_MAX_LIFESPAN_MINS ]
  [ ALLOWED_SECONDARY_ROLES ]
  [ BLOCKED_SECONDARY_ROLES ]
  [ AGENT_RESTRICTED_SESSION_SCOPE ]
  [ COMMENT ]

Parameters

NameRequiredDescription
nameIdentifier for the session policy; must be unique for your account. The identifier value must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements.
RENAME TO new_nameSpecifies the new identifier for the session policy; must be unique for your account. For more details, see Identifier requirements. You can move the object to a different database and/or schema while optionally renaming the object. To do so, specify a qualified new_name value that includes the new database and/or schema name in the form db_name.schema_name.object_name or schema_name.object_name, respectively. Note The destination database and/or schema must already exist. In addition, an object with the same name cannot already exist in the new location; otherwise, the statement returns an error. Moving an object to a managed access schema is prohibited unless the object owner (that is, the role that has the OWNERSHIP privilege on the object) also owns the target schema.
SET ...Specifies one or more parameters to set for the session policy separated by blank spaces, commas, or new lines.
SESSION_IDLE_TIMEOUT_MINS = integerFor Snowflake clients and programmatic clients, the number of minutes in which a session can be idle before users must authenticate to Snowflake again. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 5 and 1440, inclusive. Default: 240 (4 hours)
SESSION_UI_IDLE_TIMEOUT_MINS = integerFor Snowsight, the number of minutes in which a session can be idle before a user must authenticate to Snowflake again. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 5 and 1440, inclusive. Default: 1080 (18 hours)
SESSION_MAX_LIFESPAN_MINS = integerFor Snowflake clients and programmatic clients, the maximum number of minutes a session can remain active before users must authenticate to Snowflake again, regardless of activity. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 0 and 43200 (30 days), inclusive. A value of 0 means no maximum lifespan is enforced. Default: 0 (no maximum lifespan enforcement)
SESSION_UI_MAX_LIFESPAN_MINS = integerFor Snowsight, the maximum number of minutes a session can remain active before users must authenticate to Snowflake again, regardless of activity. If a value is not specified, Snowflake uses the default value. The number of minutes can be any integer between 0 and 43200 (30 days), inclusive. A value of 0 means no maximum lifespan is enforced. Default: 0 (no maximum lifespan enforcement)
ALLOWED_SECONDARY_ROLES = ( [ { 'ALL' | role_name [ , role_name ... ] } ] )Specifies the secondary roles for a session policy, if any. The possible values for the property are: Default: ('ALL'). If you unset this property, its value in the output of a DESCRIBE SESSION POLICY command is 'ALL'.
  • ('ALL') — Allows all secondary roles.
  • ( role_name [ , role_name ... ] ) — Allows the specified roles as secondary roles. The secondary roles can be user-defined account roles or system roles. Specify the role name as it is stored in Snowflake. For details, see Identifier requirements.
()Disallows secondary roles.
BLOCKED_SECONDARY_ROLES = ( [ { 'ALL' | role_name [ , role_name ... ] } ] )Specifies the blocked secondary roles for a session policy, if any. Blocked secondary roles take precedence over allowed secondary roles. The possible values for the property are: Default: (). If you unset this property, its value in the output of a DESCRIBE SESSION POLICY command is '()'.
  • ('ALL') — Disallows secondary roles.
  • ( role_name [ , role_name ... ] ) — Blocks the specified roles as secondary roles. The specified roles, and the roles granted to those roles, cannot be activated as secondary roles. These blocked roles can be user-defined account roles or system roles. Specify the role name as it is stored in Snowflake. For details, see Identifier requirements.
()Allows all secondary roles.
AGENT_RESTRICTED_SESSION_SCOPE = { '<predefined_scope>' | '<rss_object_name>' | $$ <yaml_definition> $$ }Privilege ceiling that Snowflake applies when an agent is active in the session. When no agent is active, this property is ignored. For values and YAML structure, see Restricted Session Scope for agents.
COMMENT = 'string_literal'Adds a comment or overwrites an existing comment for the session policy.
TAG tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ]Specifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.
UNSET ...Specifies one or more parameters to unset for the session policy, which resets them to the system defaults. You can reset multiple properties with a single ALTER statement. Each property must be separated by a comma. When resetting a property, specify only the name. Specifying a value for the property will return an error.

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes OWNERSHIP | Session policy | OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control. For additional details on session policy DDL and privileges, see Managing session policies.

See also