新入门PGSQL数据库(尝试利用PGPOOL实现分布式),摘录笔记

概念:

PostgreSQL (pronounced "post-gress-Q-L") is an open source relational database management system ( DBMS ) developed by a worldwide team of volunteers. PostgreSQL is not controlled by any corporation or other private entity and the source code is available free of charge.

用于实现分布式的中间件:

pgPool, pgBouncer and the multi-string JDBC driver. pgBouncer is a lightweight connection pooler that provides connection pooling to a single database server only. It does not provide for query routing, load balancing or of high availability support。

pgpool四种模式

O 意味着“可用”, X 意味着“不可用
(1) 并行查询模式需要同时打开复制和负载均衡,但是复制和负载均衡无法用于并行查询模式中的分布式表。
(
2) 在线恢复可以和流复制同时使用。
(*3) 客户端仅仅是通过 pgpool-II 连接到 PostgreSQL服务器。这种模式仅仅用于限制到服务器的连接数,或者在多台机器上启用故障恢复。

pgpool有很多功能,其中最重要的我觉得是如下几个:提供连接池(负载均衡模式),复制模式(能通过pgpool分发sql,因此是基于sql语句的分发复制),主备模式(依赖其他的复制,如snoly和流复制,但pgpool能把客户端的sql请求根据sql是查询还是修改发送到备库或主库),并行模式(其实就是把表水平拆分到各个数据节点,一条sql查询时需要从多个数据节点查询数据)。

 要搭建基于postgresql的高可用、负载均衡的数据库集群架构,还有很多技术,如postgres-xc,但最常用的postgresql的主备模式(主库加流复制为例来搭建,1主库+多备库,实现高可用和负载均衡)。高可用即一个节点宕机不影响整体业务运行,负载均衡是指客户端发过来的链接请求能均匀的分布到各个数据节点,负载均衡的时候需要考虑到主库和备库是不同的,主库可读可写而备库只能读,因此select语句可以发往主库和备库,而update、insert、delete等要在主库执行,别的负载均衡软件如lvs是做不到的,但pgpool可以检测sql语句,自动发往不同的节点。

pgpool-II 手册

http://www.pgpool.net/docs/pgpool-II-3.5.4/doc/pgpool-zh_cn.html

http://www.pgpool.net/mediawiki/index.php/Documentation

PGSQL安装教程(笔者使用Centos7测试)https://wiki.postgresql.org/wiki/YUM_Installation

原文地址:https://www.cnblogs.com/kzwrcom/p/6398474.html