简单的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 ...
随机推荐
- Oracle数据库用户名密码【转载自百度经验】
登录到安装oracle数据库服务器的操作系统.打开命令窗口:(我的演示机器是windows) 查看环境变量ORACLE_SID的设置情况: windows: echo %ORACLE_SID% l ...
- eclipse 检测App的内存占用和泄漏【转载】
前段时间开发的Android应用,每次都是在运行了半个小时左右后突然挂掉了,很是莫名其妙,也不知道哪里出了问题,后来一步步排查,发现问题出在JNI层,一个被频繁调用的函数分配的内存忘记释放,导致内存泄 ...
- A blog about Core Animation and other iOS graphics framework
A blog about Core Animation and other iOS graphics frameworks. https://www.calayer.com/
- 巧用DNSlog实现无回显注入
测试一些网站的时候,一些注入都是无回显的,我们可以写脚本来进行盲注,但有些网站会ban掉我们的ip,这样我们可以通过设置ip代理池解决, 但是盲注往往效率很低,所以产生了DNSlog注入.具体原理如下 ...
- python之获取文件夹下文件的绝对路径
#!/usr/bin/python #-*-conding:utf-8-*- #获取目录下文件的绝对路径 import os def getabsroute(path): listdir = os.l ...
- JNI由浅入深_2_C语言基础
*含义 1.乘法 3*5 2.定义指针变量 int * p://定义了一个名字叫p的变量,能够存放int数据类型的地址 3.指针运算符, //如果p是一个已经定义好的指针变量则*p表示以p的内容为地址 ...
- Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task
With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. Thi ...
- 为什么我们要做三份 Webpack 配置文件
时至今日,Webpack 已经成为前端工程必备的基础工具之一,不仅被广泛用于前端工程发布前的打包,还在开发中担当本地前端资源服务器(assets server).模块热更新(hot module re ...
- 【星云测试】开发者测试(2)-采用精准测试工具对J2EE Guns开发框架进行测试
配置测试Guns Guns简介 Guns是一个近几年来基于SpringBoot的开源便利且较新的JavaEE项目开发框架,它整合了springmvc + shiro + mybatis-plus + ...
- android学习:Android上面部署Apache FTPServer
经过了几天的研究,终于Apache FTPServer在Android的配置和使用上有了一些心得,现在分享出来,提供给大家参考,说到这儿又不得不吐槽一下这要命的转载了,找Apache FTPServe ...