Mengupgrade cluster

Cuplikan ini menunjukkan cara melakukan upgrade di tempat klaster ke versi database yang lebih baru. Pengguna akan melakukannya untuk memanfaatkan fitur baru, peningkatan performa, dan perbaikan keamanan yang tersedia di versi target.

Contoh kode

C#

Untuk melakukan autentikasi ke AlloyDB, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

using Google.Cloud.AlloyDb.V1;
using Google.LongRunning;

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for UpgradeCluster</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 UpgradeCluster()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        string name = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]";
        DatabaseVersion version = DatabaseVersion.Unspecified;
        // Make the request
        Operation<UpgradeClusterResponse, OperationMetadata> response = alloyDBAdminClient.UpgradeCluster(name, version);

        // Poll until the returned long-running operation is complete
        Operation<UpgradeClusterResponse, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        UpgradeClusterResponse result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<UpgradeClusterResponse, OperationMetadata> retrievedResponse = alloyDBAdminClient.PollOnceUpgradeCluster(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            UpgradeClusterResponse retrievedResult = retrievedResponse.Result;
        }
    }
}

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contohGoogle Cloud .