部署
1 启动原生PG作为主
1.1 PG14.2源码编译安装
./configure --enable-depend --enable-cassert --enable-debug CFLAGS="-ggdb -O0" --prefix=/home/postgres/psql14_pg make && make install
其中,configure选项参考CONFIGURE-OPTIONS
1.2 初始化数据
cd /home/postgres/psql14_pg ./bin/initdb -D /home/postgres/pgdata_14
1.3 修改配置文件
vim /home/postgres/pgdata_14/postgresql.conf port=15432 wal_level = replica wal_recycle=off
修改访问控制文件
vim /home/postgres/pgdata_14/pg_hba.conf host repl all 0.0.0.0/0 trust
1.4 启动服务
./bin/pg_ctl -D /home/postgres/pgdata_14 start -l logfile
1.5 创建流复制用户
./bin/psql -h127.0.0.1 -p15432 postgres=# CREATE ROLE repl login replication encrypted password 'repl';
2 启动He3DB作为备
2.1 编译安装PG He3DB
//编译需要依赖静态库 he3pg/src/backend/storage/file/librust_log.a ./configure --enable-depend --enable-cassert --enable-debug CFLAGS="-ggdb -O0" --prefix=/home/postgres/psqlhe3_mirror make && make install
2.2 从主备份数据
cd /home/postgres/psqlhe3_mirror ./bin/pg_basebackup -h 127.0.0.1 -p 15432 -U repl -R -Fp -Xs -Pv -D /home/postgres/pgdata_mirror
2.3 修改postgres.conf配置
vim /home/postgres/pgdata_mirror/postgresql.conf // 配置文件最后添加配置 primary_conninfo = 'application_name=pushstandby user=repl host=127.0.0.1 port=15432 sslmode=disable sslcompression=0 gssencmode=disable target_session_attrs=any' hot_standby=on port = 5434 push_standby=on wal_recycle=off fsync=off wal_keep_size=10000 full_page_writes=off he3mirror=true
2.4 启动服务
./bin/pg_ctl -D /home/postgres/pgdata_mirror start -l logfile
3 验证
3.1 链接主插入新数据
./bin/psql -h127.0.0.1 -p15432 postgres=# create table "t1" (id int); CREATE TABLE postgres=# insert into t1 values(1); INSERT 0 1
3.2 备机验证数据
./bin/psql -h127.0.0.1 -p5434 postgres=# select * from t1; id ---- 1 (1 row)
3.3 链接主插入新数据
./bin/psql -h127.0.0.1 -p15432
postgres=# insert into t1 values(2);
INSERT 0 1
3.4 备机验证数据
./bin/psql -h127.0.0.1 -p5434 postgres=# select * from t1; id ---- 1 2 (2 row)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




