PostgreSQL负载均衡中间件-PGpool
pgpool-II 是运行于 PostgreSQL 数据库服务器和客户端之间的一个中间件,提供的功能包括:连接池、复制、负载均衡、客户端限制和并行查询等。
pgpool-II is a middleware that works between PostgreSQL servers and a PostgreSQL database client. It is licensed under BSD license. It provides the following features.

Connection Pooling
pgpool-II saves connections to the PostgreSQL servers, and reuse them whenever a new connection with the same properties (i.e. username, database, protocol version) comes in. It reduces connection overhead, and improves system's overall throughput.
Replicationpgpool-II can manage multiple PostgreSQL servers. Using the replication function enables creating a realtime backup on 2 or more physical disks, so that the service can continue without stopping servers in case of a disk failure.
Load Balance
If a database is replicated, executing a SELECT query on any server will return the same result. pgpool-II takes an advantage of the replication feature to reduce the load on each PostgreSQL server by distributing SELECT queries among multiple servers, improving system's overall throughput. At best, performance improves proportionally to the number of PostgreSQL servers. Load balance works best in a situation where there are a lot of users executing many queries at the same time.
Limiting Exceeding Connections
There is a limit on the maximum number of concurrent connections with PostgreSQL, and connections are rejected after this many connections. Setting the maximum number of connections, however, increases resource consumption and affect system performance. pgpool-II also has a limit on the maximum number of connections, but extra connections will be queued instead of returning an error immediately.
Parallel Query
Using the parallel query function, data can be divided among the multiple servers, so that a query can be executed on all the servers concurrently to reduce the overall execution time. Parallel query works the best when searching large-scale data.
pgpool-II talks PostgreSQL's backend and frontend protocol, and relays a connection between them. Therefore, a database application (frontend) thinks that pgpool-II is the actual PostgreSQL server, and the server (backend) sees pgpool-II as one of its clients. Because pgpool-II is transparent to both the server and the client, an existing database application can be used with pgpool-II almost without a change to its sources.
最新版本:4.1
2020年9月,PGpool全球开发组宣布,以下更新版本发布:4.1.4、4.0.11、3.7.16、3.6.23、3.5.27。本次发布的更新版本较多,每个版本都包含对应的功能提升和bug修复,具体更新内容见官网发行说明。下面列举最新版本v4.1.4的部分更新内容:
跟随PostgreSQL 12.4的主线功能相应修改:不采用CREATE OR REPLACE FUNCTION而是采用CREATE FUNCTION代替;
采用PostgreSQL的bin和lib路径来代替pgpool_setup和watchdog_setup中的"PGBIN"和"LPATH";
移除不必要的代码路径检查;
修复当启用serialize_accept时connection_life_time失效的问题;
在授权处理时显示更多的有效错误信息;
官方主页:http://www.pgpool.net/mediawiki/index.php/Main_Page
该文章最后由 阿炯 于 2020-09-25 15:07:07 更新,目前是第 2 版。