Skip to content

迁移 Postgres 数据到 Google Cloud

GCP: Google Cloud Platform

GCP 提供从 自建 PostgreSQL 数据到 GCP SQL 存储方案:

  • 基于 pglogical
  • 使用发布/订阅模型实现选择性复制数据,复制速度快
  • 支持跨版本 9.5+ => 14.x
  • 可从多个上游同步,实现数据聚集和合并

和 15.x Logical Replication 不一样,不会自动从主同步账号。

迁移要点:

  • 自建主节点有公网 IP ,GCP 节点通过 public out going IP 访问,需要在主开通 iptables 白名单和 pg ;
  • 修改 Ubuntu 环境主 postgres 部分配置(如 max_replication_slots max_wal_senders )需要写最后,否则可能不生效 ;
  • 在 GCP 需副本从主同步时,使用 SSL。设置 SSL 连接,再主上复制 PEM,Ubuntu pg 14.x 环境默认为 ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem' ;
  • 同步后观察 delay bytes 为零,确定无延迟后,需要先停止 migration job 后,再切 replica 为 primary

主需要修改关键选项如下:

ini
...

wal_sender_timeout = 0

shared_preload_libraries = 'pglogical'

max_worker_processes = 10 # 按需改
wal_level = 'logical'

max_replication_slots = 10 # 按需改
max_wal_senders = 10 # 按需改

Released under the CC-BY-NC-4.0