删除实例

您可以使用其中一个 Bigtable 客户端库以编程方式删除实例,也可以使用 Google Cloud 控制台、Google Cloud CLI 或 cbt CLI 手动删除实例:

控制台

  1. 在 Google Cloud 控制台中打开 Bigtable 实例列表。

    打开实例列表

  2. 点击要删除的实例,然后点击删除实例。 此时会显示一个确认对话框。

    “删除实例”对话框的屏幕截图

  3. 按照确认对话框中的说明操作,然后点击删除。 该实例将被永久删除。

gcloud

  1. 如果您尚未安装 Google Cloud CLI,请进行安装。
  2. 如果您不知道实例 ID,请使用 bigtable instances list 命令查看项目的实例列表:

    gcloud bigtable instances list
    
  3. 使用 bigtable instances delete 命令删除实例:

    gcloud bigtable instances delete INSTANCE_ID
    

    INSTANCE_ID 替换为实例的永久性标识符。

cbt

  1. 安装 cbt CLI(如果您尚未安装)。
  2. 如果您不知道实例 ID,请使用 listinstances 命令查看项目的实例列表:

    cbt listinstances
    
  3. 使用 deleteinstance 命令删除实例:

    cbt deleteinstance INSTANCE_ID
    

    INSTANCE_ID 替换为实例的永久性标识符。

C++

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Status;
[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id, std::string const& instance_id) {
  std::string instance_name = cbt::InstanceName(project_id, instance_id);
  Status status = instance_admin.DeleteInstance(instance_name);
  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Successfully deleted the instance " << instance_id << "\n";
}

C#

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

// Deletes an instance from the project.
// Initialize request argument(s).
DeleteInstanceRequest request = new DeleteInstanceRequest
{
    InstanceName = new InstanceName(projectId, instanceId)
};
try
{
    // Make request.
    Console.WriteLine("Waiting for operation to complete...");
    bigtableInstanceAdminClient.DeleteInstance(request);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception while deleting {instanceId} instance");
    Console.WriteLine(ex.Message);
}

Java

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

try {
  adminClient.deleteInstance(instanceId);
  System.out.println("Instance deleted: " + instanceId);
} catch (NotFoundException e) {
  System.err.println("Failed to delete non-existent instance: " + e.getMessage());
}

Node.js

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

console.log('Deleting Instance');
await instance.delete();
console.log(`Instance deleted: ${instance.id}`);

PHP

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\DeleteInstanceRequest;

/**
 * Delete a bigtable instance
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance to be deleted
 */
function delete_instance(
    string $projectId,
    string $instanceId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

    printf('Deleting Instance' . PHP_EOL);
    try {
        $deleteInstanceRequest = (new DeleteInstanceRequest())
            ->setName($instanceName);
        $instanceAdminClient->deleteInstance($deleteInstanceRequest);
        printf('Deleted Instance: %s.' . PHP_EOL, $instanceId);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Instance %s does not exists.' . PHP_EOL, $instanceId);
        } else {
            throw $e;
        }
    }
}

Python

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

print("\nDeleting instance")
if not instance.exists():
    print("Instance {} does not exist.".format(instance_id))
else:
    instance.delete()
    print("Deleted instance: {}".format(instance_id))

Ruby

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

如需向 Bigtable 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

instance.delete