postgresql主从java_PostgreSQL一主两从实现及主从切换

HA 实现方式:

热备份、冷备份

冷备份:物理备份,也就是文件复制。主机写完一个WAL日志文件后,才复制到standby服务器上去应用。

热备份:流复制,也就是同步复制或异步复制。主备机实时同步。

一主两从操作步骤:

在三台机器分别按照步骤1-4安装pg数据包

1、 安装

./configure –prefix=/usr/pgsql9.3.4 –with-perl –with-openssl –with-pam –without-ldap –with-libxml –with-libxslt –enable-thread-safety –with-wal-blocksize=16 –with-blocksize=16

make world

make install-world

2、添加用户

groupadd postgres

useradd -g postgres postgres

passwd postgres

3、修改内核参数

vim /etc/sysctl.conf

#Kernel paramaters required by Postgresql

kernel.shmmni = 4096

kernel.sem = 250 32000 100 128

fs.file-max = 65536

net.ipv4.ip_local_port_range = 1024 65000

net.core.rmem_default = 1048576

net.core.rmem_max = 1048576

net.core.wmem_default = 262144

net.core.wmem_max = 262144

sysctl -p

vim /etc/security/limits.conf

postgres soft nproc 16384

postgres hard nproc 16384

postgres soft nofile 65536

postgres hard nofile 65536

4、增加.bash_profile环境变量

export PGHOME=/usr/pgsql9.3.4

export PATH=PGHOME/bin:PATH:.

export MANPATH=PGHOM@H_404_121@E/share/man:

MANPATH

5、主:172.18.18.99

su - postgres

123

1》mkdir /data/pgdata/pg_primary

2》mkdir /data/pgdata/pg_primary_data

3》/usr/pgsql9.3.4/bin/initdb -D /data/pgdata/pg_primary/ -E UTF8 –locale=C -U postgres -W

4》数据库参数

postgresql.conf//修改port等等(直接拿99开发机配置库配置文件替换)

pg_hba.conf //修改如下

修改pg_hba.conf:(METHOD 和 最后一项ADDRESS)

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only

local all all md5

# IPv4 l

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值