ALTER SERVICE

Modifies Snowpark Container Services service configuration, upgrades the code for the service, and allows you to suspend or resume a service. You can:

  • Apply modifications to a running service. For example, suspend or resume a service, and update the number of service instances running.

  • Apply modifications that take effect only after service is restarted. For example, specify a default warehouse for queries.

  • Apply modifications that cause Snowflake to shut down the service, and restart using new code. For example, you might want to deploy updated service code.

  • Restart the specified instances of a service using the snapshot provided as the initial content for the specified volume. The service must be suspended before you execute ALTER SERVICE.

See also:

CREATE SERVICE , DESCRIBE SERVICE, DROP SERVICE , SHOW SERVICES

Syntax

ALTER SERVICE [ IF EXISTS ] <name> { SUSPEND | RESUME }

ALTER SERVICE [ IF EXISTS ] <name>
  {
     fromSpecification
     | fromSpecificationTemplate
  }

ALTER SERVICE [IF EXISTS] <service_name> RESTORE VOLUME <volume_name>
                                                 INSTANCES <comma_separated_instance_ids>
                                                 FROM SNAPSHOT <snapshot_name>

ALTER SERVICE [ IF EXISTS ] <name> SET [ MIN_INSTANCES = <num> ]
                                       [ MAX_INSTANCES = <num> ]
                                       [ QUERY_WAREHOUSE = <warehouse_name> ]
                                       [ AUTO_RESUME = { TRUE | FALSE } ]
                                       [ EXTERNAL_ACCESS_INTEGRATIONS = ( <EAI_name> [ , ... ] ) ]
                                       [ COMMENT = '<string_literal>' ]



ALTER SERVICE [ IF EXISTS ] <name> UNSET { MIN_INSTANCES                |
                                           MAX_INSTANCES                |
                                           QUERY_WAREHOUSE              |
                                           AUTO_RESUME                  |
                                           EXTERNAL_ACCESS_INTEGRATIONS |
                                           COMMENT
                                         }
                                         [ , ... ]

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

Where:

fromSpecification ::=
  {
    FROM @<stage> SPECIFICATION_FILE = '<yaml_file_stage_path>'
    | FROM SPECIFICATION <specification_text>
  }
Copy
fromSpecificationTemplate ::=
  {
    FROM @<stage> SPECIFICATION_TEMPLATE_FILE = '<yaml_file_stage_path>'
    | FROM SPECIFICATION_TEMPLATE <specification_text>
  }
  USING ( <key> => <value> [ , <key> => <value> [ , ... ] ]  )
Copy

Parameters

name

Specifies the identifier for the service to alter.

If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

{ SUSPEND | RESUME }

Specifies whether to suspend or resume the service.

When you suspend a service, Snowflake shuts down and deletes the containers. If you later resume a suspended service,Snowflake recreates the containers. That is, Snowflake takes the image from your repository and starts the containers. Note that, Snowflake deploys the same image version; it is not a service update operation.

When you invoke a suspended service using either a service function or invoking the public endpoint (ingress), Snowflake automatically resumes the service.

FROM stage

Specifies the Snowflake internal stage where the specification file is stored; for example, “@tutorial_stage.”

SPECIFICATION_FILE = 'yaml_file_stage_path'

Specifies the path to the service specification file on the stage; for example, “/some-dir/echo_spec.yaml”.

SPECIFICATION_TEMPLATE_FILE = 'yaml_file_stage_path'

Specifies the path to the service specification template file on the stage; for example, 'some-dir/echo_template_spec.yaml'. When SPECIFICATION_TEMPLATE_FILE is specified, the USING parameter is required.

FROM SPECIFICATION specification_text

Specifies service specification. You can use pair of dollar signs ($$) to delimit the beginning and ending of the specification string.

FROM SPECIFICATION_TEMPLATE specification_text

Specifies service specification. You can use a pair of dollar signs ($$) to delimit the beginning and ending of the specification string. When SPECIFICATION_TEMPLATE is specified, the USING parameter is required.

USING ( key => value [ , key => value [ , ... ] ]  )

Lets you provide values to parameterize specification template expansion.

USING is required when using a specification template (FROM SPECIFICATION_TEMPLATE_FILE or FROM SPECIFICATION_TEMPLATE). The key-value pairs must form a comma-separated list.

Where:

  • key is the name of the template variable. The template variable name can optionally be enclosed in double quotes (").

  • value is the value to assign to the variable in the template. String values must be enclosed in ' or $$. The value must either be alphanumeric or valid JSON.

RESTORE VOLUME volume_name INSTANCES comma_separated_instance_ids FROM SNAPSHOT snapshot_name

Restores the snapshot snapshot_name on the existing block storage volume volume_name for the instances comma_separated_instance_ids.

Snapshots can only be taken for block storage volumes (and not for local, memory, or stage volumes).

Volume names are case-sensitive. Therefore, double quotes should always be used to match the corresponding name in the service specification.

SET ...

Sets one or more specified properties or parameters for the service:

MIN_INSTANCES = num

Specifies the minimum number of service instances.

MAX_INSTANCES = num

Specifies the maximum number of service instances.

QUERY_WAREHOUSE = warehouse_name

Warehouse to use if a service container connects to Snowflake to execute a query but does not explicitly specify a warehouse to use.

AUTO_RESUME = { TRUE | FALSE }

Specifies whether to automatically resume the service when the service function is called or a request is received.

EXTERNAL_ACCESS_INTEGRATIONS = ( EAI_name [ , ... ] )

Specifies the names of the external access integrations that allow your service to access external sites. Snowflake replaces all the existing EAIs with those specified in this parameter. The names in this list are case-sensitive. For more information, see Network egress. Note that this changes the allowed network access for all running instances of the service. You don’t need to explicitly suspend and resume the service.

COMMENT = 'string_literal'

Specifies a comment for the compute pool.

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 for objects and columns.

UNSET ...

Specifies one or more properties and/or parameters to unset for the service, which resets them to the defaults (see CREATE SERVICE):

  • MIN_INSTANCES

  • MAX_INSTANCES

  • QUERY_WAREHOUSE

  • AUTO_RESUME

  • EXTERNAL_ACCESS_INTEGRATIONS

  • COMMENT

Access control requirements

A role used to execute this SQL command must have the following privileges at a minimum:

Privilege

Object

Notes

OPERATE

Service

USAGE

Snapshot

Note that operating on any object in a schema also requires the USAGE privilege on the parent database and 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.

Usage notes

  • Regarding metadata:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

Examples

Suspend a service.

ALTER SERVICE echo_service SUSPEND;
Copy

Modify the MIN_INSTANCES and MAX_INSTANCES properties of an existing service.

ALTER SERVICE echo_service SET MIN_INSTANCES=3 MAX_INSTANCES=5;
Copy

Restore a snapshot on an existing block volume associated with instances 0 and 2 of the example_service service.

ALTER SERVICE example_service
  RESTORE VOLUME "myvolume"
  INSTANCES 0,2
  FROM SNAPSHOT my_snapshot;
Copy