postgresql异步standby的搭建

主库的配置
1配置pg_hba.conf文件
host     replication     postgres        10.2.13.0/24            md5
host     replication     postgres        10.3.13.0/24            md5
2配置posgresql。conf文件
listen_addresses = '*'
max_wal_senders = 5
wal_level = hot_standby
3在standby上生成基础备份
pg_basebackup -h 10.2.13.1 -U postgres -F p -P -x -R -D /var/lib/pgsql/9.4/data
standby_mode = 'on'
primary_conninfo = 'user=postgres password=postgres host=10.2.13.1 port=5432 sslmode=prefer sslcompression=1 krbsrvname=postgres'
4配置config文件 hot_standby=on
-bash-4.1$ 
检查异步流复制的情况
postgres=# select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication;
 pid  |   state   | client_addr | sync_priority | sync_state 
------+-----------+-------------+---------------+------------
 8856 | streaming | 10.2.13.2   |             0 | async
查看备库落后主库多少字节的wal日志,

postgres=# select pg_xlog_location_diff(pg_current_xlog_location(),replay_location) from pg_stat_replication;
 pg_xlog_location_diff 
-----------------------
                     0
在主库上把wal位置转换成wal文件名和偏移量
postgres=# select * from pg_xlogfile_name_offset('0/5F8862F0');
        file_name         | file_offset 
--------------------------+-------------
 00000001000000000000005F |     8938224
判读数据库是否处于恢复状态
postgres=# select pg_is_in_recovery();
 pg_is_in_recovery 
-------------------
 f
常见问题分析
1 host    replication    postgres        172.17.5.0/24            md5  这个是允许这个网段的主机同步数据
 host     all            all            172.17.5.0/24            trust    还要还应该有一个配置,允许这个网段连接pg数据库啊
备库basebackup连接主库的时候会连接不上,要设置hba配置文件,所以新装的数据库hba文件要配置允许这个网段的服务器连接上数据库
2 主库postgre用户还要修改一下密码
postgres=# \password postgres
Enter new password: 
Enter it again: 
3启动备库的时候宝端口号呗占用
[root@QA-4-45 ~]# ps -ef| grep postgres
postgres  2008     1  0 03:34 ?        00:00:00 /usr/pgsql-9.4/bin/postmaster -D /var/lib/pgsql/9.4/data
postgres  2010  2008  0 03:34 ?        00:00:00 postgres: logger process                                
postgres  2012  2008  0 03:34 ?        00:00:00 postgres: checkpointer process                          
postgres  2013  2008  0 03:34 ?        00:00:00 postgres: writer process                                
postgres  2014  2008  0 03:34 ?        00:00:00 postgres: wal writer process                            
postgres  2015  2008  0 03:34 ?        00:00:04 postgres: autovacuum launcher process                   
postgres  2016  2008  0 03:34 ?        00:00:00 postgres: stats collector process                       
root      2096  1787  0 03:37 pts/0    00:00:00 su - postgres
postgres  2097  2096  0 03:37 pts/0    00:00:00 -bash
root      2234  2221  0 04:13 pts/1    00:00:00 su - postgres
postgres  2235  2234  0 04:13 pts/1    00:00:00 -bash
root      2394  2381  0 05:27 pts/4    00:00:00 su - postgres
postgres  2395  2394  0 05:27 pts/4    00:00:00 -bash
root      2419  2364  0 05:27 pts/3    00:00:00 su - postgres
postgres  2420  2419  0 05:27 pts/3    00:00:00 -bash
root      2543  2527  0 05:52 pts/6    00:00:00 grep postgr
因为是测试机,解决的方法比较暴力重启了服务器,其实可以重postgre服务或者kill掉那个进程就可以解决问题了。
总结,遇到问题从报错出发,还是原理不够明白,还应该养成多看日志的好习惯
一个用户要想成功连接到特定的数据库,不仅需要通过 pg_hba.conf 的检查, 还必须要有该数据库上的 CONNECT 权限。如果希望限制哪些用户能够连接到哪些数据库, 赋予/撤销 CONNECT 权限通常比在 pg_hba.conf 中设置规则简单。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29898569/viewspace-1743301/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29898569/viewspace-1743301/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值