Aurora 我的SQL就地升級教程 - Amazon Aurora

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Aurora 我的SQL就地升級教程

下列 Linux 範例顯示如何使用 AWS CLI.

第一個範例會建立執行 2.x 版本的 Aurora MySQL. 叢集包含寫入器資料庫執行個體和讀取器資料庫執行個體。wait db-instance-available 命令會暫停,直至寫入器資料庫執行個體可供使用為止。這正是叢集準備好升級之時。

aws rds create-db-cluster --db-cluster-identifier mynewdbcluster --engine aurora-mysql \ --db-cluster-version 5.7.mysql_aurora.2.10.2 ... aws rds create-db-instance --db-instance-identifier mynewdbcluster-instance1 \ --db-cluster-identifier mynewdbcluster --db-instance-class db.t4g.medium --engine aurora-mysql ... aws rds wait db-instance-available --db-instance-identifier mynewdbcluster-instance1

您可以升級叢集的 Aurora My SQL 3.x 版本,以取決於叢集目前正在執行的 2.x 版本以及 AWS 區域 叢集所在的位置。使用第一個命令 --output text,只是顯示可用的目標版本。第二個命令顯示響應的完整JSON輸出。在該回應中,您可以查看詳細資訊,例如用於 engine 參數的 aurora-mysql 值。您還可以查看升級至 3.02.0 代表主要版本升級的事實。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].{EngineVersion:EngineVersion}' --output text 5.7.mysql_aurora.2.10.2 aws rds describe-db-engine-versions --engine aurora-mysql --engine-version 5.7.mysql_aurora.2.10.2 \ --query '*[].[ValidUpgradeTarget]' ... { "Engine": "aurora-mysql", "EngineVersion": "8.0.mysql_aurora.3.02.0", "Description": "Aurora MySQL 3.02.0 (compatible with MySQL 8.0.23)", "AutoUpgrade": false, "IsMajorVersionUpgrade": true, "SupportedEngineModes": [ "provisioned" ], "SupportsParallelQuery": true, "SupportsGlobalDatabases": true, "SupportsBabelfish": false }, ...

此範例說明,如果您輸入的目標版本編號不是叢集的有效升級目標,Aurora 不會執行升級。Aurora 也不會執行主要版本升級,除非您包含 --allow-major-version-upgrade 參數。如此一來,您就不會意外執行可能需要對應用程式的程式碼進行大量測試和變更的升級。

aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 5.7.mysql_aurora.2.09.2 --apply-immediately An error occurred (InvalidParameterCombination) when calling the ModifyDBCluster operation: Cannot find upgrade target from 5.7.mysql_aurora.2.10.2 with requested version 5.7.mysql_aurora.2.09.2. aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --region us-east-1 --apply-immediately An error occurred (InvalidParameterCombination) when calling the ModifyDBCluster operation: The AllowMajorVersionUpgrade flag must be present when upgrading to a new major version. aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --apply-immediately --allow-major-version-upgrade { "DBClusterIdentifier": "mynewdbcluster", "Status": "available", "Engine": "aurora-mysql", "EngineVersion": "5.7.mysql_aurora.2.10.2" }

叢集和相關資料庫執行個體的狀態需要一段時間才能變更為 upgrading。叢集和資料庫執行個體的版本編號只有在升級完成時才會變更。同樣,您可以使用寫入器資料庫執行個體的 wait db-instance-available 命令,等到升級完成後再繼續進行。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].[Status,EngineVersion]' --output text upgrading 5.7.mysql_aurora.2.10.2 aws rds describe-db-instances --db-instance-identifier mynewdbcluster-instance1 \ --query '*[].{DBInstanceIdentifier:DBInstanceIdentifier,DBInstanceStatus:DBInstanceStatus} | [0]' { "DBInstanceIdentifier": "mynewdbcluster-instance1", "DBInstanceStatus": "upgrading" } aws rds wait db-instance-available --db-instance-identifier mynewdbcluster-instance1

