PolarDB for PostgreSQLPolarDB for PostgreSQL
  • 架构简介
  • 快速部署
  • 进阶部署
  • Preparation of Shared-Storage Device

    • 阿里云 ECS + ESSD 云盘存储
  • Preparation of File System

    • 格式化并挂载 PFS
  • Deploying PolarDB

    • 基于单机文件系统部署
    • 基于 PFS 文件系统部署
  • More about Deployment

    • 购买商业版
  • Daily Ops

    • 备份恢复
    • 共享存储在线扩容
    • 计算节点扩缩容
    • Replica 节点在线 Promote
  • Benchmarks

    • TPC-C 测试
    • TPC-H 测试
Kernel Features
  • PolarDB for PostgreSQL

    • Overview
    • HTAP Architecture
    • Buffer Management
    • DDL Synchronization
    • LogIndex
  • PostgreSQL

    • Code Analysis of ANALYZE
    • Sequence
  • 基于 Docker 容器开发
  • 定制开发环境
  • Code Contributing
  • Documentation Contributing
  • Coding Style
  • 问题报告
  • English
  • 简体中文
GitHub
  • 架构简介
  • 快速部署
  • 进阶部署
  • Preparation of Shared-Storage Device

    • 阿里云 ECS + ESSD 云盘存储
  • Preparation of File System

    • 格式化并挂载 PFS
  • Deploying PolarDB

    • 基于单机文件系统部署
    • 基于 PFS 文件系统部署
  • More about Deployment

    • 购买商业版
  • Daily Ops

    • 备份恢复
    • 共享存储在线扩容
    • 计算节点扩缩容
    • Replica 节点在线 Promote
  • Benchmarks

    • TPC-C 测试
    • TPC-H 测试
Kernel Features
  • PolarDB for PostgreSQL

    • Overview
    • HTAP Architecture
    • Buffer Management
    • DDL Synchronization
    • LogIndex
  • PostgreSQL

    • Code Analysis of ANALYZE
    • Sequence
  • 基于 Docker 容器开发
  • 定制开发环境
  • Code Contributing
  • Documentation Contributing
  • Coding Style
  • 问题报告
  • English
  • 简体中文
GitHub
  • Development

    • 基于 Docker 容器开发
    • 定制开发环境

基于 Docker 容器开发

棠羽

2024/08/30

10 min

下载源代码

从 GitHub 上下载 PolarDB for PostgreSQL 的源代码,稳定分支为 POLARDB_15_STABLE:

GitHub
git clone -b POLARDB_15_STABLE https://github.com/ApsaraDB/PolarDB-for-PostgreSQL.git
Gitee
git clone -b POLARDB_15_STABLE https://gitee.com/mirrors/PolarDB-for-PostgreSQL

代码克隆完毕后,进入源码目录:

cd PolarDB-for-PostgreSQL/

拉取开发镜像

拉取 PolarDB-PG 的 开发镜像。

DockerHub
docker pull polardb/polardb_pg_devel:ubuntu24.04
阿里云 ACR
docker pull registry.cn-hangzhou.aliyuncs.com/polardb_pg/polardb_pg_devel:ubuntu24.04

创建并运行容器

此时我们已经在开发机器的源码目录中。从开发镜像上创建一个容器,将当前目录作为一个 volume 挂载到容器中,这样可以:

  • 在容器内的环境中编译源码
  • 在容器外(开发机器上)使用编辑器来查看或修改代码
DockerHub
docker run -it \
    -v $PWD:/home/postgres/polardb_pg \
    --shm-size=512m --cap-add=SYS_PTRACE --privileged=true \
    --name polardb_pg_devel \
    polardb/polardb_pg_devel:ubuntu24.04 \
    bash
阿里云 ACR
docker run -it \
    -v $PWD:/home/postgres/polardb_pg \
    --shm-size=512m --cap-add=SYS_PTRACE --privileged=true \
    --name polardb_pg_devel \
    registry.cn-hangzhou.aliyuncs.com/polardb_pg/polardb_pg_devel:ubuntu24.04 \
    bash

进入容器后,为容器内用户获取源码目录的权限,然后编译部署 PolarDB-PG 实例。

# 获取权限并编译部署
cd polardb_pg
sudo chmod -R a+wr ./
sudo chown -R postgres:postgres ./
./build.sh

# 验证
psql -c 'SELECT version();'
                                   version
----------------------------------------------------------------------
 PostgreSQL 15.x (PolarDB 15.x.x.x build xxxxxxxx) on {your_platform}
(1 row)

构建选项说明

以下表格列出了编译、初始化或测试 PolarDB-PG 集群所可能使用到的选项及说明。更多选项及其说明详见源码目录下的 build.sh 脚本。

选项描述
--wr=N初始化 Replica 节点数量
--ws=N初始化 Standby 节点数量
--ec='--with-pfsd'是否编译 PolarDB File System (PFS) 相关功能
--ni只编译,不拉起示例集群
--port=指定 primary 节点端口号
--debug=[on/off]编译为 Debug / Release 模式

如无定制的需求,则可以按照下面给出的选项编译部署不同形态的 PolarDB-PG 集群并进行测试。

各形态编译部署

本地搭建一个单 Primary 节点:

./build.sh

本地搭建一个 Primary 节点 + 两个 Replica 节点的共享存储集群:

./build.sh --wr=2

本地搭建一个 Primary 节点 + 一个 Replica 节点 + 一个 Standby 节点的集群:

./build.sh --wr=1 --ws=1

回归测试

可以根据机器负载自行调整并行度 $jobs。

Debug 模式:

./build.sh --ws=1 --wr=2 --debug=on --jobs=$jobs --ec="--enable-tap-tests"
make precheck -j$jobs

Release 模式:

./build.sh --ws=1 --wr=2 --debug=off --jobs=$jobs --ec="--enable-tap-tests"
make precheck -j$jobs
Edit this page on GitHub
Last Updated:
Contributors: Shijun.Zhou
Next
定制开发环境