Amazon Redshift
管理指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

使用适用于 Java 的 AWS 开发工具包管理参数组

本示例演示以下与参数组相关的任务:

  • 创建参数组

  • 修改参数组

  • 将参数组与群集相关联

  • 获取关于参数组的信息

此示例创建一个新的参数组 parametergroup1,然后进行以下更新:

  • 将参数 extra_float_digits 从默认值 0 更改为 2。

  • 使用以下 JSON 替换现有的工作负载管理配置(wlm_json_configuration 参数),其作用是在默认队列之外再定义一个队列。

    Copy
    [ { "user_group":[ "example_user_group1" ], "query_group":[ "example_query_group1" ], "query_concurrency":7 }, { "query_concurrency":5 } ]

前面的 JSON 是两个对象的数组,每个对象对应一个队列。第一个对象定义的队列具有特定的用户组和查询组。它还将并发级别设置为 7。

Copy
{ "user_group":[ "example_user_group1" ], "query_group":[ "example_query_group1" ], "query_concurrency":7 }

因为此示例替换 WLM 配置,所以此 JSON 配置还定义了未指定特定用户组或查询组的默认队列。它将并发设置为默认值 5。

Copy
{ "query_concurrency":5 }

有关工作负载管理 (WML) 配置的更多信息,请转到实施工作负载管理

有关运行以下示例的分步说明,请参阅 使用 Eclipse 运行 Amazon Redshift 的 Java 示例。您需要更新该代码并提供群集标识符。

Copy
import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.redshift.AmazonRedshiftClient; import com.amazonaws.services.redshift.model.*; public class CreateAndModifyClusterParameterGroup { public static AmazonRedshiftClient client; public static String clusterParameterGroupName = "parametergroup1"; public static String clusterIdentifier = "***provide cluster identifier***"; public static String parameterGroupFamily = "redshift-1.0"; public static void main(String[] args) throws IOException { AWSCredentials credentials = new PropertiesCredentials( CreateAndModifyClusterParameterGroup.class .getResourceAsStream("AwsCredentials.properties")); client = new AmazonRedshiftClient(credentials); try { createClusterParameterGroup(); modifyClusterParameterGroup(); associateParameterGroupWithCluster(); describeClusterParameterGroups(); } catch (Exception e) { System.err.println("Operation failed: " + e.getMessage()); } } private static void createClusterParameterGroup() { CreateClusterParameterGroupRequest request = new CreateClusterParameterGroupRequest() .withDescription("my cluster parameter group") .withParameterGroupName(clusterParameterGroupName) .withParameterGroupFamily(parameterGroupFamily); client.createClusterParameterGroup(request); System.out.println("Created cluster parameter group."); } private static void describeClusterParameterGroups() { DescribeClusterParameterGroupsResult result = client.describeClusterParameterGroups(); printResultClusterParameterGroups(result); } private static void modifyClusterParameterGroup() { List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter() .withParameterName("extra_float_digits") .withParameterValue("2")); // Replace WLM configuration. The new configuration defines a queue (in addition to the default). parameters.add(new Parameter() .withParameterName("wlm_json_configuration") .withParameterValue("[{\"user_group\":[\"example_user_group1\"],\"query_group\":[\"example_query_group1\"],\"query_concurrency\":7},{\"query_concurrency\":5}]")); ModifyClusterParameterGroupRequest request = new ModifyClusterParameterGroupRequest() .withParameterGroupName(clusterParameterGroupName) .withParameters(parameters); client.modifyClusterParameterGroup(request); } private static void associateParameterGroupWithCluster() { ModifyClusterRequest request = new ModifyClusterRequest() .withClusterIdentifier(clusterIdentifier) .withClusterParameterGroupName(clusterParameterGroupName); Cluster result = client.modifyCluster(request); System.out.format("Parameter Group %s is used for Cluster %s\n", clusterParameterGroupName, result.getClusterParameterGroups().get(0).getParameterGroupName()); } private static void printResultClusterParameterGroups(DescribeClusterParameterGroupsResult result) { if (result == null) { System.out.println("\nDescribe cluster parameter groups result is null."); return; } System.out.println("\nPrinting parameter group results:\n"); for (ClusterParameterGroup group : result.getParameterGroups()) { System.out.format("\nDescription: %s\n", group.getDescription()); System.out.format("Group Family Name: %s\n", group.getParameterGroupFamily()); System.out.format("Group Name: %s\n", group.getParameterGroupName()); describeClusterParameters(group.getParameterGroupName()); } } private static void describeClusterParameters(String parameterGroupName) { DescribeClusterParametersRequest request = new DescribeClusterParametersRequest() .withParameterGroupName(parameterGroupName); DescribeClusterParametersResult result = client.describeClusterParameters(request); printResultClusterParameters(result, parameterGroupName); } private static void printResultClusterParameters(DescribeClusterParametersResult result, String parameterGroupName) { if (result == null) { System.out.println("\nCluster parameters is null."); return; } System.out.format("\nPrinting cluster parameters for \"%s\"\n", parameterGroupName); for (Parameter parameter : result.getParameters()) { System.out.println(" Name: " + parameter.getParameterName() + ", Value: " + parameter.getParameterValue()); System.out.println(" DataType: " + parameter.getDataType() + ", MinEngineVersion: " + parameter.getMinimumEngineVersion()); System.out.println(" AllowedValues: " + parameter.getAllowedValues() + ", Source: " + parameter.getSource()); System.out.println(" IsModifiable: " + parameter.getIsModifiable() + ", Description: " + parameter.getDescription()); } } }