Chinaunix

标题: postgresql-slony-I同步复制配置步骤 [打印本页]

作者: huangxifeng607    时间: 2010-02-20 17:30
标题: postgresql-slony-I同步复制配置步骤

                主数据库: 172.16.254.21 端口:5432
从数据库: 172.16.254.22 端口:5432
步骤1:主从均安装slon
      apt-get install slon-bin
步骤2:主从数据库配置权限,创建语言。
在主数据库中   vi /etc/postgresql/8.3/node/pg_hba.conf
添加一条记录    host    all         repl         172.16.254.22/32  md5
在主从数据库均执行以下操作:
   shell>psql
   node=#create role repl password '123456' login superuser
   #创建用户repl,赋予超级用户权限
   node=# use node;
   node=# create language plpgsql;
   #创建语言plpgsql
步骤3:备份主数据库至从数据库并恢复
   #在主数据库备份要复制的数据库
   pg_dump node > node_20100220.dmp
   #在从库恢复数据库node   
   postgres=#create database node;
   postgres=#\q
   shell>psql node > /export/scripts/master.log &
    $SLON $CLUSTER_NAME "$SLAVE" >> /export/scripts/slave.log &
}
stop()
{
  #  killall slon
     kill -9 `ps axu|grep 'dbname=node' |grep -v grep|awk '{print $2}'`
}
case $1 in
    'install')
        install
        ;;
    'uninstall')
        uninstall
        ;;
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    *)
        echo "usage: $0 {install|uninstall|start|stop} "
        ;;
esac
步骤5:启动
./replication start
步骤6:测试
1.在主数据库的空表public.hxf中添加一条记录
insert into hxf(uid,uname) select 1,'huangxifeng';
2.在主数据库中看到有一条记录
node=# select * from hxf;
uid |    uname   
-----+-------------
   1 | huangxifeng
(1 row)
3.在从数据库中看到有一条记录
node=# select * from hxf;
uid |    uname   
-----+-------------
   1 | huangxifeng
(1 row)
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/66215/showart_2182947.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2