{{< details >}}

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: 极狐GitLab 私有化部署

{{< /details >}}

将极狐GitLab 数据库迁移到不同的 PostgreSQL 实例

有时需要将数据库从一个 PostgreSQL 实例移动到另一个。例如,如果您正在使用 AWS Aurora 并准备启用数据库负载均衡,则需要将数据库迁移到 RDS for PostgreSQL。

要将数据库从一个实例迁移到另一个实例:

  1. 收集源和目标 PostgreSQL 端点信息:

    SRC_PGHOST=<source postgresql host>
    SRC_PGUSER=<source postgresql user>
    
    DST_PGHOST=<destination postgresql host>
    DST_PGUSER=<destination postgresql user>
    
  2. 停止极狐GitLab:

    sudo gitlab-ctl stop
    
  3. 从源导出数据库:

    /opt/gitlab/embedded/bin/pg_dump -h $SRC_PGHOST -U $SRC_PGUSER -c -C -f gitlabhq_production.sql gitlabhq_production
    /opt/gitlab/embedded/bin/pg_dump -h $SRC_PGHOST -U $SRC_PGUSER -c -C -f praefect_production.sql praefect_production
    

    {{< alert type=”note” >}}

    在极少数情况下,您可能会注意到在执行 pg_dump 和恢复后出现数据库性能问题。这可能是因为 pg_dump 不包含用于优化器进行查询计划决策的统计信息。如果恢复后性能下降,请通过找到问题查询来解决问题,然后在查询使用的表上运行 ANALYZE。

    {{< /alert >}}

  4. 将数据库恢复到目标(这将覆盖任何具有相同名称的现有数据库):

    /opt/gitlab/embedded/bin/psql -h $DST_PGHOST -U $DST_PGUSER -f praefect_production.sql postgres
    /opt/gitlab/embedded/bin/psql -h $DST_PGHOST -U $DST_PGUSER -f gitlabhq_production.sql postgres
    
  5. 可选。如果从不使用 PgBouncer 的数据库迁移到使用 PgBouncer 的数据库,则必须手动向应用程序数据库(通常是 gitlabhq_production)添加 pg_shadow_lookup 函数
  6. /etc/gitlab/gitlab.rb 文件中配置极狐GitLab 应用程序服务器,以适当的连接详细信息设置您的目标 PostgreSQL 实例:

    gitlab_rails['db_host'] = '<destination postgresql host>'
    

    有关极狐GitLab 多节点设置的更多信息,请参考 参考架构

  7. 重新配置以使更改生效:

    sudo gitlab-ctl reconfigure
    
  8. 重启极狐GitLab:

    sudo gitlab-ctl start