简单的Slony-I设置实例
磨砺技术珠矶,践行数据之道,追求卓越价值
回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
参考如下链接:
http://lets.postgresql.jp/documents/technical/pgpool/4/
这里我使用slony-I 2.1.0。
下载地址如下:
http://slony.info/downloads/2.1/source/
安装过程:
我有两台机器,
机器A: 作为master数据库,IP地址: 192.168.10.102
机器B: 作为slave数据库,IP地址: 192.168.10.101
两台机器上都安装了Postgresql数据库9.1.2版本,安装目录位于: /usr/local/pgsql
master数据库和slave数据库都需要安装slony-I,安装过程一样:
将下载后的 slony1-2.1.0.tar.bz2 拷贝到如下目录:/soft
解压:tar -jxvf slony1-2.1.0.tar.bz2
给目录赋予权限:chown postgres:postgres /soft/slony1-2.1.0
给postgresql的安装目录也赋予权限:chown -R postgres:postgres /usr/local/pgsql
执行 configure:
cd /soft/slony1-2.1.0
./configure --prefix=/usr/local/slony --with-pgconfigdir=/usr/local/pgsql/bin
执行make 和 make install : make && make install
修改PATH环境变量:vim ~/.bash_profile:
export PATH=$PATH:/usr/local/pgsql/bin:/usr/local/slony/bin
准备好复制用的数据库:
[root@pg102 ~]# su - postgres
[postgres@pg102 ~]$ createdb testdb3
[postgres@pg102 ~]$
准备好复制用的表:
[postgres@pg102 ~]$ psql testdb3
psql (9.1.2)
Type "help" for help. testdb3=# CREATE TABLE t1 (id SERIAL PRIMARY KEY, comment TEXT,
testdb3(# ins_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for serial column "t1.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1"
CREATE TABLE
testdb3=#
查看建好的表:
testdb3=# \d t1
Table "public.t1"
Column | Type | Modifiers
----------+-----------------------------+-------------------------------------------------
id | integer | not null default nextval('t1_id_seq'::regclass)
comment | text |
ins_time | timestamp without time zone | default now()
Indexes:
"t1_pkey" PRIMARY KEY, btree (id)
需要注意到是:
如果想使用slony来复制数据,表必须是带有主键的。
我前面建表的时候,因为字段类型serial的原因,隐含地建立了一个sequence。这个在之后要使得slony知道此点。
还有一点,DDL动作是不会被复制到,因此,需要我手动向slave数据库节点建库和表:
[postgres@pg102 ~]$ pg_dump -C -s testdb3 | psql -h 192.168.10.101
SET
SET
SET
SET
SET
CREATE DATABASE
ALTER DATABASE
You are now connected to database "testdb3" as user "postgres".
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE SEQUENCE
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
ALTER TABLE
REVOKE
REVOKE
GRANT
GRANT
[postgres@pg102 ~]$
接下来,开始进行slony的设定:
声明slony cluster名称、注册node、初始化cluster...(请注意table和相关联的sequence都需要注册)
[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
完成了上述在master数据库节点发布的命令之后,下面在 master数据库和slave数据库节点分别启动slon daemon:
/usr/local/slony/bin/slon testdb3_cluster "dbname=testdb3 user=postgres host=localhost"&
/usr/local/slony/bin/slon testdb3_cluster "dbname=testdb3 user=postgres host=localhost" &
从master数据库节点,开始执行订阅过程:
[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
验证slony-I 复制生效:
在master数据库节点,增加数据:
testdb3=# INSERT INTO t1(comment) VALUES('replication test');
INSERT 0 1
testdb3=# select * from t1;
id | comment | ins_time
----+------------------+----------------------------
1 | replication test | 2013-07-17 16:26:37.320865
(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
----+------------------+----------------------------
1 | replication test | 2013-07-17 16:26:37.320865
(1 row) testdb3=#
最后,可以再看看在master数据库和slave数据库,针对master数据库和slave数据库的表都可以看到增加了trigger:
master数据库上:
testdb3=# \d t1
Table "public.t1"
Column | Type | Modifiers
----------+-----------------------------+-------------------------------------------------
id | integer | not null default nextval('t1_id_seq'::regclass)
comment | text |
ins_time | timestamp without time zone | default now()
Indexes:
"t1_pkey" PRIMARY KEY, btree (id)
Triggers:
_testdb3_cluster_logtrigger AFTER INSERT OR DELETE OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE _testdb3_cluster.logtrigger('_testdb3_cluster', '1', 'k')
_testdb3_cluster_truncatetrigger BEFORE TRUNCATE ON t1 FOR EACH STATEMENT EXECUTE PROCEDURE _testdb3_cluster.log_truncate('1')
Disabled triggers:
_testdb3_cluster_denyaccess BEFORE INSERT OR DELETE OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE _testdb3_cluster.denyaccess('_testdb3_cluster')
_testdb3_cluster_truncatedeny BEFORE TRUNCATE ON t1 FOR EACH STATEMENT EXECUTE PROCEDURE _testdb3_cluster.deny_truncate() testdb3=#
slave数据库上:
testdb3=# \d t1
Table "public.t1"
Column | Type | Modifiers
----------+-----------------------------+-------------------------------------------------
id | integer | not null default nextval('t1_id_seq'::regclass)
comment | text |
ins_time | timestamp without time zone | default now()
Indexes:
"t1_pkey" PRIMARY KEY, btree (id)
Triggers:
_testdb3_cluster_denyaccess BEFORE INSERT OR DELETE OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE _testdb3_cluster.denyaccess('_testdb3_cluster')
_testdb3_cluster_truncatedeny BEFORE TRUNCATE ON t1 FOR EACH STATEMENT EXECUTE PROCEDURE _testdb3_cluster.deny_truncate()
Disabled triggers:
_testdb3_cluster_logtrigger AFTER INSERT OR DELETE OR UPDATE ON t1 FOR EACH ROW EXECUTE PROCEDURE _testdb3_cluster.logtrigger('_testdb3_cluster', '1', 'k')
_testdb3_cluster_truncatetrigger BEFORE TRUNCATE ON t1 FOR EACH STATEMENT EXECUTE PROCEDURE _testdb3_cluster.log_truncate('1') testdb3=#
回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
磨砺技术珠矶,践行数据之道,追求卓越价值
简单的Slony-I设置实例的更多相关文章
- 简单的Slony-I设置实例 II
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页 接前面例子, 简单的Slony-I设置实例 这次我 ...
- 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 ...
随机推荐
- css3 网格背景
background-image: -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, rgba(255, 255, 255, .2)), ...
- jq实现多级菜单
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- PhoneGap API 之事件处理_双击返回键退出程序
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 【redis运维】redis自己主动安装脚本(仅仅安装redis)
Redis自己主动安装部署 本文总共分为4个部分: redis自己主动安装脚本文件夹结构说明: redis自己主动安装脚本内容: redis的操作系统服 ...
- [POI2006]TET-Tetris 3D
题目 二维线段树板子题啊 但是惊讶的发现我不会打标记 毕竟内层是线段树不能\(pushup\)也不能\(pushdown\) 于是考虑一下标记永久化 其实非常显然\(mx_i\)表示区间最大值,\(t ...
- 随手练——洛谷-P1008 / P1618 三连击(暴力搜索)
1.普通版 第一眼看到这个题,我脑海里就是,“我们是不是在哪里见过~”,去年大一刚学C语言的时候写过一个类似的题目,写了九重循环....就像这样(在洛谷题解里看到一位兄台写的....超长警告,慎重点开 ...
- appium ios Demo
Appium Demo 录制图片,环境搭建完毕后根据视频基本能利用模拟器完成简单测试用例 感谢大神http://www.cnblogs.com/tobecrazy/p/4970188.html
- php数组键值操作和数组统计函数-函数
1.数组函数//作用:提供了很多官方写的很多有用的代码段,提高编写速度 1)数组的键值操作函数 array_values();//获取数组中的值 array_keys();//获取数组中的键 in_a ...
- Gradle Goodness: Excluding Tasks for Execution
In Gradle we can create dependencies between tasks. But we can also exclude certain tasks from those ...
- 理解Web应用程序的代码结构和运行原理(3)
1.理解Web应用程序的运行原理和机制 Web应用程序是基于浏览器/服务器模式(也称B/S架构)的应用程序,它开发完成后,需要部署到Web服务器上才能正常运行,与用户交互的客户端是网页浏览器. 浏览器 ...