当前位置:网站首页>Pg-pool-ii read / write separation experience
Pg-pool-ii read / write separation experience
2022-06-24 04:52:00 【Tencent cloud database tencentdb】
- PG-Pool-II function
- PG-Pool-II install
- PG-Pool-II Read-write separation test
- PG-Pool-II The performance and SQL test
- Preliminary conclusion
PG-Pool-II function
- Connection pool
PG It's a multiprocess structure , Connection pooling can reduce the problem of connection vacancy , Improve resource utilization .
- Master slave copy + online recovery+auto failover
adopt pgpool management Master-slave relationship , Realization PG Master-slave high availability .
- Load balancing
When there are multiple slave Libraries , You can automatically load requests from different nodes through weight settings , Optimize performance .
- Connections limit
Set the connection number control , Avoid excessive connections that may cause access errors , When the number of connections is exceeded, go online , Queue for subsequent access .
- High availability
adopt pgpool Management ability , Can achieve its own high availability , Avoid performance problems with connection pools .
- The query cache
Cache in memory SQL result . If one is the same SQL, You can return a value from the cache , Improve query performance .
PG-Pool-II install
Resources to prepare :
CVM 1 platform ,centos 7.2 64 position , To configure 32C64GB.
Cloud database PostgreSQL, Main instance 1c2GB,200GB disk , Read only instance 2 individual ,1c2GB,200GB disk , Combine into a read-only instance group .
- Install according to the operating system pg The official yum Source .yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdgredhat-repo-latest.noarch.rpm
- install pgpool-II Installation package , What we use here is 4.1.4 Example , You can choose the 4.2.4 edition . yum install -y pgpool-II-11 yum install -y pgpool-II-11-extensions yum install -y pgpool-II-11-devel
- View folder :/etc/pgpool-II-11/, Whether there is a file .
PG-Pool-II Configuration and use
The main configuration files are as follows :
/etc/pgpool-II-11/pgpool.conf , Master profile
/etc/pgpool-II-11/pool_hba.conf, The connection profile is similar to pg_hba.conf
/etc/pgpool-II-11/pool_passwd, Access user and password files , It mainly configures the access user name and password , Authentication for connecting to the database .
/etc/pgpool-II-11/pgpool.conf The main configuration information is as follows :
# Basic connection information
# - pgpool Connection Settings -
listen_addresses ='*'
port =9999
socket_dir='/var/run/pgpool-II-11'
# - Manage interface configuration information , No configuration -
pcp_listen_addresses =''
pcp_port =5432
pcp_socket_dir ='/var/run/pgpool-II-11'
# - Database master node connection information configuration , important
backend_hostname0 ='172.27.32.11'
backend_port0 =5432
backend_weight0 =1
backend_data_directory0 ='/data/pgsql11/master'
backend_flag0 ='ALWAYS_MASTER'
backend_application_name0 ='master'
# Connection information of read-only instance or read-only instance group , To configure PG Read only group VIP
backend_hostname1 ='172.27.32.12'
backend_port1 =5432
backend_weight1 =1
backend_data_directory1 ='/data/pgsql11/ro'
backend_flag1 ='DISALLOW_TO_FAILOVER'
backend_application_name1 ='ro'
# - Authentication login information -
enable_pool_hba = on
pool_passwd ='pool_passwd'
# Relevant document information
pid_file_name ='/var/run/pgpool-II-11/pgpool.pid'
# Copying model
replication_mode = off
#load balance Whether the mode is on
load_balance_mode = on
# Whether the master-slave mode is enabled ( important , Read write separation related )
master_slave_mode = on
master_slave_sub_mode ='stream'
# Whether the health check is on , It is mainly used for fail over function
health_check_period =0
health_check_timeout =20
health_check_user ='nobody'
health_check_password =''
health_check_database =''
# Log related configuration
log_destination ='syslog'
log_connections = on
log_hostname = on
log_statement = on
log_per_node_statement = on
pool_hba.conf File configuration , Be similar to pg_hba.conf file :
Add the following contents to the end of the file :host all all 0.0.0.0/0 md5 |
|---|
pool_passwd User name and password information , This file can be generated by executing the following statement :
pg_md5 --md5auth --username=pgpool [email protected] |
|---|
After configuration , Execute the service startup statement to start pg_pool.
systemctl start pgpool-II-11.service
After starting the service , It can be done by systemctl status pgpool-II-11.service See the startup of the service .
PG-Pool-II Read-write separation test
- adopt pgbench adopt pgpool Perform basic data irrigation on the database . /usr/pgsql-11/bin/pgbench -U haha -p 9999 -h 172.27.32.12 test -i -s 10
- Create a new one sql File to test vi test.sql
\set aid random_gaussian(1, :range,10.0)
\set bid random(1,1* :scale)
\set tid random(1,10* :scale)
\set delta random(-5000,5000)
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
SELECT tbalance FROM pgbench_tellers WHERE tid = :tid;
SELECT bid,aid,delta,mtime FROM pgbench_history WHERE tid = :tid;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
- adopt pgpool 2 Perform database read / write data test : /usr/pgsql-11/bin/pgbench -U haha -p 9999 -h 172.27.32.9 test -v -r -P 1 -f ./test.sql -c 300 -j 300 -T 120 -D scale=10000 -D range=100000000
- Because in the above configuration file , We turned on logging SQL sentence , Therefore, you can view what has been executed by different nodes through logs SQL. cat /var/log/messages |grep "DB node id: 1" cat /var/log/messages |grep "DB node id: 0"
- among node ID by 1 is We backend_hostname1 Configured node 1, For our read-only instance group address .
- Where nodes ID by 0 And ours backend_hostname0 Configured nodes 0, For our master node .
- You can see that both read and write statements are distributed to different nodes . The read-write separation function is successfully realized .
cat /var/log/messages |grep"DB node id: 0"
Aug3022:24:49VM-32-9-centos pgpool[3968]: [25447-1]2021-08-3022:24:49: pid3968: LOG: DB node id:0backend pid:33553statement: BEGIN;
Aug3022:24:49VM-32-9-centos pgpool[5126]: [25656-1]2021-08-3022:24:49: pid5126: LOG: DB node id:0backend pid:33531statement: UPDATE pgbench_tellers SET tbalance = tbalance + -651WHERE tid =42973;
Aug3022:24:49VM-32-9-centos pgpool[3974]: [25559-1]2021-08-3022:24:49: pid3974: LOG: DB node id:0backend pid:33551statement: END;
……
cat /var/log/messages |grep"DB node id: 1"
Sep 112:03:25VM-32-9-centos pgpool[20505]: [26250-1]2021-09-0112:03:25: pid20505: LOG: DB node id:1backend pid:20410statement: SELECT abalance FROM pgbench_accounts WHERE aid =45648796;
Sep 112:03:25VM-32-9-centos pgpool[20520]: [27210-1]2021-09-0112:03:25: pid20520: LOG: DB node id:1backend pid:20411statement: SELECT abalance FROM pgbench_accounts WHERE aid =56012538;
Sep 112:03:25VM-32-9-centos pgpool[20522]: [28362-1]2021-09-0112:03:25: pid20522: LOG: DB node id:1backend pid:20401statement: SELECT abalance FROM pgbench_accounts WHERE aid =53695003;
……
边栏推荐
- Web penetration test - 5. Brute force cracking vulnerability - (6) VNC password cracking
- getAttribute 返回值为null
- Abnova多肽设计和合成解决方案
- Advantages of fixed assets management system
- Precautions for online education and training industry filing
- Network timeout configuration method when PR and push are proposed
- Bi-sql distinct
- Loss and optimization of linear regression, machine learning to predict house prices
- 问题:sql创建存储过程
- External network access SVN server (external network access SVN server deployed on the cloud)
猜你喜欢

