只需一种选项,以下是对原句的中文翻译:AWS Aurora PostgreSQL进行主要版本更新

首先

这是Metaps Advent Calendar第一天的帖子。

由于Aurora PostgreSQL 11系即将到达支持结束生命周期(EOL),我们将进行到14系的重大版本升级。
https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/AuroraUserGuide/Aurora.VersionPolicy.html?utm_source=pocket_mylist#Aurora.VersionPolicy.MajorVersionLifetime

目录

    • 事前準備

 

    • メンテナンス化

 

    • バージョンアップ

 

    • Anylyze実行

 

    メンテナンス解除

前期准备

创建参数组

    Postgre14系のパラメーターグループ作成(terraform実行)
# aws_rds_cluster_parameter_group.foo-aurora-postgresql14:
resource "aws_rds_cluster_parameter_group" "foo-aurora-postgresql14" {
    description = "foo-aurora-postgresql14"
    family      = "aurora-postgresql14"
    name        = "foo-aurora-postgresql14"
    tags        = {}
    parameter {
        apply_method = "immediate"
        name         = "log_min_duration_statement"
        value        = "-1"
    }
    parameter {
        apply_method = "immediate"
        name         = "log_statement"
        value        = "none"
    }
}
# aws_db_parameter_group.foo-aurora-postgresql14:
resource "aws_db_parameter_group" "foo-aurora-postgresql14" {
    description = "foo-aurora-postgresql14"
    family      = "aurora-postgresql14"
    name        = "foo-aurora-postgresql14"
    tags        = {}
}

创建用于确认服务器停机时间的脚本

    どの程度DB接続がダウンするか確認するため、ダウンタイム確認用のスクリプト作成
#!/bin/bash

if [ -z "${1}" ]; then
    echo "Specify hostname."
    exit
fi

pg_isready -h $1 > /dev/null 2>&1
if [ "${?}" = "0" ]; then
    echo -n "[pg_isready] OK"
fi

psql -c "SELECT 1" -h $1 -U foo > /dev/null 2>&1
if [ "${?}" = "0" ]; then
    echo  " [psql query execute] OK"
fi
    スクリプトファイルへ実行権限付与
chmod +x psqlping.sh
    • 実行時にパスワード入力を省略するようにしておく

 

    参考 https://qiita.com/kabi5n/items/48b7701724f189c48814

维护化

    メンテ用の503リスナールールを上位に移動(CLI実行)
ALB_LISTENER_RULE_ARN=arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxxxxxxxxxx
aws elbv2 set-rule-priorities --rule-priorities RuleArn=${ALB_LISTENER_RULE_ARN},Priority=1 --no-cli-pager

升级版本

获取快照

CLUSTER_NAME_LIST=$(cat << EOS
foo-aurora-postgresql-cluster
bar-aurora-postgresql-cluster
baz-aurora-postgresql-cluster
EOS
)

for CLUSTER_NAME in ${CLUSTER_NAME_LIST}
do
aws rds create-db-cluster-snapshot --db-cluster-identifier ${CLUSTER_NAME} --db-cluster-snapshot-identifier ${CLUSTER_NAME}-20231113 --no-cli-pager
done

执行确认计划时间的脚本

while true; do echo -n "$(date) "; ./psqlping.sh foo.ap-northeast-1.rds.amazonaws.com; sleep 0.5; done

版本升级

image.png
image.png

停工的結果

根据环境的不同情况,大约需要12分钟。

2023年  9月 22日 金曜日 02:44:49 UTC [pg_isready] OK [psql query execute] OK
2023年  9月 22日 金曜日 02:44:50 UTC 2023年  9月 22日 金曜日 02:44:50 UTC 2023年  9月 22日 金曜日 02:44:51 UTC 2023年  9月 22日
2023年  9月 22日 金曜日 02:56:47 UTC [pg_isready] OK [psql query execute] OK

分析执行

数据库连接

psql -h foo.ap-northeast-1.rds.amazonaws.com -U foo
\c foo_db

分析

select current_timestamp;ANALYZE VERBOSE;select current_timestamp;

       current_timestamp       
 2023-09-22 13:03:21.496542+09
(1 )
 2023-09-22 13:13:12.62939+09
(1 )

解除维护

    メンテ用の503リスナールールを下位に移動(CLI実行)
ALB_LISTENER_RULE_ARN=arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxxxxxxxxxx
aws elbv2 set-rule-priorities --rule-priorities RuleArn=${ALB_LISTENER_RULE_ARN},Priority=1000 --no-cli-pager
bannerAds