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

DeleteDBParameterGroup 与 Amazon SDK 或 CLI 配合使用

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

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

.NET
Amazon SDK for .NET
注意

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

/// <summary> /// Delete a DB parameter group. The group cannot be a default DB parameter group /// or be associated with any DB instances. /// </summary> /// <param name="name">Name of the DB parameter group.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteDBParameterGroup(string name) { var response = await _amazonRDS.DeleteDBParameterGroupAsync( new DeleteDBParameterGroupRequest() { DBParameterGroupName = name, }); return response.HttpStatusCode == HttpStatusCode.OK; }
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); Aws::RDS::Model::DeleteDBParameterGroupRequest request; request.SetDBParameterGroupName(parameterGroupName); Aws::RDS::Model::DeleteDBParameterGroupOutcome outcome = client.DeleteDBParameterGroup(request); if (outcome.IsSuccess()) { std::cout << "The DB parameter group was successfully deleted." << std::endl; } else { std::cerr << "Error with RDS::DeleteDBParameterGroup. " << outcome.GetError().GetMessage() << std::endl; result = false; }
CLI
Amazon CLI

删除数据库参数组

以下 command 示例删除一个数据库参数组。

aws rds delete-db-parameter-group \ --db-parameter-group-name mydbparametergroup

此命令不生成任何输出。

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

Go
适用于 Go V2 的 SDK
注意

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

type DbInstances struct { RdsClient *rds.Client } // DeleteParameterGroup deletes the named DB parameter group. func (instances *DbInstances) DeleteParameterGroup(ctx context.Context, parameterGroupName string) error { _, err := instances.RdsClient.DeleteDBParameterGroup(ctx, &rds.DeleteDBParameterGroupInput{ DBParameterGroupName: aws.String(parameterGroupName), }) if err != nil { log.Printf("Couldn't delete parameter group %v: %v\n", parameterGroupName, err) return err } else { return nil } }
Java
SDK for Java 2.x
注意

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

// Delete the parameter group after database has been deleted. // An exception is thrown if you attempt to delete the para group while database // exists. public static void deleteParaGroup(RdsClient rdsClient, String dbGroupName, String dbARN) throws InterruptedException { try { boolean isDataDel = false; boolean didFind; String instanceARN; // Make sure that the database has been deleted. while (!isDataDel) { DescribeDbInstancesResponse response = rdsClient.describeDBInstances(); List<DBInstance> instanceList = response.dbInstances(); int listSize = instanceList.size(); didFind = false; int index = 1; for (DBInstance instance : instanceList) { instanceARN = instance.dbInstanceArn(); if (instanceARN.compareTo(dbARN) == 0) { System.out.println(dbARN + " still exists"); didFind = true; } if ((index == listSize) && (!didFind)) { // Went through the entire list and did not find the database ARN. isDataDel = true; } Thread.sleep(sleepTime * 1000); index++; } } // Delete the para group. DeleteDbParameterGroupRequest parameterGroupRequest = DeleteDbParameterGroupRequest.builder() .dbParameterGroupName(dbGroupName) .build(); rdsClient.deleteDBParameterGroup(parameterGroupRequest); System.out.println(dbGroupName + " was deleted."); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
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 delete_parameter_group(self, parameter_group_name): """ Deletes a DB parameter group. :param parameter_group_name: The name of the parameter group to delete. :return: Data about the parameter group. """ try: self.rds_client.delete_db_parameter_group( DBParameterGroupName=parameter_group_name ) except ClientError as err: logger.error( "Couldn't delete parameter group %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • 有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK(Boto3)API 参考》中的 DeleteDBParameterGroup

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