AnolisOS 8.8 PostgreSQL 流复制搭建

前面我们已经搭建和安装好一台配置有 PostgreSQL 服务的实例,按照这个方法安装好另外一台服务器,其 IP 地址为 192.168.30.141。接下来我们配置 PostgreSQL 的流复制。

在服务器 141 上
[root@localhost anolisos]# cd ~
[root@localhost ~]# su - postgres
[postgres@localhost ~]$ cd /usr/local/pgsql-14/data/
[postgres@localhost data]$ cp postmaster.opts ../
[postgres@localhost data]$ rm -rf ./*
[postgres@localhost data]$ pg_basebackup -h 192.168.30.140 -p 5432 -U postgres -Fp -P -X stream -R -D /usr/local/pgsql-14/data/
Password: 
67659/67659 kB (100%), 1/1 tablespace
[postgres@localhost data]$ mv ../postmaster.opts ./
[postgres@localhost data]$ pg_ctl restart -D /usr/local/pgsql-14/data/

在服务器 140 上
[postgres@localhost data]$ ps -ef | grep wal
postgres    3456    3451  0 14:22 ?        00:00:00 postgres: walwriter 
postgres    3515    3451  0 14:27 ?        00:00:00 postgres: walsender postgres 192.168.30.141(34042) streaming 0/4000060
postgres    3559    3208  0 14:29 pts/0    00:00:00 grep --color=auto wal
[postgres@localhost data]$

在服务器 141 上
[postgres@localhost data]$ ps -ef | grep wal
postgres    3396    3390  0 14:27 ?        00:00:00 postgres: walreceiver streaming 0/4000060
postgres    3416    3086  0 14:29 pts/0    00:00:00 grep --color=auto wal
[postgres@localhost data]$ 

在服务器 140 上
[postgres@localhost data]$ psql 
psql (14.7)
Type "help" for help.

postgres=# \x
Expanded display is on.
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid              | 3515
usesysid         | 10
usename          | postgres
application_name | walreceiver
client_addr      | 192.168.30.141
client_hostname  | 
client_port      | 34042
backend_start    | 2024-08-12 14:27:47.202992+08
backend_xmin     | 
state            | streaming
sent_lsn         | 0/4000060
write_lsn        | 0/4000060
flush_lsn        | 0/4000060
replay_lsn       | 0/4000060
write_lag        | 
flush_lag        | 
replay_lag       | 
sync_priority    | 0
sync_state       | async
reply_time       | 2024-08-12 14:31:07.686188+08

postgres=# 

到这一步 PostgreSQL 流复制搭建成功。可以自己创建库、表然后分别在 140 141 上观察。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值