PostgreSQL学习第十六篇 异步流复制Hot Standby的示例

配置环境:

主机名
IP地址
角色
数据目录
pg
186.168.100.14
主库
/PostgreSQL/9.6.1/datan
pghs
186.168.100.24
standby
/PostgreSQL/9.6.1/datahs

主数据库的配置:
允许主库接受流复制的连接pg_hba.conf中:
host    replication     postgres       186.168.100.0/24                  trust

postgresql.conf设置:
listen_addresses = '*'
max_wal_senders = 5
wal_level = hot_standby
重启数据库


standby上的操作:
在备库生成基础备份:
[postgres@pghs data]$ pg_basebackup -h 186.168.100.14 -U postgres -F p -P -x -R -D /PostgreSQL/9.6.1/datahs -l  postgresbackup20170209
45089/45089 kB (100%), 2/2 tablespaces


那么在/PostgreSQL/9.6.1/datahs 路径下就看到了拷贝过来的文件等,因为使用了-R,所以有recovery.conf文件,内容:、
standby_mode = 'on'
primary_conninfo = 'user=postgres host=186.168.100.14 port=5432 sslmode=disable sslcompression=1'

在启动standby数据库之前,需要修改postgresql.conf文件:
hot_standby = on

启动standby:
[postgres@pghs datahs]$ pg_ctl start -D /PostgreSQL/9.6.1/datahs/
server starting
[postgres@pghs datahs]$ FATAL:  data directory "/PostgreSQL/9.6.1/datahs" has group or world access
DETAIL:  Permissions should be u=rwx (0700).

[postgres@pghs 9.6.1]$ chmod 700 datahs/
[postgres@pghs 9.6.1]$ LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".


在主库建一个表,然后插入几条数据:
postgres=# create table testhsb(id int,name varchar(10));
CREATE TABLE
postgres=# insert into testhsb values (1,'test');
INSERT 0 1

备库查询:
postgres=# select * from testhsb;
 id | name
----+------
  1 | test
(1 row)

操作马上就同步了
在备库尝试修改:
postgres=# delete from testhsb where id=1;
ERROR:  cannot execute DELETE in a read-only transaction

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丹心明月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值