Enable the Dedicated SQL feature

Updated at:

You can call the CreateSqlInstance operation to enable the Dedicated SQL feature for a project.

Prerequisites

Parameter description

def create_sql_instance(self, project_name, sql_instance,useAsDefault):

Request parameters

Parameter

Type

Required

Description

Example

project_name

String

Yes

The name of the project for which to enable the Dedicated SQL feature.

demo-test-project

sql_instance

int

Yes

The number of compute units (CUs). CUs are used in parallel when the Dedicated SQL feature is enabled.

500

useAsDefault

bool

Yes

Specifies whether to use Dedicated SQL by default for the project. If set to true, the Dedicated SQL feature is enabled for the specified project and applies to all query statements in the project, including those for alerts and dashboards.

False

Response parameters

For more information, see CreateSqlInstance.

Sample code

from aliyun.log import LogClient
import os


def main():
    # The Simple Log Service endpoint. For more information, see Endpoints. In this example, the Simple Log Service endpoint for the China (Hangzhou) region is used. Replace this parameter value with your actual endpoint.
    endpoint = 'cn-hangzhou.log.aliyuncs.com'
    # In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
    access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    access_key = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
    # The name of the project.
    project_name = 'demo-test-project'

    # Create a Simple Log Service client.
    client = LogClient(endpoint, access_key_id, access_key)

    # Create an SQL instance. You can specify the number of CUs for the SQL instance. Valid values: 1 to 5000.
    print("===sample_create_sql_instance===")
    res = client.create_sql_instance(project_name, 500, False)
    res.log_print()

    # Obtain the configurations of the SQL instance.
    print("===sample_list_sql_instance===")
    res = client.list_sql_instance(project_name)
    res.log_print()


if __name__ == '__main__':
    main()

Sample response

===sample_create_sql_instance===
CreateSqlInstanceResponse:
request_id: 6729B91518FF9F4603162886
headers: {'Server': 'AliyunSLS', 'Content-Length': '0', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 05 Nov 2024 06:20:06 GMT', 'x-log-time': '1730787606', 'x-log-requestid': '6729B91518FF9F4603162886'}
response:
===sample_list_sql_instance===
ListSqlInstanceResponse:
request_id: 6729B916D86F8B7ED6F5A15F
headers: {'Server': 'AliyunSLS', 'Content-Type': 'application/json', 'Content-Length': '152', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Date': 'Tue, 05 Nov 2024 06:20:06 GMT', 'x-log-time': '1730787606', 'x-log-requestid': '6729B916D86F8B7ED6F5A15F'}
response: [{'createTime': 1730786020, 'cu': 500, 'name': 'group1', 'updateTime': 1730787605, 'useAsDefault': False}]

Process finished with exit code 0