将 DescribeDBParameters 与 Amazon SDK 或 CLI 配合使用 - Amazon Relational Database Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

DescribeDBParameters 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 DescribeDBParameters

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

/// <summary> /// Get a list of DB parameters from a specific parameter group. /// </summary> /// <param name="dbParameterGroupName">Name of a specific DB parameter group.</param> /// <param name="source">Optional source for selecting parameters.</param> /// <returns>List of parameter values.</returns> public async Task<List<Parameter>> DescribeDBParameters(string dbParameterGroupName, string source = null) { var results = new List<Parameter>(); var paginateParameters = _amazonRDS.Paginators.DescribeDBParameters( new DescribeDBParametersRequest() { DBParameterGroupName = dbParameterGroupName, Source = source }); // Get the entire list using the paginator. await foreach (var parameters in paginateParameters.Parameters) { results.Add(parameters); } return results; }
  • 有关 API 详细信息,请参阅《Amazon SDK for .NET API 参考》中的 DescribeDBParameters

C++
SDK for C++
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); //! Routine which gets DB parameters using the 'DescribeDBParameters' api. /*! \sa getDBParameters() \param parameterGroupName: The name of the parameter group. \param namePrefix: Prefix string to filter results by parameter name. \param source: A source such as 'user', ignored if empty. \param parametersResult: Vector of 'Parameter' objects returned by the routine. \param client: 'RDSClient' instance. \return bool: Successful completion. */ bool AwsDoc::RDS::getDBParameters(const Aws::String &parameterGroupName, const Aws::String &namePrefix, const Aws::String &source, Aws::Vector<Aws::RDS::Model::Parameter> &parametersResult, const Aws::RDS::RDSClient &client) { Aws::String marker; do { Aws::RDS::Model::DescribeDBParametersRequest request; request.SetDBParameterGroupName(PARAMETER_GROUP_NAME); if (!marker.empty()) { request.SetMarker(marker); } if (!source.empty()) { request.SetSource(source); } Aws::RDS::Model::DescribeDBParametersOutcome outcome = client.DescribeDBParameters(request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::RDS::Model::Parameter> &parameters = outcome.GetResult().GetParameters(); for (const Aws::RDS::Model::Parameter &parameter: parameters) { if (!namePrefix.empty()) { if (parameter.GetParameterName().find(namePrefix) == 0) { parametersResult.push_back(parameter); } } else { parametersResult.push_back(parameter); } } marker = outcome.GetResult().GetMarker(); } else { std::cerr << "Error with RDS::DescribeDBParameters. " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!marker.empty()); return true; }
  • 有关 API 详细信息,请参阅《Amazon SDK for C++ API 参考》中的 DescribeDBParameters

CLI
Amazon CLI

描述数据库参数组中的参数

以下 describe-db-parameters 示例将检索有关指定数据库参数组的详细信息。

aws rds describe-db-parameters \ --db-parameter-group-name mydbpg

输出:

{ "Parameters": [ { "ParameterName": "allow-suspicious-udfs", "Description": "Controls whether user-defined functions that have only an xxx symbol for the main function can be loaded", "Source": "engine-default", "ApplyType": "static", "DataType": "boolean", "AllowedValues": "0,1", "IsModifiable": false, "ApplyMethod": "pending-reboot" }, { "ParameterName": "auto_generate_certs", "Description": "Controls whether the server autogenerates SSL key and certificate files in the data directory, if they do not already exist.", "Source": "engine-default", "ApplyType": "static", "DataType": "boolean", "AllowedValues": "0,1", "IsModifiable": false, "ApplyMethod": "pending-reboot" }, ...some output truncated... ] }

有关更多信息,请参阅《Amazon RDS 用户指南》中的使用数据库参数组

Go
适用于 Go V2 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

