"Preserving Data Integrity and Ensuring High Availability: Seamless Migration and Containerized Management of PostgreSQL and AgensGraph with Stolon"
Muhammad Affan
Senior Application Support Engineer @ Cloudelligent | Aws, Alibaba, Google Certified | PostgreSQL | Oracle Database | MySQL | MSSQL | Data Migration | Cloud Management | Package Deployments | Server/Database Performance
The Stolon extension for PostgreSQL is specifically created to oversee PostgreSQL instances within a high-availability (HA) setup. It streamlines activities such as failover, monitoring, and cluster management. Essentially, Stolon serves as a PostgreSQL automation framework that operates on top of technologies like Kubernetes and Etcd.
In this implementation, I will utilize one master server and two slave servers. The operating system release version for all servers is "Rocky Linux 8.9."
Initially, we will make the necessary adjustments to execute AgensGraph and establish roles in the system. Additionally, we will configure replication roles in the database server to retrieve data from the master to the slave DB server.
Elevating AgensGraph with Stolon: The Path to Enhanced PostgreSQL Extension Integration
In today's data-centric landscape, organizations rely on innovative database solutions to manage complex data relationships and derive actionable insights. Graph databases, such as AgensGraph, have emerged as indispensable tools for modelling and querying interconnected data using the powerful Cypher query language. However, ensuring high availability, scalability, and reliability are critical considerations, especially as data volumes continue to grow. This is where Stolon comes into play, seamlessly integrating with PostgreSQL to enhance data management capabilities for AgensGraph users.
The Role of Stolon in PostgreSQL Extension Integration: Stolon serves as a vital component in extending PostgreSQL's capabilities, offering several key benefits for AgensGraph deployments:
Implementing Stolon with AgensGraph: Integrating Stolon with AgensGraph is a straightforward process that involves the following steps:
How to Setup Environment on Master and Slave Nodes:
Setting up AgensGraph with Stolon for High Availability and Scalability
In today’s data-driven world, managing databases efficiently is crucial for businesses seeking to harness the power of their data. For those utilizing graph databases like AgensGraph, ensuring high availability, scalability, and reliability is paramount. In this guide, we'll walk you through the process of setting up AgensGraph with Stolon, a powerful solution for database clustering and management.
Environment Setup on Master and Slave Nodes
1. Create User 'agens':
sudo useradd agens
sudo passwd agens
2. Download AgensGraph:
Download AgensGraph version 2.1.1 tar file to directory "/home/agens/"
3. Adjust LD_LIBRARY_PATH:
Update LD_LIBRARY_PATH in ~/.bash_profile
export LD_LIBRARY_PATH=/home/agens/AgensGraph_v2.1.1_linux_EE/AgensGraph/lib
4. Create Symlink for libreadline:
If needed, create a symlink for libreadline.so.6
5. Install Required Libraries:
If you encounter shared library errors, install the required libraries:
sudo dnf install libssl*
yum install compat-openssl10
Initializing and Configuring AgensGraph
1. Initialize Database Server:
Initialize the database server from the bin directory
./initdb -D /home/agens/server1
2. Start Database:
Start the database server from the bin directory
./ag_ctl -D /home/agens/server1 start
3. Connect to Database:
Connect to the database from the bin directory
./agens -p 5432 -d postgres
4. Create Role 'repl':
Create a replication role and set the password
./psql -U agens postgres -c "CREATE ROLE repl REPLICATION LOGIN PASSWORD 'repl';"
5. Alter Role 'agens':
Alter the 'agens' role with a new password
./psql -U agens postgres
ALTER ROLE agens WITH PASSWORD 'agens';
6. Restart Server:
Restart the server for changes to take effect
./ag_ctl -D /home/agens/server1 restart
Installing Stolon for High Availability
1. Download Stolon:
领英推荐
Navigate to the Stolon installation directory
cd /home/agens/AgensGraph_v2.1.1_linux_EE/AgensGraph/tool/stolon_v0.12.0/
2. Run Stolon Installer:
Execute the Stolon installer script
./stolon-0.12.0-installer.sh
3. Update .bash_profile:
Add Stolon paths to ~/.bash_profile
export AGHOME=/home/agens/AgensGraph_v2.1.1_linux_EE/AgensGraph
export AGDATA=/home/agens/server1
export LD_LIBRARY_PATH=/home/agens/AgensGraph_v2.1.1_linux_EE/AgensGraph/lib
export PATH=/home/agens/AgensGraph_v2.1.1_linux_EE/AgensGraph/bin
4. Check Stolon & Etcd Versions:
Verify Stolon and Etcd versions
stolonctl version
etcdctl --version
Setting Up Master and Slave Nodes with Stolon
AgensGraph, coupled with Stolon, offers a robust solution for creating PostgreSQL clusters with automated failover and replication. Let's delve into the intricate process of setting up such a cluster across multiple servers.
1. Initialize Stolon Cluster:
Initialize the Stolon cluster with etcdv3 as the store backend
./stolonctl --cluster-name=agens-ee-stolon-cluster --store-backend=etcdv3 init
We configure the pg_hba.conf file on the master node located at /home/agens/Stolon/data/agens0/postgres. This file governs client authentication in PostgreSQL. Here's a snippet of the configurations:
local postgres agens md5
local replication repl md5
host all agens 0.0.0.0/0 md5
host all agens ::0/0 md5
host replication repl 0.0.0.0/0 md5
host replication repl ::0/0 md5
host all all 0.0.0.0/0 md5
host all all ::0/0 md5
After configuring pg_hba.conf,
we proceed to initialize Stolon and etcd, a distributed key-value store. The following command starts etcd and initializes the Stolon cluster:
nohup /home/agens/Stolon/etcd/etcd [etcd configurations...] > $HOME/Stolon/etcd/log/etcd.log
./stolonctl --cluster-name=agens-ee-stolon-cluster --store-backend=etcdv3 init
Subsequently, we start the Stolon Sentinel to monitor the health of keepers and proxies:
nohup /home/agens/Stolon/bin/stolon-sentinel --cluster-name=agens-ee-stolon-cluster --store-backend=etcdv3 > $HOME/Stolon/log/stolon_sentinel.log
The Stolon Keeper process is then initiated to manage the PostgreSQL instance:
nohup /home/agens/Stolon/bin/stolon-keeper [keeper configurations...] > $HOME/Stolon/log/stolon_keeper.log
Finally, the Stolon Proxy process is started to route client connections:
nohup /home/agens/Stolon/bin/stolon-proxy [proxy configurations...] > $HOME/Stolon/log/stolon_proxy.log
Configuring Slave Nodes
Similar steps are followed for configuring slave nodes (`Slave1` and Slave2), with adjustments made for server IP addresses and paths accordingly.
Verifying Cluster Status
To ensure the health and status of the cluster, execute the following command:
./stolonctl --cluster-name=agens-ee-stolon-cluster --store-backend=etcdv3 status
This command provides insights into active sentinels, proxies, keepers, and overall cluster information.
Ensuring Security
While configuring trusted IPs via pg_hba.conf is a common practice, it's essential to reinforce security measures. Instead of solely relying on IP-based authentication, consider implementing network traffic control through IPTABLES for a more secure environment.
In conclusion, by meticulously configuring AgensGraph and Stolon across multiple nodes, organizations can establish resilient PostgreSQL clusters, ensuring data availability, seamless migration, and reliability even in the face of failures.
Conclusion
By harnessing the capabilities of Stolon, organizations can enhance the reliability, scalability, and fault tolerance of their AgensGraph deployments. Whether deploying on-premises or in the cloud, Stolon's seamless integration with PostgreSQL empowers organizations to build resilient and agile data platforms that drive innovation and accelerate business growth. With Stolon, AgensGraph users can confidently navigate the complexities of graph database management, unlocking new possibilities for data-driven insights and decision-making.