
apecloud/apecloud-postgresApeCloud postgres offering is committed to providing a robust and highly available database solution. This is achieved by integrating "postgres with consensus hook" and implementing the raft consensus algorithm through a "consensus extension." The comprehensive architecture is meticulously designed to minimize data loss, boasting an impressive Recovery Point Objective (RPO) of 0, which essentially eliminates acceptable data loss. Moreover, the system is geared towards ensuring rapid recovery in the face of failures, exemplified by a low Recovery Time Objective (RTO).
docker network create --driver bridge \ --gateway=192.168.0.1 --subnet 192.168.0.0/24 \ my_pg_network
docker run -d \ --name test-apepg1 \ --network my_pg_network \ --ip 192.168.0.2 \ -p 54322:5432 \ -e POSTGRES_HOST_AUTH_METHOD=md5 \ -e POSTGRES_PASSWORD=password \ -e CONSENSUS_MODE=leader \ -e CONSENSUS_POSTGRESQL_HOST=192.168.0.2 \ apecloud/apecloud-postgres:14.10-0.7.0
PGPASSWORD=password psql -Upostgres -h127.0.0.1 -p 54322 \ -c "select role from consensus_member_status"
docker run -d \ --name test-apepg2 \ --network my_pg_network \ --ip 192.168.0.3 \ -p 54323:5432 \ -e POSTGRES_HOST_AUTH_METHOD=md5 \ -e POSTGRES_PASSWORD=password \ -e CONSENSUS_MODE=follower \ -e CONSENSUS_POSTGRESQL_HOST=192.168.0.3 \ -e CONSENSUS_CLUSTER_LEADER_HOST=192.168.0.2 \ -e CONSENSUS_CLUSTER_LEADER_PORT=5432 \ apecloud/apecloud-postgres:14.10-0.7.0
docker run -d \ --name test-apepg3 \ --network my_pg_network \ --ip 192.168.0.4 \ -p 54324:5432 \ -e POSTGRES_HOST_AUTH_METHOD=md5 \ -e POSTGRES_PASSWORD=password \ -e CONSENSUS_MODE=follower \ -e CONSENSUS_POSTGRESQL_HOST=192.168.0.4 \ -e CONSENSUS_CLUSTER_LEADER_HOST=192.168.0.2 \ -e CONSENSUS_CLUSTER_LEADER_PORT=5432 \ apecloud/apecloud-postgres:14.10-0.7.0
PGPASSWORD=password psql -Upostgres -h127.0.0.1 -p 54322 \ -c "select * from consensus_cluster_status"
server_id | ip_port | match_index | next_index | role | has_voted | force_sync | election_weight | learner_source | pipelining -----------+-------------------+-------------+------------+----------+-----------+------------+-----------------+----------------+------------ 1 | 192.168.0.2:*** | 23 | 0 | Leader | t | f | 5 | 0 | f 2 | 192.168.0.3:*** | 23 | 24 | Follower | f | f | 5 | 0 | t 3 | 192.168.0.4:*** | 23 | 24 | Follower | f | f | 5 | 0 | t (3 rows)
$ PGPASSWORD=password psql -Upostgres -h127.0.0.1 -p 5432 psql (14.10 (with consensus 0.7.0 PGTAG=CONSENSUS_HOOK_2_1_0_PG_14_10)) Type "help" for help. postgres=# select version(); version ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 14.10 (with consensus 0.7.0 PGTAG=CONSENSUS_HOOK_2_1_0_PG_14_10) on aarch64-unknown-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit
The current instance is enabled with the consensus feature by setting the CONSENSUS_MODE environment variable, and the instance is started with the specified role.
-e CONSENSUS_MODE={leader | follower}
If it is a leader: Initialize a new instance, add consensus configuration parameters to the postgresql.conf file, and then start the instance. It's important to note that if a custom postgresql.conf configuration file is used through the POSTGRESQL_MOUNTED_CONF_DIR environment variable when the container starts, the postgresql.conf won't be reconfigured.The following parameters must be set in the postgresql.conf configuration file:
shared_preload_libraries = 'consensus' consensus.consensus_enabled = true
If it is a follower: Backup data from the leader node based on the specified CONSENSUS_CLUSTER_LEADER_HOST and CONSENSUS_CLUSTER_LEADER_PORT parameters, then join the cluster in the follower role.
The IP address of the current instance serving as a consensus cluster node is used with the default PORT of 5432. This 'IP:PORT' combination is utilized for the interaction of consensus information among various nodes in the consensus cluster.
-e CONSENSUS_POSTGRESQL_HOST=192.168.0.3
The IP for the existing Consensus cluster's Leader role node.
-e CONSENSUS_CLUSTER_LEADER_HOST=192.168.0.2
The PORT for the existing Consensus cluster's Leader role node.
-e CONSENSUS_CLUSTER_LEADER_PORT=5432
The replication user created on the leader on first run. 'replicator' defaults.
-e POSTGRESQL_REPLICATION_USER=repl
The replication users password. 'replicator' defaults.
-e POSTGRESQL_REPLICATION_PASSWORD=password
Specify the directory for externally mounted configuration files. When Docker startup, the files located in the mounted directory, under POSTGRESQL_MOUNTED_CONF_DIR, will be copied to the PGDATA directory, thereby overwriting the postgresql.conf and pg_hba.conf files.
-e POSTGRESQL_MOUNTED_CONF_DIR=/conf \ -v /u01/conf:/conf
As an alternative to passing sensitive information via environment variables, _FILE may be appended to some of the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container. In particular, this can be used to load passwords from Docker secrets stored in /run/secrets/<secret_name> files. Currently, this is only supported for POSTGRESQL_REPLICATION_USER, POSTGRESQL_REPLICATION_PASSWORD, POSTGRES_INITDB_ARGS, POSTGRES_PASSWORD, POSTGRES_USER, and POSTGRES_DB.For example:
echo "apecloud" > /u01/secret/postgres_user.txt echo "mypassword" > /u01/secret/postgres_password.txt echo "repl" > /u01/secret/postgres_replication_user.txt echo "repl_password" > /u01/secret/postgres_replication_password.txt docker run -d \ --name test-apepg \ -e POSTGRES_USER_FILE=/run/secrets/postgres_user.txt \ -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password.txt \ -e POSTGRESQL_REPLICATION_USER_FILE=/run/secrets/postgres_replication_user.txt \ -e POSTGRESQL_REPLICATION_PASSWORD_FILE=/run/secrets/postgres_replication_password.txt \ -v /u01/secret:/run/secrets \ apecloud/apecloud-postgres:14.10-0.7.0
If starting as a follower role by mounting the data directory to /var/lib/postgresql/data using the -v parameter, it is necessary to create a .backup_restore file in the data directory. If this file is not created, the new consensus cluster will be started directly as a Leader role.
PGPASSWORD=replicator pg_basebackup -h 127.0.0.1 -p 54322 -U replicator -w \ -D $PWD/pgconsensus_volume2 -X stream \ -P -v cd $PWD/pgconsensus_volume2 echo "" >> .backup_restore -v $PWD/pgconsensus_volume2:/var/lib/postgresql/data
docker run -d \ --name test-apepg \ --network my_pg_network \ --ip 192.168.0.2 \ -p 54322:5432 \ -e CONSENSUS_MODE=leader \ -e CONSENSUS_POSTGRESQL_HOST=192.168.0.2 \ -e CONSENSUS_CLUSTER_LEADER_HOST=192.168.0.2 \ -e POSTGRESQL_MOUNTED_CONF_DIR=/conf \ -v /u01/conf:/conf \ -e POSTGRES_HOST_AUTH_METHOD=md5 \ -e POSTGRES_DB=apecloud \ -e POSTGRES_USER=apecloud \ -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password.txt \ -e POSTGRESQL_REPLICATION_USER=repl \ -e POSTGRESQL_REPLICATION_PASSWORD_FILE=/run/secrets/postgres_replication_password.txt \ -v /u01/secret:/run/secrets \ -e POSTGRES_INITDB_ARGS="--data-checksums" \ -e POSTGRES_INITDB_WALDIR="/waldir" \ -v /u01/initdb-scripts:/docker-entrypoint-initdb.d \ apecloud/apecloud-postgres:14.10-0.7.0

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像服务
在 Docker Desktop 配置镜像
Docker Compose 项目配置
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
MacOS OrbStack 容器配置
在宝塔面板一键配置镜像
Synology 群晖 NAS 配置
飞牛 fnOS 系统配置镜像
极空间 NAS 系统配置服务
爱快 iKuai 路由系统配置
绿联 NAS 系统配置镜像
QNAP 威联通 NAS 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
免费版仅支持 Docker Hub 访问,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等;免费版仅支持 docker.io。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
来自真实用户的反馈,见证轩辕镜像的优质服务