Postgresql9.2 主备设置

1.1 主机说明

主服务器:192.168.1.120

备用服务器:192.168.1.121

1.2 配置主服务器

说明:从库只安装数据库软件,不进行数据库初始化。

1)         创建归档目录

mkdir /usr/local/pgsql/archive

chown postgres:postgres /usr/local/pgsql/archive

2)         修改主服务器的PostgreSQL配置../data/postgresql.conf

vi postgresql.conf

listen_address = 'localhost,192.168.1.120,192.168.1.121'

wal_level = hot_standby

max_wal_senders = 10 (根据实际情况自己设置即可)#客户端连接数

archive_mode = on

archive_command = 'cp %p /usr/local/pgsql/archive/%f'

wal_keep_segments = 8 #保留归档个数,每个16M

3)         在主服务器的PostgreSQL中配置pg_hba.conf文件中的参数

vi pg_hba.conf

host    replication     all     192.168.1.121/32        trust

创建复制用户

create user repl2 replication login encrypted password 'repl2';

4)         重载配置

service postgresql restart或者不重启执行pg_ctl reload重载配置

5)         登录psql开始备份

psql -U postgres

执行

select pg_start_backup('hot_backup'); #可使用任意符号做备份标记

拷贝数据文件到备用机

scp -r /usr/local/pgsql/data/* 192.168.1.121:/usr/local/pgsql/data

select pg_stop_backup();

1.3 配置备用服务器

1)         修改配置文件

vi postgresql.conf

hot_standby = on

data目录下创建recovery.conf

vi recovery.conf

添加

standby_mode = 'on'

primary_conninfo = 'host=192.168.1.120 user=repl2 port=5432'

修改文件权限

chown -R postgres:postgres /usr/local/pgsql

重启主服务器,然后启动备用服务器


猜你喜欢

转载自blog.51cto.com/yntmdr/2137226