写在前面
Mycat作为独立的数据库中间件,我们只需要进行相关的配置,就可以非常方便的帮我们实现水平切分、垂直切分、读写分离等功能,但PostgreSQL的主从复制需要我们通过其它方式实现。这里假设我们已经搭建好相关的环境,下面就开始我们的实践吧!
准备环境
- PostgreSQL(Version : 10.1)主从环境搭建
- 对应数据库建立(以下例子中使用的都是默认存在的postgres数据库,可以不用额外添加)
配置server.xml
<user name="postgresmycat">
<property name="password">postgresmycat</property>
<property name="schemas">postgresmycats</property>
</user>
配置schema.xml
<schema name="postgresmycats" checkSQLschema="false" sqlMaxLimit="100">
<table name="tb_user" dataNode="mydn3,mydn4" rule="user-mod-long" />
<table name="tb_student" dataNode="mydn3,mydn4" rule="student-mod-long" />
</schema>
<dataNode name="mydn3" dataHost="myhost3" database="postgres" />
<dataNode name="mydn4" dataHost="myhost4" database="postgres" />
<!-- 这里的dbDriver使用jdbc的方式来连接,用native方式似乎目前还不太兼容,试过了好像不可以 -->
<dataHost name="myhost3" maxCon="100" minCon="10" balance="3" writeType="0" dbType="postgresql" dbDriver="jdbc">
<heartbeat>select user</heartbeat><!-- 注意这里的心跳检测命令跟mysql的有点不同 -->
<writeHost host="hostM3" url="jdbc:postgresql://localhost:5432/postgres" user="postgres" password="xxx">
<