刪除執行個體

使用其中一個 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 替換為執行個體的永久 ID。

cbt

  1. 如果尚未安裝 cbt CLI ,請立即安裝。
  2. 如果您不知道執行個體 ID,請使用 listinstances 指令查看專案的執行個體清單:

    cbt listinstances
    
  3. 使用 deleteinstance 指令刪除執行個體:

    cbt deleteinstance INSTANCE_ID
    

    INSTANCE_ID 替換為執行個體的永久 ID。

C++

如要瞭解如何安裝及使用 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 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

// 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 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

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 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

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

PHP

如要瞭解如何安裝及使用 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 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

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 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

instance.delete