SAP MTS/ATO/MTO/ETO专题之七:ATO模式1 M+M模式策略用82(6892)

External network access SVN server (external network access SVN server deployed on the cloud)

apipost接口断言详解

阿里云新一代云计算体系架构 CIPU 到底是啥?
Advanced authentication of uni app [Day12]
uni-app进阶之认证【day12】

外网访问svn服务器(外网访问部署在云上的svn服务器)

Abnova多肽设计和合成解决方案

少儿编程课程改革后的培养方式

Facebook internal announcement: instant messaging will be re integrated
随机推荐
少儿编程课程改革后的培养方式
How to create an FTP server on the ECS? Is it safe to create an FTP server on the ECS?
查找GBase 8c数据库当前索引?
SAP MTS/ATO/MTO/ETO专题之七:ATO模式1 M+M模式策略用82(6892)
Problem: SQL create stored procedure
Brief introduction: how much do you know about supply chain attacks
How to build a website for ECS? What are the prices of different ECS
Application practice of helium decentralized lorawan network in Tencent cloud IOT development platform
What is the difference between arm architecture, ARM7, ARM9, STM32, cortex m3 M4, 51 and AVR
Tencent cloud audio and video award-winning evaluation | leave online messages or submit evaluation, win Dajiang UAV /iphone/switch and other awards
什么是数据中台
Disaster recovery series (IV) - disaster recovery construction of business application layer
What are the advantages of ECS? Is ECS better than VM?
How does the VPS server upload data? Is the VPS server free to use?
What are the differences between ECs and virtual hosts? Which is better, ECS or VM?
Activity recommendation | cloud native community meetup phase VII Shenzhen station begins to sign up!
梯度下降法介紹-黑馬程序員機器學習講義
How to enlarge the ECS page? How to select ECS instance specifications?
Verifying data models in golang
What is the principle of Ping? How does the server disable Ping?