百度智能云

All Product Document

          Relational Database Service

          Instance Management

          Instance Management

          The cloud database RDS (Relational Database Service) is a professional cloud database service of high-performance and highly reliability. RDS provides Web interface to configure and operate database instances, and provide you with reliable data backup and recovery, complete security management, sound monitoring, easy expansion and other functional support.

          Create RDS master instance

          Use the following codes to create an RDS master instance

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.CreateRdsArgs{
          	// specify database engine of rds, take mysql, sqlserver, postgresql, required
              Engine:            "mysql",
              // specify database version of rds, required
              EngineVersion:  "5.6",
              // billing related parameters, and take PaymentTiming as prepaid: post-paid; Reservation:there is no need to set it when the payment method is postpaid but it must be set when the payment method is prepaid; required
              Billing: rds.Billing{
                  PaymentTiming: "Postpaid",
                  //Reservation: rds.Reservation{ReservationLength: 1, ReservationTimeUnit: "Month"},
              },
              // automatic renewal parameters AutoRenewTime and AutoRenewtimeUnit can be specified during prepaid payment
              // automatic renewal time (renewal unit is year, not greater than 3 and renewal unit is mouth, not greater than 9)
              // AutoRenewTime: 1,
              // automatic renewal unit("year";"mouth")
              // AutoRenewTimeUnit: "year",
              // CPU count, required
              CpuCount: 1,
              //package memory capacity, in GB, required
              MemoryCapacity: 1,
              //package disk capacity, in GB, increasing every 5G, required
              VolumeCapacity: 5,
              //number of RDS instances created in batch, not more than 10, 1 by default, optional
              PurchaseCount: 1,
              //rds instance name, lowercase letters and numbers allowed, length limited to 1~32, etc. default naming rule:{engine} + {engineVersion},optional
              InstanceName: "instanceName",
              //series,Basic:stand-alone basic version,Standard:dual-engine HA version. Only SQLServer 2012sp3 supports stand-alone basic version. Standard by default, optional
              Category: "Standard",
              //specify zone information, blank by default, selected by system automatically, optional
              //the naming rule for zoneName is "country -region- available region sequence" in lowercase, for example, Beijing available region A is "cn-bj-a".
              ZoneNames: ["cn-bj-a"],
              //vpc,if not provided, then take the default vpc, optional
              VpcId: "vpc-IyrqYIQ7",
              //whether to pay directly, false by default, deduction will be made directly for the change order set as pay directly, and there is no need to perform the payment logic, optional
              IsDirectPay: false,
              //subnetId of each available area in vpc; if it is not the default vpc, the subnetId must be specified, optional
              Subnets: []rds.SubnetMap{
                  {
                      ZoneName: "cn-bj-a",
                      SubnetId: "sbn-IyWRnII7",
                  },   
              },
              // label information bound to instance, optional
              Tags: []model.TagModel{
                  {
                      TagKey:   "tagK",
                      TagValue: "tagV",
                  },
              },
          }
          result, err := client.CreateRds(args)
          if err != nil {
              fmt.Printf("create rds error: %+v\n", err)
              return
          }
          
          for _, e := range result.InstanceIds {
          	fmt.Println("create rds success, instanceId: ", e)
          }

          Note:

          • For instance packages available, see details in (https://cloud.baidu.com/doc/RDS/s/9jwvz0wd3)
          • The billing method for postpaid instance is, the account cash balance+general vouchers should be greater than 100; and the billing method for prepaid instance is, the account cash balance should be greater than or equal to the instance fee.
          • Batch creation is supported, and if the creation of any one of instances fails, all instances will be rolled back and the creation of all of them will fail.
          • The creation of interface is an asynchronous operation, the status of instance can be queried by the interface for querying specified instance details.

          Create RDS read-only instance

          Use the following codes to create an RDS read only instance

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.CreateReadReplicaArgs{
              //master Instance ID, required
              SourceInstanceId: "sourceInstanceId"
              // billing related parameters, read-only instances only support Postpaid, required
              Billing: rds.Billing{
                  PaymentTiming: "Postpaid",
              },
              // CPU count, required
              CpuCount: 1,
              //package memory capacity, in GB, required
              MemoryCapacity: 1,
              //package disk capacity, in GB, increasing every 5G, required
              VolumeCapacity: 5,
              //batch creation of RDS read-only instances of cloud database. Currently only one instance is supported, optional
              PurchaseCount: 1,
              //instance name, lowercase letters and numbers allowed, length limited to 1~32, etc. default naming rule:{engine} + {engineVersion},optional
              InstanceName: "instanceName",
              //specify zone information, blank by default, selected by system automatically, optional
              //the naming rule for zoneName is "country -region- available region sequence" in lowercase, for example, Beijing available region A is "cn-bj-a".
              ZoneNames: ["cn-bj-a"],
              //same as master instance vpcID, optional
              VpcId: "vpc-IyrqYIQ7",
              //whether to pay directly, false by default, deduction will be made directly for the change order set as pay directly, and there is no need to perform the payment logic, optional
              IsDirectPay: false,
              //subnetId of each available area in vpc;if it is not the default vpc, the subnetId must be specified, optional
              Subnets: []rds.SubnetMap{
                  {
                      ZoneName: "cn-bj-a",
                      SubnetId: "sbn-IyWRnII7",
                  },   
              },
              // label information bound to instance, optional
              Tags: []model.TagModel{
                  {
                      TagKey:   "tagK",
                      TagValue: "tagV",
                  },
              },
          }
          result, err := client.CreateReadReplica(args)
          if err != nil {
              fmt.Printf("create rds readReplica error: %+v\n", err)
              return
          }
          
          for _, e := range result.InstanceIds {
          	fmt.Println("create rds readReplica success, instanceId: ", e)
          }

          Note:

          • It is required to create on the basis of the RDS master instance
          • For instance packages available, see details in (https://cloud.baidu.com/doc/RDS/s/9jwvz0wd3)
          • Only the master instance of which the database type is MySQL supports the creation of read-only instances
          • The database engine and database version of the read-only instance are the same as those of the master instance, which has no need to set up, the minimum version of the master instance is MySQL 5.6
          • The disk capacity of the read-only instance cannot be less than that of the master instance
          • The vpcId of the read-only instance should be consistent with the master instance
          • An RDS instance can only have 5 read-only instances at most, and only one instance can be created at a time
          • The read-only instances can be purchased by post-paid method only

          Create RDS proxy instance

          Use the following codes to create an RDS proxy instance

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.CreateRdsProxyArgs{
              //master instancee ID, required
              SourceInstanceId: "sourceInstanceId"
              // billing related parameters, proxy instance only supports Postpaid, required
              Billing: rds.Billing{
                  PaymentTiming: "Postpaid",
              },
              // number of proxy instance nodes. The value can be 2,4,6,8,16,required
              NodeAmount: 2,
              //instance name. Lowercase letters and numbers are allowed, and the length is limited to 1~32. The default naming rule is:{engine} + {engineVersion},optional
              InstanceName: "instanceName",
              //specify zone information, blank by default, selected by system automatically, optional
              //the naming rule for zoneName is "country -region- available region sequence" in lowercase, for example, Beijing available region A is "cn-bj-a", so it is suggested to keep the available region same as that of the master instance
              ZoneNames: ["cn-bj-a"],
              //same as master instance vpcID, optional
              VpcId: "vpc-IyrqYIQ7",
              //whether to pay directly, false by default, deduction will be made directly for the change order set as pay directly, and there is no need to perform the payment logic, optional
              IsDirectPay: false,
              //subnetId of each available area in vpc; if it is not the default vpc, the subnetId must be specified, optional
              Subnets: []rds.SubnetMap{
                  {
                      ZoneName: "cn-bj-a",
                      SubnetId: "sbn-IyWRnII7",
                  },   
              },
              // label information bound to instance, optional
              Tags: []model.TagModel{
                  {
                      TagKey:   "tagK",
                      TagValue: "tagV",
                  },
              },
          }
          result, err := client.CreateRdsProxy(args)
          if err != nil {
              fmt.Printf("create rds proxy error: %+v\n", err)
              return
          }
          
          for _, e := range result.InstanceIds {
          	fmt.Println("create rds proxy success, instanceId: ", e)
          }

          Note:

          • It is required to create on the basis of the RDS master instance
          • Only the master instance of which the database type is MySQL supports the creation of read-only instances
          • The proxy instance package is bound to the master instance package, and the minimum version of the master instance is MySQL 5.6
          • At most one proxy instance can be created under one master instance
          • The proxy instance should be created in the same vpc as the master instance
          • The proxy instances can be purchased by pre-paid method only

          Query RDS List

          Use the following codes to query the RDS list.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.ListRdsArgs{
              // get the starting position of the list query in batch, which is a string generated by the system, optional
              Marker: "marker",
              // specify the maximum number (master instance) contained in each page, the maximum number does not exceed 1000, and the default value is 1000, optional
              MaxKeys: 1,
          }
          result, err := client.ListRds(args)
          if err != nil {
              fmt.Printf("list rds error: %+v\n", err)
              return
          }
          
          // return the starting position of the marked query
          fmt.Println("rds list marker: ", result.Marker)
          // true indicates that there are data behind, and false indicates that it is the last page
          fmt.Println("rds list isTruncated: ", result.IsTruncated)
          // get the marker value to be transmitted on the next page. When isTruncated is false, the domain does not appear
          fmt.Println("rds list nextMarker: ", result.NextMarker)
          // max number contained on each page
          fmt.Println("rds list maxKeys: ", result.MaxKeys)
          // get rds list information
          for _, e := range result.Instances {
              fmt.Println("rds instanceId: ", e.InstanceId)
              fmt.Println("rds instanceName: ", e.InstanceName)
              fmt.Println("rds engine: ", e.Engine)
              fmt.Println("rds engineVersion: ", e.EngineVersion)
              fmt.Println("rds instanceStatus: ", e.InstanceStatus)
              fmt.Println("rds cpuCount: ", e.CpuCount)
              fmt.Println("rds memoryCapacity: ", e.MemoryCapacity)
              fmt.Println("rds volumeCapacity: ", e.VolumeCapacity)
              fmt.Println("rds usedStorage: ", e.UsedStorage)
              fmt.Println("rds paymentTiming: ", e.PaymentTiming)
              fmt.Println("rds instanceType: ", e.InstanceType)
              fmt.Println("rds instanceCreateTime: ", e.InstanceCreateTime)
              fmt.Println("rds instanceExpireTime: ", e.InstanceExpireTime)
              fmt.Println("rds publicAccessStatus: ", e.PublicAccessStatus)
              fmt.Println("rds vpcId: ", e.VpcId)
          }

          Note:

          • Only the list of instances under own account can be viewed.
          • The interface divides each master instance and its read-only and proxy instances under the master instance into a group, parameter maxKeys represents the number of groups, that is, the number of master instances.

          Query the specified RDS instance information

          Use the following codes to query the specified RDS instance information.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          result, err := client.GetDetail(instanceId)
          if err != nil {
              fmt.Printf("get rds detail error: %+v\n", err)
              return
          }
          
          fmt.Println("rds instanceId: ", result.InstanceId)
          fmt.Println("rds instanceName: ", result.InstanceName)
          fmt.Println("rds engine: ", result.Engine)
          fmt.Println("rds engineVersion: ", result.EngineVersion)
          fmt.Println("rds instanceStatus: ", result.InstanceStatus)
          fmt.Println("rds cpuCount: ", result.CpuCount)
          fmt.Println("rds memoryCapacity: ", result.MemoryCapacity)
          fmt.Println("rds volumeCapacity: ", result.VolumeCapacity)
          fmt.Println("rds usedStorage: ", result.UsedStorage)
          fmt.Println("rds paymentTiming: ", result.PaymentTiming)
          fmt.Println("rds instanceType: ", result.InstanceType)
          fmt.Println("rds instanceCreateTime: ", result.InstanceCreateTime)
          fmt.Println("rds instanceExpireTime: ", result.InstanceExpireTime)
          fmt.Println("rds publicAccessStatus: ", result.PublicAccessStatus)
          fmt.Println("rds vpcId: ", result.VpcId)

          Delete RDS instance

          Use the following codes to delete the RDS list.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          //multiple instances are separated by English comma ",", and up to 10 can be entered
          if err := client.DeleteRds(instanceIds); err != nil {
              fmt.Printf("delete rds error: %+v\n", err)
              return
          }
          fmt.Printf("delete rds success\n")

          Note:

          • Only the Postpaid instances or the expired instances of which the payment type of Prepaid can be released.
          • If the master instance is released, then the read-only instances and proxy instances associated with the master instance will also be released.

          RDS instance capacity expansion or reduction

          Use the following codes to expand and reduce the RDS instance.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.ResizeRdsArgs{
          	// cpu count
              CpuCount: 2,
              // memory capacity, in GB
              MemoryCapacity: 8,
              // disk capacity, in GB, increasing every 5G
              VolumeCapacity: 20,
              // 代number of proxy instance nodes, required when proxy instance is changed
              NodeAmount: 2,
              // whether to pay directly, false by default, deduction will be made directly for the change order set as pay directly, and there is no need to perform the payment logic, optional
              IsDirectPay: false,
          }
          err = client.ResizeRds(instanceId, args)
          if err != nil {
              fmt.Printf("resize rds error: %+v\n", err)
              return
          }
          
          fmt.Println("resize rds success.")

          Note:

          • For instance packages available, see details in (https://cloud.baidu.com/doc/RDS/s/9jwvz0wd3)
          • At least one of cpuCount, memoryCapacity and volumeCapacity should be filled in when the master instancee or read-only instance is changed.
          • when the billing method of instance is post-paid, the capacity can be expanded or reduced flexibly; when the billing method is prepaid, the capacity cannot be reduced.
          • The capacity expansion or reduction can be performed only when the instance is in the available status.
          • The instance will be restarted once after the capacity is expanded or reduced.
          • It is an asynchronous interface. Whether instanceStatus is restored can be viewed by the interface for querying the instance details.

          Restart instance

          Use the following codes to restart the instance.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          err := client.RebootInstance(instanceId)
          if err != nil {
              fmt.Printf("reboot rds error: %+v\n", err)
              return
          }

          Modify instance name

          Use the following codes to modify the RDS instance name.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.UpdateInstanceNameArgs{
              InstanceName: "instanceName",
          }
          err = client.UpdateInstanceName(instanceId, args)
          if err != nil {
              fmt.Printf("update instance name error: %+v\n", err)
              return
          }
          fmt.Printf("update instance name success\n")

          Note:

          • The instance names can contain uppercase and lowercase letters, numbers and special characters such as-_/. but it must begin with letters and have a length of 1-64.

          Modify synchronization mode

          Use the following codes to modify the RDS instance synchronization mode.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.ModifySyncModeArgs{
              //"Async"asynchronous replicatio,"Semi_sync"semi-synchronous replication.
              SyncMode: "Async",
          }
          err = client.ModifySyncMode(instanceId, args)
          if err != nil {
              fmt.Printf("modify syncMode error: %+v\n", err)
              return
          }
          fmt.Printf("modify syncMode success\n")

          Modify connection information

          Use the following codes to modify the RDS domain name prefix.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.ModifyEndpointArgs{
              Address: "newAddress",
          }
          err = client.ModifyEndpoint(instanceId, args)
          if err != nil {
              fmt.Printf("modify endpoint error: %+v\n", err)
              return
          }
          fmt.Printf("modify endpoint success\n")

          Note:

          • It only needs to transmit the prefix of the domain name. The prefix of domain name consists of lowercase letters and numbers, beginning with lowercase letters, between 3 and 30 digits.

          Open and close public network access

          Use the following codes to modify the RDS domain name prefix.

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.ModifyPublicAccessArgs{
              // true or false
              PublicAccess: true,
          }
          err = client.ModifyPublicAccess(instanceId, args)
          if err != nil {
              fmt.Printf("modify public access error: %+v\n", err)
              return
          }
          fmt.Printf("modify public access success\n")

          Note:

          • true:open public network access; false:close public network access.

          Open automatic renewal

          Use the following code to open automatic renewal for prepaid instances that have been created

          // import "github.com/baidubce/bce-sdk-go/services/rds"
          
          args := &rds.AutoRenewArgs{
              // automatic renewal time (renewal unit is year, not greater than 3, renewal unit is month, not greater than 9)
          	AutoRenewTime: 1,
              // automatic renewal unit ("year";"month")required
          	AutoRenewTimeUnit: "year",
              // instance id set required
              InstanceIds: []string{
                  "rds-y9dJu77d", 
                  "rds-aQFOoncr",
              },
          }
          err := client.AutoRenew(args)
          if err != nil {
              fmt.Printf("create auto renew error: %+v\n", err)
              return
          }

          Note:

          • This interface is used to enable the automatic renewal function of instances created.
          • Multiple instance ids can be uploaded, and all of the instances must be in the same region.
          Previous
          Initialization
          Next
          Account Management