postgresql 主从配置

安装postgresql

主从是否一定需要分两台机器,主从必须要同一个版本,不然启动会报错。

3. 配置Master数据库

su – postgres

/usr/local/pgsql/bin/pg_ctl –D /data/pgsql9.1 start #启动数据库

#进入数据库创建repl用户

Psql –p 5432 –U postgres –h 127.0.0.1

Create user repl superuser password ‘密码’

\q

 

#修改postgresql.conf文件

vi /data/pgsql9.1/postgresql.conf

listen_addresses = '*' //监听地址

wal_level = hot_standby // 同步级别, 最小的,档案,hot_standby,或逻辑,(更改后需要重新启动)

synchronous_commit = on // 是否同步,on表示需要同步到其他服务器

max_wal_senders = 2 // 同步最大的进程数量

wal_keep_segments = 32 // 日志文件段大小,默认为16M,0表示禁用

full_page_writes=on


synchronous_standby_names = '*' /* 提供同步代理的备用服务器
* 逗号分隔的列表application_name
* 从待机状态(S);“*”=所有 */

 

#修改pg_hba.conf文件

vi /data/pgsql9.1/pg_hba.conf

#允许局域网中md5密码认证连接

host all all 192.168.100.0/24 md5

#用户数据同步,必须为replication数据库

host replication repl 192.168.100.0/24 md5

#用户在当前数据库服务器无密码连接

local all all trust

 

 

#重启数据库

Su – postgres

/usr/local/pgsql/bin/pg_ctl –D /data/pgsql9.1 restart

 

posted on 2016-08-31 17:13  mywebnumber  阅读(1143)  评论(0编辑  收藏  举报