简单的Slony-I设置实例 II
磨砺技术珠矶,践行数据之道,追求卓越价值
回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
接前面例子, 简单的Slony-I设置实例
这次我增加一台机器C: 192.168.10.100,我尽量从该机器上发送slonik命令
机器A和机器B启动之后:
执行初始化cluster动作:
[postgres@pg102 ~]$ cat setup.sh
#!/bin/sh CLUSTERNAME=testdb3_cluster
MASTERDBNAME=testdb3
SLAVEDBNAME=testdb3
MASTERHOST=192.168.10.102
SLAVEHOST=192.168.10.101
REPLICATIONUSER=postgres /usr/local/slony/bin/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';
node admin conninfo = 'dbname=$SLAVEDBNAME \
host=$SLAVEHOST user=$REPLICATIONUSER'; #--
# init the first node. Its id MUST be . 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 .
#--
create set (id=, origin=, comment='All testdb3 tables');
set add table (set id=, origin=, id=,
fully qualified name = 'public.t1',
comment='t1 table');
set add sequence (set id=, origin = , id = ,
fully qualified name = 'public.t1_id_seq',
comment = 't1 id sequence'); #--
# Create the second node (the slave) tell the nodes how
# to connect to each other and how they should listen for events.
#-- store node (id=, comment = 'Slave Node', event node=);
store path (server = , client = , conninfo='dbname=$MASTERDBNAME \
host=$MASTERHOST user=$REPLICATIONUSER');
store path (server = , client = , conninfo='dbname=$SLAVEDBNAME \
host=$SLAVEHOST user=$REPLICATIONUSER');
_EOF_
[postgres@pg102 ~]$
sh setup.sh
然后:
分别在机器A和机器B中,看到各自建立了一个名字空间(namespace,其实是schema):
机器A:
[postgres@pg102 bin]$ ./psql
psql (9.1.2)
Type "help" for help. postgres=# \c testdb3
You are now connected to database "testdb3" as user "postgres".
testdb3=# select * from pg_namespace;
nspname | nspowner | nspacl
--------------------+----------+-------------------------------------
pg_toast | 10 |
pg_temp_1 | 10 |
pg_toast_temp_1 | 10 |
pg_catalog | 10 | {postgres=UC/postgres,=U/postgres}
public | 10 | {postgres=UC/postgres,=UC/postgres}
information_schema | 10 | {postgres=UC/postgres,=U/postgres}
_testdb3_cluster | 10 | {postgres=UC/postgres,=U/postgres}
(7 rows) testdb3=# create table _testdb3_cluster.gao(id integer);
CREATE TABLE
testdb3=# drop table _testdb3_cluster;
ERROR: table "_testdb3_cluster" does not exist
testdb3=# drop table _testdb3_cluster.gao;
DROP TABLE
testdb3=#
机器B:
[postgres@pg101 bin]$ ./psql
psql (9.1.2)
Type "help" for help. postgres=# \c testdb3
You are now connected to database "testdb3" as user "postgres".
testdb3=# select * from pg_namespace;
nspname | nspowner | nspacl
--------------------+----------+-------------------------------------
pg_toast | 10 |
pg_temp_1 | 10 |
pg_toast_temp_1 | 10 |
pg_catalog | 10 | {postgres=UC/postgres,=U/postgres}
information_schema | 10 | {postgres=UC/postgres,=U/postgres}
public | 10 | {postgres=UC/postgres,=UC/postgres}
_testdb3_cluster | 10 | {postgres=UC/postgres,=U/postgres}
(7 rows) testdb3=#
可以这样说,在slony的环境中,并不存在一个中心节点来存储cluster信息。
这种方式加上各种指令为中心的处理结构,导致其架构复杂化。
接下来,看看可否另slon daemon独立于DB节点运行:
我在机器C上执行:
/usr/local/slony/bin/slon testdb3_cluster "dbname=testdb3 user=postgres host=192.168.10.102" &
/usr/local/slony/bin/slon testdb3_cluster "dbname=testdb3 user=postgres host=192.168.10.101" &
然后,此时,再在机器C上执行 subscribe 过程:
[postgres@pg102 ~]$ cat subscribe.sh
#!/bin/sh CLUSTERNAME=testdb3_cluster
MASTERDBNAME=testdb3
SLAVEDBNAME=testdb3
MASTERHOST=192.168.10.102
SLAVEHOST=192.168.10.101
REPLICATIONUSER=postgres /usr/local/slony/bin/slonik <<_EOF_
# ----
# This defines which namespace the replication system uses
# ----
cluster name = $CLUSTERNAME; # ----
# Admin conninfo's are used by the slonik program to connect
# to the node databases. So these are the PQconnectdb arguments
# that connect from the administrators workstation (where
# slonik is executed).
# ----
node admin conninfo = 'dbname=$MASTERDBNAME host=$MASTERHOST \
user=$REPLICATIONUSER';
node admin conninfo = 'dbname=$SLAVEDBNAME host=$SLAVEHOST \
user=$REPLICATIONUSER'; # ----
# Node subscribes set
# ----
subscribe set ( id = , provider = , receiver = , forward = no);
_EOF_
[postgres@pg102 ~]$ sh subscribe.sh
验证:
在master数据库节点,增加数据:

