数据库读写分离
时间:2021-07-01 10:21:17
帮助过:7人阅读
SQL Server提供了多种读写分离的机制,这里只介绍下发布和订阅的方式,因为博主只用过这种形式,SQL Server 2012中新增的功能Always On也可以实现。
快照发布
快照复制是完全按照数据和数据库对象出现时的状态来复制和分发它们的过程。快照复制不需要连续地监控数据变化,因为已发布数据的变化不被增量地传播到订阅服务器,而是周期性的被一次复制。
a.本地发布:要启动SQL Server代理
1.MyBookShop是主数据库,MyBookShop_R是被同步的数据库既辅数据库,现在可以看出主数据库比辅数据库多两条数据,现在我们把这两条数据通过发布快照的方式同步过去。

2.

3.

4.

5.

6.可以在“计划在下时间运行快照代理”中设置运行时间,快照并非实时同步更新数据库,所以可以设置个时间,也可以不设置,只同步一次就行。

7.点击安全设置

8.

9.

10.

11.

12.

13.创建成功

b.本地订阅
1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.刷新显示订阅

16.重新查询数据库,看看有没有同步过去
注:如果主数据库添加数据,辅数据库不会实时同步过去,除非重新启动代理或者到了作业执行的时间才会再次同步,如果想要数据实时同步[说是实时也会有几秒延迟,没有绝对的实时同步]到辅数据库就用事物发布而非快照发布

事务发布
事务发布的方法和快照发布基本相同,事务发布可以实时更新数据,当添加、修改或者删除一条数据时,主数据库上的变动会实时同步到辅数据库【有几秒延迟】;
事务发布可以实现读写分离,主库发布事务,多台辅库订阅,辅库要设置成只读模式;
数据库读写分离
标签:http 分离 删除 事物 相同 查询 blog 服务器 通过