要在Aurora PostgreSQL中创建一个区域性集群,并使用多个地区的读取副本,可以按照以下步骤操作:
aws rds create-db-cluster \
--db-cluster-identifier my-cluster \
--engine aurora-postgresql \
--engine-version 12.4 \
--master-username admin \
--master-user-password password \
--availability-zones us-west-2a,us-west-2b \
--database-name mydatabase \
--vpc-security-group-ids sg-12345678 \
--scaling-configuration MinCapacity=2,MaxCapacity=4,AutoPause=false
aws rds create-db-instance \
--db-instance-identifier my-replica \
--db-cluster-identifier my-cluster \
--db-instance-class db.r5.large \
--availability-zone us-west-2b \
--no-publicly-accessible
aws rds modify-db-cluster \
--db-cluster-identifier my-cluster \
--global-cluster-identifier my-global-cluster
aws rds create-db-instance \
--db-instance-identifier my-global-replica \
--db-cluster-identifier my-global-cluster \
--db-instance-class db.r5.large \
--availability-zone eu-west-1b \
--no-publicly-accessible
等待副本创建完成,并确保所有副本都处于可用状态。
使用连接字符串连接到Aurora PostgreSQL集群。在连接字符串中指定主区域的终结点,例如my-cluster.cluster-123456789012.us-west-2.rds.amazonaws.com
。
在应用程序中使用连接字符串连接到全局读取副本。在连接字符串中指定全局读取副本的终结点,例如my-global-cluster.cluster-123456789012.eu-west-1.rds.amazonaws.com
。
现在,您可以在主区域和全局读取副本之间进行读取负载均衡。根据应用程序的需求,您可以选择只读取主区域或从全局读取副本中读取数据。