简单的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 ...
随机推荐
- 项目管理利器-Maven(Windows安装)
什么是Maven? 安装Maven环境: 下载地址:https://maven.apache.org/download.cgi Maven3.3+JDK1.7以上版本 下载windows版本 解压到本 ...
- JAVAWEB之文件的上传下载
文件上传下载 文件上传: 本篇文章使用的文件上传的例子使用的都是原生技术,servelt+jdbc+fileupload插件,这也是笔者的习惯,当接触到某些从未接触过的东西时,总是喜欢用最原始的东西将 ...
- jq封装-无缝滚动效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- php-fpm配置参数.md
Global Options pid string PID文件的位置.默认为空.默认路径放在/usr/local/php-fpm/var. error_log string 错误日志的位置.默认:安装 ...
- 如何寫一個自定義控件/vs2010生成Dll文件并引用dll(C#)
1.最簡單的例子 首先你先新建->項目->類庫.然後右鍵項目.添加一個用戶控件.設置其用戶控件繼承button. egg: namespace ClassLibrary1{ publ ...
- Gradle Goodness: Run a Build Script With a Different Name
Normally Gradle looks for a build script file with the name build.gradle in the current directory to ...
- PlanetLab介绍
转自http://blog.sina.com.cn/s/blog_83517c050100vyzq.html PlanetLab产生背景 随着计算机技术和通信技术的不断发展,Internet的商业化和 ...
- 修改系统UITableViewCell的ImageView大小
代码如下: CGSize itemSize = CGSizeMake(, ); UIGraphicsBeginImageContext(itemSize); CGRect imageRect = CG ...
- OO第二次单元总结——电梯多线程调度问题
OO第二次单元总结--电梯多线程调度问题 在这个单元OO学习中,我们终于迎来了期待已久(不是)的电梯多线程调度作业,开启了OO打怪之路的新关卡.虽然说经过了这三次作业,我对于多线程的理解还不能算是熟练 ...
- oracle入门(二)
### 一,视图 ```1. 什么是视图 视图是一张虚表, 可以把视图看成表使用(增删改查),视图中没有数据,所有的数据都在基本表中(tables) 封装了一个复杂的DQL 操作视图 ...