原文--http://www.tuicool.com/articles/mMvARf

先谈谈slony的局限性:

1. DDL动作是不会被复制到;

2. 如果想使用slony来同步数据,表必须是带有主键的

内容大家看原文;个人感觉总结的很好!

下面是为slony维护;定制的脚本

包括了服务启动/关闭;以及slony set删除/安装。

#!/bin/sh

SLONIK=/opt/pgsql/bin/slonik
SLON=/opt/pgsql/bin/slon
CLUSTER_NAME=lottu_cluster
MASTERDBNAME=masterdb
SLAVEDBNAME=slavedb
MASTERHOST=192.168.8.121
SLAVEHOST=192.168.8.120
REPLICATIONUSER=postgres
PASSWORD=li0924

uninstall()
{
    $SLONIK << _EOF_
        cluster name = $CLUSTER_NAME;

        node  admin conninfo = 'dbname=$MASTERDBNAME  host=$MASTERHOST user=$REPLICATIONUSER password=$PASSWORD';
        node  admin conninfo = 'dbname=$SLAVEDBNAME  host=$SLAVEHOST user=$REPLICATIONUSER password=$PASSWORD';

        uninstall node (id = );
        uninstall node (id = );
_EOF_
}

install()
{
    $SLONIK << _EOF_
    #--
    # define the namespace the replication system
    # uses in our example it is slony_example
    #--
    cluster name = $CLUSTERNAME;

    #--
    # admin conninfo's are used by slonik to connect to
    # the nodes one for eachnode on each side of the cluster,
    # the syntax is that of PQconnectdb in
    # the C-API
    # --

    node  admin conninfo = 'dbname=$MASTERDBNAME  host=$MASTERHOST user=$REPLICATIONUSER password=$PASSWORD';
    node  admin conninfo = 'dbname=$SLAVEDBNAME  host=$SLAVEHOST user=$REPLICATIONUSER password=$PASSWORD';

    #--
    # init the first node.  Its id MUST be 1.  This creates
    # the schema _$CLUSTERNAME containing all replication
    # system specific database objects.
    #--

    init cluster ( id=, comment = 'Master Node');

    #--
    # Slony-I organizes tables into sets.  The smallest unit
    # a node can subscribe is a set. The master or origin of
    # the set is node 1.
    #--
    create set (id=, origin=, comment='All lottu tables');
    set add table (set id=, origin=, id=,
                   fully qualified name = 'public.lottu',
                   comment='lottu table');

    # set add sequence (set id=1, origin = 1, id = 1,
    #               fully qualified name = 'public.t1_id_seq',
    #               comment = 't1 id sequence');

    #--
    # Create the second node (the slave) tell the 2 nodes how
    # to connect to each other and how they should listen for events.
    #--

    store node (id=, comment = );
    store path (server = , client = , conninfo='dbname=$MASTERDBNAME host=$MASTERHOST user=$REPLICATIONUSER password=$PASSWORD');
    store path (server = , client = , conninfo='dbname=$SLAVEDBNAME  host=$SLAVEHOST user=$REPLICATIONUSER password=$PASSWORD');
_EOF_
}

start()
{
    $SLON $CLUSTER_NAME "dbname=$MASTERDBNAME host=$MASTERHOST user=$REPLICATIONUSER password=$PASSWORD" >> /home/postgresql/master.log &
  #  $SLON $CLUSTER_NAME "$SLAVE" >> /home/postgresql/slave.log &
}

stop()
{
    # killall slon
      `ps axu|grep 'dbname=masterdb' |grep -v grep|awk '{print $2}'`
}

case $ in
    'install')
        install
        ;;
    'uninstall')
        uninstall
        ;;
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    *)
        echo "usage: $0 {install|uninstall|start|stop} "
        ;;
esac

最新文章

  1. 怎样把win7系统下的屏幕设置成护眼的非常柔和的豆沙绿色?
  2. 在Swift中使用JavaScript的方法和技巧
  3. Serializer序列化/反序列化DateTime少了8小时问题解决
  4. NOIP2008普及组 题解 -SilverN
  5. Android开发-API指南-&lt;application&gt;
  6. hdu1171
  7. 解决jsp页面乱码问题
  8. 如何搭建NTP服务(转)
  9. SQL Prompt——SQL智能提示插件
  10. sql server统计字段的值在某些范围内中的个数
  11. MyEclipse下打开ftl文件
  12. TensorFlow安装-ubuntu
  13. 13、Java菜单条、菜单、菜单项
  14. 移动端页面开发适配 rem布局原理
  15. spark2.1:rdd.combineByKeyWithClassTag的用法示例
  16. iframe 里的高度自适应
  17. July 04th. 2018, Week 27th. Wednesday
  18. VS2012统计代码量
  19. vue请求java服务端并返回数据
  20. ES6学习笔记&lt;三&gt; 生成器函数与yield

热门文章

  1. [Linux]gdb调试
  2. Java nio 笔记:系统IO、缓冲区、流IO、socket通道
  3. java程序员从笨鸟到菜鸟之(七)一—java数据库操作
  4. C++Primer 第十六章
  5. PHP 小谈静态用法
  6. 转:python webdriver API 之定位 frame 中的对象
  7. C++ set容器简单用法
  8. Android中实现进入App之后检查网络状态
  9. paper 89:视频图像去模糊常用处理方法
  10. angular 自定义指令 link