testdb3=# INSERT INTO t1(comment) VALUES('replication test');
INSERT 0 1
testdb3=# select * from t1;
id | comment | ins_time
----+------------------+----------------------------
2 | replication test | 2013-07-18 13:47:30.023486
(1 row)
testdb3=#

此时,在 slave数据库节点,也可以看到同样的数据:已经成功。

[root@pg101 ~]# su - postgres
[postgres@pg101 ~]$ psql testdb3
psql (9.1.2)
Type "help" for help.
testdb3=# select * from t1;
id | comment | ins_time
----+------------------+----------------------------
2 | replication test | 2013-07-18 13:47:30.023486
(1 row)
testdb3=#

已经成功完成复制。
回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
磨砺技术珠矶,践行数据之道,追求卓越价值
简单的Slony-I设置实例 II的更多相关文章
- C#反射技术的简单操作(读取和设置类的属性)
public class A { public int Property1 { get; set; } } static void Main(){ A aa = new A(); Type type ...
- [转]在.NET Core 2.x中将多个强类型设置实例与命名选项一起使用
自1.0版之前,ASP.NET Core已使用“ 选项”模式配置强类型设置对象.从那时起,该功能获得了更多功能.例如,引入了ASP.NET Core 1.1 IOptionsSnapshot,它允许您 ...
- 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某几个角(小于4)为圆角而别的不变时 ...
- Fiddler-009-AutoResponder 简单的 MOCK SERVER 应用实例
在我们日常的测试中经常需要测试特定的响应对应的客户端展示样式是否正确无误,实现测试方法一般有如下三种: 创建新的测试数据(工作量较大) 修改已有测试数据(例如修改对应的状态码,若是最终需要测试的按钮状 ...
- Core文件简单介绍及生成设置方法
Core文件简单介绍及生成设置方法 Core文件其实就是内存的映像,当程序崩溃时,存储内存的相应信息,主用用于对程序进行调试.当程序崩溃时便会产生core文件,其实准确的应该说是core dump 文 ...
- 使用Python编写简单的端口扫描器的实例分享【转】
转自 使用Python编写简单的端口扫描器的实例分享_python_脚本之家 http://www.jb51.net/article/76630.htm -*- coding:utf8 -*- #!/ ...
- Java-Runoob-高级教程-实例-环境设置实例:4.Java 实例 – 如何查看当前 Java 运行的版本?
ylbtech-Java-Runoob-高级教程-实例-环境设置实例:4.Java 实例 – 如何查看当前 Java 运行的版本? 1.返回顶部 1. Java 实例 - 如何查看当前 Java 运行 ...
- Java-Runoob-高级教程-实例-环境设置实例:3.Java 实例 - 如何执行指定class文件目录(classpath)?
ylbtech-Java-Runoob-高级教程-实例-环境设置实例:3.Java 实例 - 如何执行指定class文件目录(classpath)? 1.返回顶部 1. Java 实例 - 如何执行指 ...
- Java-Runoob-高级教程-实例-环境设置实例:2.Java 实例 – Java 如何运行一个编译过的类文件?
ylbtech-Java-Runoob-高级教程-实例-环境设置实例:2.Java 实例 – Java 如何运行一个编译过的类文件? 1.返回顶部 1. Java 实例 - 如何执行编译过 Java ...
随机推荐
- AngularJs学习笔记--Using $location
原版地址:http://code.angularjs.org/1.0.2/docs/guide/dev_guide.services.$location 一.What does it do? $loc ...
- BZOJ 1088 扫雷Mine 枚举初始状态
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1088 题目大意: 现在棋盘是n×2的,第一列里面某些格子是雷,而第二列没有雷,如下图: ...
- - (void)addConstraints:(NSArray<__kindof NSLayoutConstraint *> *)constraints
Adds multiple constraints on the layout of the receiving view or its subviews. All constraints mus ...
- Guava包学习---Lists
Guava包是我最近项目中同事推荐使用的,是google推出的库.里面的功能非常多,包括了集合.缓存.原生类型支持.并发库.通用注解.字符串处理.IO等.我们项目中使用到了guava依赖,但是实际上只 ...
- MySQL 分库分表方案,总结的非常好!
前言 公司最近在搞服务分离,数据切分方面的东西,因为单张包裹表的数据量实在是太大,并且还在以每天60W的量增长. 之前了解过数据库的分库分表,读过几篇博文,但就只知道个模糊概念, 而且现在回想起来什么 ...
- $_cookie的使用
设置并发送 cookie: <?php $value = "my cookie value"; // 发送一个简单的 cookie setcookie("TestC ...
- virtualbox+vagrant学习-4-Vagrantfile-8-WinSSH
WinSSH WinSSH通信器是专门为OpenSSH的Windows本机端口构建的.它不依赖于类posix的环境,这种环境消除了额外的软件安装(如cygwin)以获得适当功能的需求. 想获得更多的信 ...
- kendo ui - grid 数据表格系列
kendo-ui 官网:https://www.telerik.com/documentation 初始化 grid: 引入文件: <link rel="stylesheet" ...
- css 尾巴
用border制作三角形 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- SSIS中出现数据流数据源假死状态的解决办法
相信开发过Sql Server SSIS的人都遇到过在数据流中数据源假死的问题,特别是Excel Source特别容易假死,当job执行到数据流中的Excel Source时,既不报错也不执行,也没有 ...