此時,叢集的版本編號符合針對升級指定的版本編號。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].[EngineVersion]' --output text 8.0.mysql_aurora.3.02.0

上述範例透過指定 --apply-immediately 參數立即執行升級。若要讓升級在方便的時間,當叢集不忙碌時發生,您可以指定 --no-apply-immediately 參數。這樣做會在叢集的下一個維護時段期間啟動升級。維護時段會定義維護操作可以開始的期間。長時間執行的操作可能無法在維護時段完成。因此,即使您預期升級可能需要很長時間,也不需要定義較大的維護時段。

下列範例會升級最初執行 Aurora My SQL 版本 2.10.2 的叢集。在 describe-db-engine-versions 輸出中,FalseTrue 值表示 IsMajorVersionUpgrade 屬性。從 2.10.2 版開始,您可以升級至其他 2.* 版本。這些升級不會視為主要版本升級,因此不需要就地升級。就地升級僅適用於升級至清單中顯示的 3.* 版。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster \ --query '*[].{EngineVersion:EngineVersion}' --output text 5.7.mysql_aurora.2.10.2 aws rds describe-db-engine-versions --engine aurora-mysql --engine-version 5.7.mysql_aurora.2.10.2 \ --query '*[].[ValidUpgradeTarget]|[0][0]|[*].[EngineVersion,IsMajorVersionUpgrade]' --output text 5.7.mysql_aurora.2.10.3 False 5.7.mysql_aurora.2.11.0 False 5.7.mysql_aurora.2.11.1 False 8.0.mysql_aurora.3.01.1 True 8.0.mysql_aurora.3.02.0 True 8.0.mysql_aurora.3.02.2 True aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster \ --engine-version 8.0.mysql_aurora.3.02.0 --no-apply-immediately --allow-major-version-upgrade ...

在沒有指定維護時段的情況下建立叢集時,Aurora 會隨機挑選一週中的一天。在這種情況下,modify-db-cluster 命令會在週一提交。因此,我們將維護時段變更為週二上午。所有時間均以UTC時區表示。tue:10:00-tue:10:30 時段對應於太平洋時間上午 2:00-2:30。維護時段中的變更會立即生效。

aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster --query '*[].[PreferredMaintenanceWindow]' [ [ "sat:08:20-sat:08:50" ] ] aws rds modify-db-cluster --db-cluster-identifier mynewdbcluster --preferred-maintenance-window tue:10:00-tue:10:30" aws rds describe-db-clusters --db-cluster-identifier mynewdbcluster --query '*[].[PreferredMaintenanceWindow]' [ [ "tue:10:00-tue:10:30" ] ]

下列範例顯示如何取得升級產生事件的報告。--duration 引數代表擷取事件資訊的分鐘數。此引數是必要的,因為依預設describe-events只會傳回最後一小時的事件。

aws rds describe-events --source-type db-cluster --source-identifier mynewdbcluster --duration 20160 { "Events": [ { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "DB cluster created", "EventCategories": [ "creation" ], "Date": "2022-11-17T01:24:11.093000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Performing online pre-upgrade checks.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T22:57:08.450000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Performing offline pre-upgrade checks.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T22:57:59.519000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Creating pre-upgrade snapshot [preupgrade-mynewdbcluster-5-7-mysql-aurora-2-10-2-to-8-0-mysql-aurora-3-02-0-2022-11-18-22-55].", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:00:22.318000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Cloning volume.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:01:45.428000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Purging undo records for old row versions. Records remaining: 164", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:02:25.141000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Purging undo records for old row versions. Records remaining: 164", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:06:23.036000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Upgrade in progress: Upgrading database objects.", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:06:48.208000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" }, { "SourceIdentifier": "mynewdbcluster", "SourceType": "db-cluster", "Message": "Database cluster major version has been upgraded", "EventCategories": [ "maintenance" ], "Date": "2022-11-18T23:10:28.999000+00:00", "SourceArn": "arn:aws:rds:us-east-1:123456789012:cluster:mynewdbcluster" } ] }