当前位置:网站首页>PostgreSQL uses pgpool II to realize read-write separation + load balancing
PostgreSQL uses pgpool II to realize read-write separation + load balancing
2022-07-06 23:53:00 【Hua Weiyun】
One 、Pgpool-II brief introduction
Official website :https://www.pgpool.net/mediawiki/index.php/Main_Page
Pgpool-II It's a PostgreSQL The server and PostgreSQL Middleware working between database clients . It is based on BSD Licensed . It provides the following functions .
Connection pool
Pgpool-II To preserve with PostgreSQL Server connection , And have the same properties ( Use account , database , Protocol version ) Reuse them when new connections come in . It reduces connection overhead , And improve the overall throughput of the system .
Copy
Pgpool-II Can manage multiple PostgreSQL The server . The copy function can be used in 2 Create real-time backups on physical disks or more , So that in the event of a disk failure the service can continue to run without stopping the server .
Load balancing
If the database is copied , On any server SELECT All queries will return the same result .Pgpool-II Use the copy function , By allocating... Between multiple servers SELECT Query to reduce each PostgreSQL Server load , So as to improve the overall throughput of the system . at best , Performance and PostgreSQL The number of servers increased proportionally . In the case of many users executing many queries at the same time , Load balancing works best .
Limit out of connection
PostgreSQL The maximum number of concurrent connections is limited , Connection rejected after so many connections . however , Setting the maximum number of connections increases resource consumption and affects system performance .pgpool-II There are also restrictions on the maximum number of connections , But additional connections will be queued , Instead of returning an error immediately .
House dogs
Watchdog Can coordinate multiple Pgpool-II, Create a powerful cluster system , Avoid a single point of failure or brain crack . The watchdog can be on other pgpool-II Node performs a life check , To detect Pgpoll-II Failure of . If the activity Pgpool-II failure , Then you can use the spare Pgpool-II Promote to active , And take over the virtual IP.
In memory query cache
Querying the cache in memory allows you to save a pair of SELECT Statement and its result . If there is the same SELECT,Pgpool-II Will return the value... From the cache . Because it doesn't involve SQL Parse or access PostgreSQL, So it's very fast in memory cache . On the other hand , In some cases , It may be slower than the normal path , Because it increases the cost of storing cached data .
Pgpool-II speak PostgreSQL The back-end and front-end protocols , And pass messages between the back end and the front end . therefore , Database applications ( front end ) Think Pgpool-II It's practical PostgreSQL The server , The server ( Back end ) take Pgpool-II Think of it as one of its clients . because Pgpool-II Transparent to both the server and the client , So existing database applications can work with Pgpool-II Use it together .Pgpool-II about PostgreSQL The back-end and front-end protocols , And pass connections between them . therefore , Database applications ( front end ) Think Pgpool-II It's practical PostgreSQL The server , The server ( Back end ) take Pgpool-II Think of it as one of its clients . because Pgpool-II Transparent to both the server and the client , So existing database applications can work with Pgpool-II Use it together , Almost no need to change its source code .
Two 、 High availability architecture diagram
PG build 1 Lord 2 The process of copying from stream can refer to “【DB treasure 60】PG12 Highly available 1 Lord 2 From the stream replication environment to build and switch test ”, This paper is based on this article , Use Pgpool-II To achieve read-write separation and load balancing function .
The overall structure is as follows :
3、 ... and 、 Use Docker Rapid deployment Pgpool-II middleware
-- Download mirroring docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/lhrpgpool:4.2.2-- Create a private network docker network create --subnet=172.72.6.0/24 pg-network-- establish Pgpool-II The container of docker rm -f lhrpgpooldocker run -d --name lhrpgpool -h lhrpgpool \ --net=pg-network --ip 172.72.6.6 \ -p 9999:9999 -p 9898:9898 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrpgpool:4.2.2 \ /usr/sbin/initdocker network connect bridge lhrpgpooldocker restart lhrpgpooldocker exec -it lhrpgpool bash
Four 、 To configure Pgpool-II
All of the following operations are in pgsql User execution .
4.1、 Copy parameter file
[root@lhrpgpool etc]# su - pgsqlLast login: Mon Apr 26 14:28:35 CST 2021 on pts/0[pgsql@lhrpgpool /]# cp /postgresql/pgpool/etc/pgpool.conf.sample /postgresql/pgpool/etc/pgpool.conf[pgsql@lhrpgpool /]# cp /postgresql/pgpool/etc/pool_hba.conf.sample /postgresql/pgpool/etc/pool_hba.conf[pgsql@lhrpgpool /]# cp /postgresql/pgpool/etc/pcp.conf.sample /postgresql/pgpool/etc/pcp.conf
4.2、 To configure pgpool.conf
vi Enter column operation :Ctrl + v Enter block selection mode , Then move the cursor to select the line you want to comment on , Then press capital I Enter the insert mode at the beginning of the line , Enter a comment symbol such as // or #, After input , Press two ESC,Vim Will automatically add comments to all the line capitals you selected , Save exit completion comment .
vi /postgresql/pgpool/etc/pgpool.conf# - pgpool Connection Settings -listen_addresses = '*'# - Backend Connection Settings -backend_hostname0 = '172.72.6.2'backend_port0 = 5432backend_weight0 = 1backend_data_directory0 = '/var/lib/postgresql/data'backend_flag0 = 'ALLOW_TO_FAILOVER'backend_application_name0 = 'lhrpg64302'backend_hostname1 = '172.72.6.3'backend_port1 = 5432backend_weight1 = 1backend_data_directory1 = '/var/lib/postgresql/data'backend_flag1 = 'ALLOW_TO_FAILOVER'backend_application_name1 = 'lhrpg64303'backend_hostname2 = '172.72.6.4'backend_port2 = 5432backend_weight2 = 1backend_data_directory2 = '/var/lib/postgresql/data'backend_flag2 = 'ALLOW_TO_FAILOVER'backend_application_name2 = 'lhrpg64304'# - Authentication -enable_pool_hba = on# - Where to log -log_destination = 'syslog'log_connections = on#------------------------------------------------------------------------------# FILE LOCATIONS#------------------------------------------------------------------------------pid_file_name = '/postgresql/pgpool/pgpool.pid'logdir = '/tmp'#------------------------------------------------------------------------------# LOAD BALANCING MODE#------------------------------------------------------------------------------load_balance_mode = on
4.3、 Turn on the system log (root operation )
pgpool By default, the log of is written to stderr, It can be set to syslog in . But because it's written by default LOCAL0 Level logs will be discarded , So it's in /etc/rsyslog.conf Modify the syslog Specified output path :
echo "local0.* /postgresql/pgpool/pgpool.log" >> /etc/rsyslog.confsystemctl restart rsyslog.service
4.4、 To configure pool_hba.conf
su - pgsqlecho "host all all 0.0.0.0/0 md5" >> /postgresql/pgpool/etc/pool_hba.conf
4.5、 Generate pool_passwd file
pg_md5 --md5auth --username=nobody "lhr"pg_md5 --md5auth --username=lhr "lhr"pg_md5 --md5auth --username=pgpool "lhr"pg_md5 --md5auth --username=postgres "lhr"
Will generate pool_passwd file :
[pgsql@lhrpgpool ~]$ pg_md5 --md5auth --username=nobody "lhr"[pgsql@lhrpgpool ~]$ pg_md5 --md5auth --username=lhr "lhr"[pgsql@lhrpgpool ~]$ pg_md5 --md5auth --username=pgpool "lhr"[pgsql@lhrpgpool ~]$ pg_md5 --md5auth --username=postgres "lhr"[pgsql@lhrpgpool ~]$ cd /postgresql/etc[pgsql@lhrpgpool etc]$ cat pool_passwdnobody:md5188b0dfd531e1734c1e5bb4d57053d64lhr:md53e5c401ee2b9f28db1bb075b1b99e0adpgpool:md547b6c1f1700de696bcb6b98dc6a21ab6postgres:md5da3edeb741de62d06ab73785ed222494
4.6、 To configure pcp.conf file
[pgsql@lhrcentos76 ~]$ pg_md5 -u=pgpool "lhr"3996643de967b80174e48fb45d7227b1echo "pgpool:3996643de967b80174e48fb45d7227b1" >> /postgresql/pgpool/etc/pcp.conf
4.7、 Create users in the main library
psql -U postgres -h 192.168.66.35 -p64302create role nobody login encrypted password 'lhr';create role lhr login encrypted password 'lhr';create role pgpool login encrypted password 'lhr';grant postgres to nobody,lhr,pgpool;
stay PostgreSQL There's no concept of distinguishing between users and roles ,CREATE USER by CREATE ROLE Another name for , The two commands are almost identical , The only difference is ”CREATE USER” Command to create the user's LOGIN Property defaults to on , and CREATE ROLE Command to create the user's NOLOGIN Property defaults to on.
5、 ... and 、 start-up Pgpool-II
cat >> /lib/systemd/system/pgpool.service <<"EOF"[Unit]Description=Pgpool-IIAfter=syslog.target network.target[Service]User=pgsqlGroup=pgsqlEnvironmentFile=-/etc/sysconfig/pgpoolExecStart=/postgresql/pgpool/bin/pgpool -f /postgresql/pgpool/etc/pgpool.conf -nExecStop=/postgresql/pgpool/bin/pgpool -f /postgresql/pgpool/etc/pgpool.conf -m fast stopExecReload=/postgresql/pgpool/bin/pgpool -f /postgresql/pgpool/etc/pgpool.conf reloadLimitNOFILE=65536KillMode=processKillSignal=SIGINTRestart=on-abnormalRestartSec=30sTimeoutSec=0[Install]WantedBy=multi-user.targetEOFchmod +x /lib/systemd/system/pgpool.servicesystemctl enable pgpoolsystemctl start pgpoolsystemctl status pgpool
result :
[root@lhrpgpool etc]# systemctl status pgpool● pgpool.service - Pgpool-II Loaded: loaded (/usr/lib/systemd/system/pgpool.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2021-04-26 14:35:27 CST; 1s ago Main PID: 1954 (pgpool) CGroup: /docker/c3f0c9600069f719f49e81e3602f642925feecb5e134c8aedb96753728730013/system.slice/pgpool.service ├─1954 /postgresql/pgpool/bin/pgpool -f /postgresql/pgpool/etc/pgpool.conf -n ├─1956 pgpool: wait for connection request ├─1957 pgpool: wait for connection request ├─1958 pgpool: wait for connection request ├─1959 pgpool: wait for connection request ├─1960 pgpool: wait for connection request ├─1961 pgpool: wait for connection request ├─1962 pgpool: wait for connection request ├─1963 pgpool: wait for connection request ├─1964 pgpool: wait for connection request ├─1965 pgpool: wait for connection request ├─1966 pgpool: wait for connection request ├─1967 pgpool: wait for connection request ├─1968 pgpool: wait for connection request ├─1969 pgpool: wait for connection request ├─1970 pgpool: wait for connection request ├─1971 pgpool: wait for connection request ├─1972 pgpool: wait for connection request ├─1973 pgpool: wait for connection request ├─1974 pgpool: wait for connection request ├─1975 pgpool: wait for connection request ├─1976 pgpool: wait for connection request ├─1977 pgpool: wait for connection request ├─1978 pgpool: wait for connection request ├─1979 pgpool: wait for connection request ├─1980 pgpool: wait for connection request ├─1981 pgpool: wait for connection request ├─1982 pgpool: wait for connection request ├─1983 pgpool: wait for connection request ├─1984 pgpool: wait for connection request ├─1985 pgpool: wait for connection request ├─1986 pgpool: wait for connection request ├─1987 pgpool: wait for connection request ├─1988 pgpool: PCP: wait for connection request ├─1989 pgpool: worker process ├─1990 pgpool: health check process(0) ├─1991 pgpool: health check process(1) └─1992 pgpool: health check process(2)Apr 26 14:35:28 lhrpgpool pgpool[1954]: [14-1] 2021-04-26 14:35:28: pid 1954: LOG: find_primary_node: standby node is 2Apr 26 14:35:28 lhrpgpool pgpool[1988]: [15-1] 2021-04-26 14:35:28: pid 1988: LOG: PCP process: 1988 startedApr 26 14:35:28 lhrpgpool pgpool[1990]: [15-1] 2021-04-26 14:35:28: pid 1990: LOG: process startedApr 26 14:35:28 lhrpgpool pgpool[1991]: [15-1] 2021-04-26 14:35:28: pid 1991: LOG: process startedApr 26 14:35:28 lhrpgpool pgpool[1989]: [15-1] 2021-04-26 14:35:28: pid 1989: LOG: process startedApr 26 14:35:28 lhrpgpool pgpool[1992]: [15-1] 2021-04-26 14:35:28: pid 1992: LOG: process startedApr 26 14:35:28 lhrpgpool pgpool[1954]: [15-1] 2021-04-26 14:35:28: pid 1954: LOG: pgpool-II successfully started. version 4.2.2 (chichiriboshi)Apr 26 14:35:28 lhrpgpool pgpool[1954]: [16-1] 2021-04-26 14:35:28: pid 1954: LOG: node status[0]: 1Apr 26 14:35:28 lhrpgpool pgpool[1954]: [17-1] 2021-04-26 14:35:28: pid 1954: LOG: node status[1]: 2Apr 26 14:35:28 lhrpgpool pgpool[1954]: [18-1] 2021-04-26 14:35:28: pid 1954: LOG: node status[2]: 2
6、 ... and 、 Query node status
[pgsql@lhrpgpool ~]$ psql -U nobody -h localhost -p 9999 -d postgrespsql (13.2, server 12.2 (Debian 12.2-2.pgdg100+1))Type "help" for help.postgres=> show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change ---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 14:35:27 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 0 | false | 0 | | | 2021-04-26 14:35:27 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 0 | true | 0 | | | 2021-04-26 14:35:27(3 rows)
see pgpool Backend state :
pcp_node_info -U pgpool -h localhost -p 9898 -n 0 -vpcp_node_info -U pgpool -h localhost -p 9898 -n 1 -vpcp_node_info -U pgpool -h localhost -p 9898 -n 2 -v
result :
[pgsql@lhrpgpool ~]$ pcp_node_info -U pgpool -h localhost -p 9898 -n 0 -vPassword: Hostname : 172.72.6.2Port : 5432Status : 2Weight : 0.333333Status Name : upRole : primaryReplication Delay : 0Replication State : Replication Sync State : Last Status Change : 2021-04-26 14:35:27[pgsql@lhrpgpool ~]$ pcp_node_info -U pgpool -h localhost -p 9898 -n 1 -vPassword: Hostname : 172.72.6.3Port : 5432Status : 2Weight : 0.333333Status Name : upRole : standbyReplication Delay : 0Replication State : Replication Sync State : Last Status Change : 2021-04-26 14:35:27[pgsql@lhrpgpool ~]$ pcp_node_info -U pgpool -h localhost -p 9898 -n 2 -vPassword: Hostname : 172.72.6.4Port : 5432Status : 2Weight : 0.333333Status Name : upRole : standbyReplication Delay : 0Replication State : Replication Sync State : Last Status Change : 2021-04-26 14:35:27
7、 ... and 、 Test read-write separation + Load balancing
Before the test , Consider modifying the file pgpool.conf The following parameters in :
log_statement=alllog_per_node_statement =onclient_min_messages =loglog_min_messages = info
take effect :
pgpool reload
After the test is completed , Change back to the original value :
log_statement=offlog_per_node_statement = off# client_min_messages =notice# log_min_messages = warning
Testing process :
-- open 3 A window psql -U postgres -h 192.168.66.35 -p 9999 -d sbtestcreate table test(id int);insert into test values(1);select * from test;
window 1:
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -p 9999 -d sbtestPassword for user postgres:psql (13.2, server 12.2 (Debian 12.2-2.pgdg100+1))Type "help" for help.sbtest=# show pool_nodes;LOG: statement: show pool_nodes;LOG: DB node id: 0 backend pid: 10106 statement: SELECT version() node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 0 | true | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 0 | false | 0 | | | 2021-04-26 09:54:44(3 rows)sbtest=# create table test(id int);LOG: statement: create table test(id int);LOG: DB node id: 0 backend pid: 10106 statement: create table test(id int);CREATE TABLEsbtest=# insert into test values (1);LOG: statement: insert into test values (1);LOG: DB node id: 0 backend pid: 10106 statement: insert into test values (1);INSERT 0 1sbtest=# select * from test;LOG: statement: select * from test;LOG: DB node id: 0 backend pid: 10106 statement: SELECT count(*) FROM pg_class AS c, pg_namespace AS n WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relnamespace = n.oid AND n.nspname = 'pg_catalog'LOG: DB node id: 0 backend pid: 10106 statement: SELECT count(*) FROM pg_catalog.pg_class AS c, pg_namespace AS n WHERE c.relname = 'test' AND c.relnamespace = n.oid AND n.nspname ~ '^pg_temp_'LOG: DB node id: 0 backend pid: 10106 statement: SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relpersistence = 'u'LOG: DB node id: 1 backend pid: 6069 statement: select * from test; id---- 1(1 row)sbtest=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 1 | true | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 0 | false | 0 | | | 2021-04-26 09:54:44(3 rows)
window 2:
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -p 9999 -d sbtestPassword for user postgres:psql (13.2, server 12.2 (Debian 12.2-2.pgdg100+1))Type "help" for help.sbtest=# show pool_nodes;LOG: statement: show pool_nodes;LOG: DB node id: 0 backend pid: 10116 statement: SELECT version() node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 0 | true | 0 | | | 2021-04-26 09:54:44(3 rows)sbtest=# select * from test;LOG: statement: select * from test;LOG: DB node id: 0 backend pid: 10116 statement: SELECT count(*) FROM pg_class AS c, pg_namespace AS n WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relnamespace = n.oid AND n.nspname = 'pg_catalog'LOG: DB node id: 0 backend pid: 10116 statement: SELECT count(*) FROM pg_catalog.pg_class AS c, pg_namespace AS n WHERE c.relname = 'test' AND c.relnamespace = n.oid AND n.nspname ~ '^pg_temp_'LOG: DB node id: 0 backend pid: 10116 statement: SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relpersistence = 'u'LOG: DB node id: 2 backend pid: 6085 statement: select * from test; id---- 1(1 row)sbtest=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 1 | true | 0 | | | 2021-04-26 09:54:44(3 rows)sbtest=# insert into test values(2);LOG: statement: insert into test values(2);LOG: DB node id: 0 backend pid: 10116 statement: insert into test values(2);INSERT 0 1sbtest=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 1 | true | 0 | | | 2021-04-26 09:54:44(3 rows)
window 3:
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -p 9999 -d sbtestPassword for user postgres:psql (13.2, server 12.2 (Debian 12.2-2.pgdg100+1))Type "help" for help.sbtest=# show pool_nodes;LOG: statement: show pool_nodes;LOG: DB node id: 0 backend pid: 10127 statement: SELECT version() node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 1 | true | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44(3 rows)sbtest=# select * from test;LOG: statement: select * from test;LOG: DB node id: 0 backend pid: 10127 statement: SELECT count(*) FROM pg_class AS c, pg_namespace AS n WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relnamespace = n.oid AND n.nspname = 'pg_catalog'LOG: DB node id: 0 backend pid: 10127 statement: SELECT count(*) FROM pg_catalog.pg_class AS c, pg_namespace AS n WHERE c.relname = 'test' AND c.relnamespace = n.oid AND n.nspname ~ '^pg_temp_'LOG: DB node id: 0 backend pid: 10127 statement: SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.oid = pg_catalog.to_regclass('"test"') AND c.relpersistence = 'u'LOG: DB node id: 1 backend pid: 6084 statement: select * from test; id---- 1 2(2 rows)sbtest=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 2 | true | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44(3 rows)sbtest=# insert into test values(3);LOG: statement: insert into test values(3);LOG: DB node id: 0 backend pid: 10127 statement: insert into test values(3);INSERT 0 1sbtest=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 0 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 2 | true | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 1 | false | 0 | | | 2021-04-26 09:54:44(3 rows)-- Do a few more tests postgres=# show pool_nodes;LOG: statement: show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change---------+------------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+--------------------- 0 | 172.72.6.2 | 5432 | up | 0.333333 | primary | 6 | false | 0 | | | 2021-04-26 09:54:44 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 7 | false | 0 | | | 2021-04-26 09:54:44 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 8 | true | 0 | | | 2021-04-26 09:54:44(3 rows)
You can see , Read operations are evenly allocated to 0、1 and 2 this 3 A node , Write operations are assigned only to 0 Node .
in addition , Relevant information will also be recorded in the alarm log (/postgresql/pgpool/pgpool.log).
Apr 26 10:01:06 lhrpgpool pgpool[32486]: [20-1] 2021-04-26 10:01:06: pid 32486: LOG: statement: show pool_nodes;Apr 26 10:01:23 lhrpgpool pgpool[32486]: [21-1] 2021-04-26 10:01:23: pid 32486: LOG: statement: insert into test values(3);Apr 26 10:01:23 lhrpgpool pgpool[32486]: [22-1] 2021-04-26 10:01:23: pid 32486: LOG: DB node id: 0 backend pid: 10127 statement: insert into test values(3);Apr 26 10:01:26 lhrpgpool pgpool[32486]: [23-1] 2021-04-26 10:01:26: pid 32486: LOG: statement: show pool_nodes;Apr 26 10:02:02 lhrpgpool pgpool[32486]: [24-1] 2021-04-26 10:02:02: pid 32486: LOG: statement: select * from test;Apr 26 10:02:02 lhrpgpool pgpool[32486]: [25-1] 2021-04-26 10:02:02: pid 32486: LOG: DB node id: 1 backend pid: 6084 statement: select * from test;Apr 26 10:02:04 lhrpgpool pgpool[32485]: [25-1] 2021-04-26 10:02:04: pid 32485: LOG: statement: select * from test;Apr 26 10:02:04 lhrpgpool pgpool[32485]: [26-1] 2021-04-26 10:02:04: pid 32485: LOG: DB node id: 1 backend pid: 6069 statement: select * from test;Apr 26 10:02:06 lhrpgpool pgpool[32485]: [27-1] 2021-04-26 10:02:06: pid 32485: LOG: statement: select * from test;Apr 26 10:02:06 lhrpgpool pgpool[32485]: [28-1] 2021-04-26 10:02:06: pid 32485: LOG: DB node id: 1 backend pid: 6069 statement: select * from test;Apr 26 10:02:09 lhrpgpool pgpool[32476]: [24-1] 2021-04-26 10:02:09: pid 32476: LOG: statement: select * from test;Apr 26 10:02:09 lhrpgpool pgpool[32476]: [25-1] 2021-04-26 10:02:09: pid 32476: LOG: DB node id: 2 backend pid: 6085 statement: select * from test;Apr 26 10:02:11 lhrpgpool pgpool[32486]: [26-1] 2021-04-26 10:02:11: pid 32486: LOG: statement: select * from test;Apr 26 10:02:11 lhrpgpool pgpool[32486]: [27-1] 2021-04-26 10:02:11: pid 32486: LOG: DB node id: 1 backend pid: 6084 statement: select * from test;Apr 26 10:02:13 lhrpgpool pgpool[32486]: [28-1] 2021-04-26 10:02:13: pid 32486: LOG: statement: select * from test;Apr 26 10:02:13 lhrpgpool pgpool[32486]: [29-1] 2021-04-26 10:02:13: pid 32486: LOG: DB node id: 1 backend pid: 6084 statement: select * from test;
边栏推荐
- How to answer the dualistic opposition of Zhihu
- pinia 模块划分
- [automated testing framework] what you need to know about unittest
- leetcode:236. 二叉树的最近公共祖先
- leetcode:236. The nearest common ancestor of binary tree
- Newsletter L Huobi ventures is in-depth contact with genesis public chain
- How to find out if the U disk file of the computer reinstallation system is hidden
- 使用源码编译来安装PostgreSQL13.3数据库
- What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
- Cas d'essai fonctionnel universel de l'application
猜你喜欢
The largest single investment in the history of Dachen was IPO today
How rider uses nuget package offline
Experiment 4: installing packages from Gui
STM32通过串口进入和唤醒停止模式
1000 words selected - interface test basis
传统企业要为 Web3 和去中心化做的 11 个准备
AVL树到底是什么?
Master binary tree in one article
MATLIB reads data from excel table and draws function image
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
随机推荐
One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
设计一个抢红包系统
Pytest multi process / multi thread execution test case
AI金榜题名时,MLPerf榜单的份量究竟有多重?
Newsletter L Huobi ventures is in-depth contact with genesis public chain
[system analyst's road] Chapter 7 double disk system design (service-oriented development method)
MATLIB从excel表中读取数据并画出函数图像
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
How to find out if the U disk file of the computer reinstallation system is hidden
Daily question brushing record (XV)
STM32通过串口进入和唤醒停止模式
Oracle对表进行的常用修改命令
Computer reinstallation system teaching, one click fool operation, 80% of people have learned
Penetration test --- database security: detailed explanation of SQL injection into database principle
openresty ngx_lua子请求
Unity color palette | color palette | stepless color change function
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
短链的设计
Without CD, I'll teach you a trick to restore the factory settings of win10 system
编译logisim