Database High Availability using PGPOOL-II
Pgpool-II is an amazing solution to increase your database availability. Pgpool-II is a proxy software that sits between PostgreSQL servers and a PostgreSQL database client.
It reduces the connection overhead and improves the system’s overall throughput.
With Pgpool we can create highly available systems that can continue to operate even if a system failure occurs. It also allows scalability.
Features
Following are some pgpool-II cool features that can improve your DB throughput and make it highly available.
Load Balancing
Postgres Streaming Replication
As we scale out to increase the database processing capacity. In Postgress we scale out using streaming replication or logical replication but still, postgres cannot distribute the queries by its replication
So in this case pg-pool can be used to distribute the queries between the master and standby servers
Pgpool for load balancing
Pgpool handles the load balancing like a charm.
- We can assign weights to all servers to decide how much load to send on each server
- We can also ban some queries to be executed by defining the
black_functions_list
Connection Pooling
- We know making a new connection on every single operation has an overhead of resources.
- So we make a connection pool with pgpool.
- Connection with the same properties is taken from the pool of connections and then returned.
- You can set parameters for the number of pools and connections in pgpool.
Also, pgbouncer is a lightweight tool for connection pooling. If you only want connection pooling in your database use pgbouncer instead.
Automatic Fail-over
- In case of a server failover, pgpool can help you handle it
- You can write a script of how to handle the fail-over and pgpool will automatically execute the script when a fail-over is detected
- It can handle fail-over by promoting the standby server as a primary server
High Availability
So what is high availability? It helps us to make the database always available and work without interruptions, it adds great redundancy to handle errors.
Pgpool is highly available itself. This is done so that pgpool should not become a single point of failure.
- Pgpool makes itself highly available
- It makes itself redundant using the feature called watchdog
watchdog
is a sub-process of pgpool-II aiming for adding high availability feature to it.
Obstacles
There are still some obstacles in making our cluster highly available.
Split brains
- It occurs when there is more than one master node.
- It creates data inconsistency
Consistency and availability
We cannot ensure both consistency and availability at the same time. We have to prioritize one in our system. CAP theory explains this problem as “In the event of a network failure on a distributed database, it is possible to provide either consistency or availability—but not both.”
Recommended Setup
Recommended Setup for High Availability
- So for replication, we can use Postgres streaming replication. Pgpool also provides replication but It is recommended to use Postgres built-in streaming replication.
- Use Pgpool for: Handling fail-overs, Load balancing, High Availability, and Connection pooling
Комментарии