type DbInstances struct { RdsClient *rds.Client } // GetParameters gets the parameters that are contained in a DB parameter group. func (instances *DbInstances) GetParameters(ctx context.Context, parameterGroupName string, source string) ( []types.Parameter, error) { var output *rds.DescribeDBParametersOutput var params []types.Parameter var err error parameterPaginator := rds.NewDescribeDBParametersPaginator(instances.RdsClient, &rds.DescribeDBParametersInput{ DBParameterGroupName: aws.String(parameterGroupName), Source: aws.String(source), }) for parameterPaginator.HasMorePages() { output, err = parameterPaginator.NextPage(ctx) if err != nil { log.Printf("Couldn't get parameters for %v: %v\n", parameterGroupName, err) break } else { params = append(params, output.Parameters...) } } return params, err }
  • 有关 API 详细信息,请参阅《Amazon SDK for Go API 参考》中的 DescribeDBParameters

Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

// Retrieve parameters in the group. public static void describeDbParameters(RdsClient rdsClient, String dbGroupName, int flag) { try { DescribeDbParametersRequest dbParameterGroupsRequest; if (flag == 0) { dbParameterGroupsRequest = DescribeDbParametersRequest.builder() .dbParameterGroupName(dbGroupName) .build(); } else { dbParameterGroupsRequest = DescribeDbParametersRequest.builder() .dbParameterGroupName(dbGroupName) .source("user") .build(); } DescribeDbParametersResponse response = rdsClient.describeDBParameters(dbParameterGroupsRequest); List<Parameter> dbParameters = response.parameters(); String paraName; for (Parameter para : dbParameters) { // Only print out information about either auto_increment_offset or // auto_increment_increment. paraName = para.parameterName(); if ((paraName.compareTo("auto_increment_offset") == 0) || (paraName.compareTo("auto_increment_increment ") == 0)) { System.out.println("*** The parameter name is " + paraName); System.out.println("*** The parameter value is " + para.parameterValue()); System.out.println("*** The parameter data type is " + para.dataType()); System.out.println("*** The parameter description is " + para.description()); System.out.println("*** The parameter allowed values is " + para.allowedValues()); } } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
  • 有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 DescribeDBParameters

Python
SDK for Python (Boto3)
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

class InstanceWrapper: """Encapsulates Amazon RDS DB instance actions.""" def __init__(self, rds_client): """ :param rds_client: A Boto3 Amazon RDS client. """ self.rds_client = rds_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ rds_client = boto3.client("rds") return cls(rds_client) def get_parameters(self, parameter_group_name, name_prefix="", source=None): """ Gets the parameters that are contained in a DB parameter group. :param parameter_group_name: The name of the parameter group to query. :param name_prefix: When specified, the retrieved list of parameters is filtered to contain only parameters that start with this prefix. :param source: When specified, only parameters from this source are retrieved. For example, a source of 'user' retrieves only parameters that were set by a user. :return: The list of requested parameters. """ try: kwargs = {"DBParameterGroupName": parameter_group_name} if source is not None: kwargs["Source"] = source parameters = [] paginator = self.rds_client.get_paginator("describe_db_parameters") for page in paginator.paginate(**kwargs): parameters += [ p for p in page["Parameters"] if p["ParameterName"].startswith(name_prefix) ] except ClientError as err: logger.error( "Couldn't get parameters for %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return parameters
  • 有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK(Boto3)API 参考》中的 DescribeDBParameters

Ruby
适用于 Ruby 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

require 'aws-sdk-rds' # v2: require 'aws-sdk' # List all Amazon Relational Database Service (Amazon RDS) parameter groups. # # @param rds_resource [Aws::RDS::Resource] An SDK for Ruby Amazon RDS resource. # @return [Array, nil] List of all parameter groups, or nil if error. def list_parameter_groups(rds_resource) parameter_groups = [] rds_resource.db_parameter_groups.each do |p| parameter_groups.append({ "name": p.db_parameter_group_name, "description": p.description }) end parameter_groups rescue Aws::Errors::ServiceError => e puts "Couldn't list parameter groups:\n #{e.message}" end
  • 有关 API 详细信息,请参阅《Amazon SDK for Ruby API 参考》中的 DescribeDBParameters

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。