클러스터의 데이터베이스 나열

이 스니펫은 지정된 클러스터 내의 모든 데이터베이스를 나열하는 방법을 보여줍니다. 이 방법은 관리, 모니터링 또는 자동화 작업을 위해 데이터베이스 정보를 검색하는 데 유용합니다.

코드 샘플

C#

AlloyDB에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

using Google.Api.Gax;
using Google.Cloud.AlloyDb.V1;
using System;

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for ListDatabases</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ListDatabases()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        string parent = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]";
        // Make the request
        PagedEnumerable<ListDatabasesResponse, Database> response = alloyDBAdminClient.ListDatabases(parent);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (Database item in response)
        {
            // Do something with each item
            Console.WriteLine(item);
        }

        // Or iterate over pages (of server-defined size), performing one RPC per page
        foreach (ListDatabasesResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (Database item in page)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
        }

        // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
        int pageSize = 10;
        Page<Database> singlePage = response.ReadPage(pageSize);
        // Do something with the page of items
        Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
        foreach (Database item in singlePage)
        {
            // Do something with each item
            Console.WriteLine(item);
        }
        // Store the pageToken, for when the next page is required.
        string nextPageToken = singlePage.NextPageToken;
    }
}

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저 참조하기