当前位置:网站首页>Use of pgpool II and pgpooladmin
Use of pgpool II and pgpooladmin
2022-07-07 02:21:00 【Hua Weiyun】
One 、 brief introduction
I have published several articles about PG Articles copied from the master-slave stream in :
- 【DB treasure 60】PG12 Highly available 1 Lord 2 From the stream replication environment to build and switch test
- 【DB treasure 61】PostgreSQL Use Pgpool-II Read and write separation + Load balancing
- PostgreSQL Highly available repmgr(1 Lord 2 from +1witness)+Pgpool-II Realize master-slave switching + Read / write separation + Load balancing
- 【DB treasure 72】pgpool-II and pgpoolAdmin Use
of pgpool-II Related documents of :
however , The previous article did not introduce pgpoolAdmin Knowledge , This is for pgpool Developed web Interface tools , It's more practical .
pgpool The project also provides a way to use PHP Written Web Management tools , be called “pgpoolAdmin ", The Web Management tools can be used in Web Interface implementation pgpool-II Configuration of .
pgpoolAdmin download :https://pgpool.net/mediawiki/index.php/Downloads
pgpoolAdmin Official documents :https://www.pgpool.net/docs/pgpoolAdmin/index_en.html
The pgpool Administration Tool is management tool of pgpool. It is possible to monitor, start, stop pgpool and change setting for pgpool.
PgpoolAdmin Is management pgpool Of WEB Interface tools , It can be done to pgpool monitor , Start stop service , change setting .
Let's take a picture first :
Today we will introduce pgpool-II and pgpoolAdmin Use .
Two 、 Environment Architecture
Be careful :
In this environment 192.168.66.35 or 192.168.1.35 All refer to the same host .
All environments in the above figure are installed in the host .
3、 ... and 、 Rapid deployment 1 Lord 2 Copy environment from stream
3.1、 Application host
-- Pull the mirror image docker pull postgres:12-- Create a private network docker network create --subnet=172.72.6.0/24 pg-network-- Create host related mapping paths mkdir -p /docker_data/pg/lhrpg64302/datamkdir -p /docker_data/pg/lhrpg64303/datamkdir -p /docker_data/pg/lhrpg64304/data-- Main library docker rm -f lhrpg64302rm -rf /docker_data/pg/lhrpg64302/datadocker run -d --name lhrpg64302 -h lhrpg64302 \ -p 64302:5432 --net=pg-network --ip 172.72.6.2 \ -v /docker_data/pg/lhrpg64302/data:/var/lib/postgresql/data \ -v /docker_data/pg/lhrpg64302/bk:/bk \ -e POSTGRES_PASSWORD=lhr \ -e TZ=Asia/Shanghai \ postgres:12-- Slave Library 1docker rm -f lhrpg64303rm -rf /docker_data/pg/lhrpg64303/datarm -rf /docker_data/pg/lhrpg64303/bkdocker run -d --name lhrpg64303 -h lhrpg64303 \ -p 64303:5432 --net=pg-network --ip 172.72.6.3 \ -v /docker_data/pg/lhrpg64303/data:/var/lib/postgresql/data \ -v /docker_data/pg/lhrpg64303/bk:/bk \ -e POSTGRES_PASSWORD=lhr \ -e TZ=Asia/Shanghai \ postgres:12 -- Slave Library 2docker rm -f lhrpg64304rm -rf /docker_data/pg/lhrpg64304/datarm -rf /docker_data/pg/lhrpg64304/bkdocker run -d --name lhrpg64304 -h lhrpg64304 \ -p 64304:5432 --net=pg-network --ip 172.72.6.4 \ -v /docker_data/pg/lhrpg64304/data:/var/lib/postgresql/data \ -v /docker_data/pg/lhrpg64304/bk:/bk \ -e POSTGRES_PASSWORD=lhr \ -e TZ=Asia/Shanghai \ postgres:12 -- Remote login psql -U postgres -h 192.168.66.35 -p 64302psql -U postgres -h 192.168.66.35 -p 64303psql -U postgres -h 192.168.66.35 -p 64304
3.2、 Main warehouse operation
3.2.1、 Release the firewall from the main database
cat << EOF > /docker_data/pg/lhrpg64302/data/pg_hba.conf# TYPE DATABASE USER ADDRESS METHODlocal all all trusthost all all 127.0.0.1/32 trusthost all all 0.0.0.0/0 md5host replication all 0.0.0.0/0 md5EOF
Pay attention to add replication
3.2.2、 Main library configuration archive
docker exec -it lhrpg64302 bash-- The path also needs to be created from the library mkdir -p /postgresql/archivechown -R postgres.postgres /postgresql/archivecat >> /var/lib/postgresql/data/postgresql.conf <<"EOF"wal_level='replica'archive_mode='on'archive_command='test ! -f /postgresql/archive/%f && cp %p /postgresql/archive/%f'restore_command='cp /postgresql/archive/%f %p'max_wal_senders=10wal_keep_segments=256wal_sender_timeout=60sEOF-- restart docker restart lhrpg64302-- or :/usr/lib/postgresql/12/bin/pg_ctl restart -D /var/lib/postgresql/data/psql -U postgres -h 192.168.66.35 -p 64302select * from pg_settings where name in ('wal_level','archive_mode','archive_command');-- Switch Archive select pg_switch_wal();
Execution results :
postgres=# select * from pg_settings where name in ('wal_level','archive_mode','archive_command'); name | setting | unit | category | short_desc | extra_desc | context | vartype | source | min_val | max_val | enumvals | boot_val | reset_val | sourcefile | sourceline | pending_restart-----------------+------------------------------------------------------------------+------+-----------------------------+-------------------------------------------------------------------+------------+------------+---------+--------------------+---------+---------+---------------------------+----------+------------------------------------------------------------------+------------------------------------------+------------+----------------- archive_command | test ! -f /postgresql/archive/%f && cp %p /postgresql/archive/%f | | Write-Ahead Log / Archiving | Sets the shell command that will be called to archive a WAL file. | | sighup | string | configuration file | | | | | test ! -f /postgresql/archive/%f && cp %p /postgresql/archive/%f | /var/lib/postgresql/data/postgresql.conf | 753 | f archive_mode | on | | Write-Ahead Log / Archiving | Allows archiving of WAL files using archive_command. | | postmaster | enum | configuration file | | | {always,on,off} | off | on | /var/lib/postgresql/data/postgresql.conf | 752 | f wal_level | replica | | Write-Ahead Log / Settings | Set the level of information written to the WAL. | | postmaster | enum | configuration file | | | {minimal,replica,logical} | replica | replica | /var/lib/postgresql/data/postgresql.conf | 751 | f(3 rows)postgres=# select * from pg_stat_get_archiver();-[ RECORD 1 ]------+-----------------------------------------archived_count | 8last_archived_wal | 000000010000000000000006.00000028.backuplast_archived_time | 2021-04-22 11:42:54.049649+00failed_count | 0last_failed_wal |last_failed_time |stats_reset | 2021-04-22 11:35:55.727069+00postgres=# select pg_switch_wal();-[ RECORD 1 ]-+----------pg_switch_wal | 0/7015058postgres=# select * from pg_stat_get_archiver();-[ RECORD 1 ]------+------------------------------archived_count | 9last_archived_wal | 000000010000000000000007last_archived_time | 2021-04-23 01:00:30.076916+00failed_count | 0last_failed_wal |last_failed_time |stats_reset | 2021-04-22 11:35:55.727069+00-- Before switching archive root@lhrpg64302:/# ps -ef|grep postpostgres 1 0 0 01:28 ? 00:00:00 postgrespostgres 26 1 0 01:28 ? 00:00:00 postgres: checkpointer postgres 27 1 0 01:28 ? 00:00:00 postgres: background writer postgres 28 1 0 01:28 ? 00:00:00 postgres: walwriter postgres 29 1 0 01:28 ? 00:00:00 postgres: autovacuum launcher postgres 30 1 0 01:28 ? 00:00:00 postgres: archiver postgres 31 1 0 01:28 ? 00:00:00 postgres: stats collector postgres 32 1 0 01:28 ? 00:00:00 postgres: logical replication launcher postgres 33 1 0 01:29 ? 00:00:00 postgres: postgres postgres 172.72.6.1(6884) idleroot 40 34 0 01:29 pts/0 00:00:00 grep postroot@lhrpg64302:/# cd /postgresql/archive/root@lhrpg64302:/postgresql/archive# ls -ltotal 0-- Switch Archive postgres=# select pg_switch_wal(); pg_switch_wal--------------- 0/1645528(1 row)-- After switching archiving root@lhrpg64302:/postgresql/archive# ls -ltotal 16384-rw------- 1 postgres postgres 16777216 Apr 23 01:30 000000010000000000000001root@lhrpg64302:/postgresql/archive# ps -ef|grep post postgres 1 0 0 01:28 ? 00:00:00 postgrespostgres 26 1 0 01:28 ? 00:00:00 postgres: checkpointer postgres 27 1 0 01:28 ? 00:00:00 postgres: background writer postgres 28 1 0 01:28 ? 00:00:00 postgres: walwriter postgres 29 1 0 01:28 ? 00:00:00 postgres: autovacuum launcher postgres 30 1 0 01:28 ? 00:00:00 postgres: archiver last was 000000010000000000000001postgres 31 1 0 01:28 ? 00:00:00 postgres: stats collector postgres 32 1 0 01:28 ? 00:00:00 postgres: logical replication launcher postgres 33 1 0 01:29 ? 00:00:00 postgres: postgres postgres 172.72.6.1(6884) idleroot 47 34 0 01:30 pts/0 00:00:00 grep post
- Parameters max_wal_senders Introduce :
Specifies the maximum number of concurrent connections from standby servers or streaming base backup clients (i.e., the maximum number of simultaneously running WAL sender processes). The default is zero, meaning replication is disabled. WAL sender processes count towards the total number of connections, so the parameter cannot be set higher than max_connections. This parameter can only be set at server start. wal_level must be set to archive or hot_standby to allow connections from standby servers.
in other words , This parameter is set on the host , Is the sum of the number of concurrent connections from the slave to the host , So this parameter is a positive integer . The default value is 0, That is, there is no stream copy function by default . The number of concurrent connections from the process point of view , It's the individual wal sender Sum of processes , Can pass ps -ef|grep senders Check it out. , Therefore, the value cannot exceed the maximum number of connections in the system (max_connections, The BUG stay 9.1.5 Repaired ), You can allow more than the actual number of stream replication users . This parameter change requires a restart DB, For example, I only have one slave :
[[email protected] database]$ ps -ef|grep sender
postgres 21257 21247 0 20:57 ? 00:00:00 postgres: wal sender process repuser 192.25.10.71(46161) streaming 0/4018ED8
postgres 22193 20949 0 23:02 pts/0 00:00:00 grep sender
- Parameters wal_keep_segments=256 Introduce
Indicates how many... Are reserved WAL file . If the source database business is busy , Then this value should be increased accordingly .
stay PG13 in ,wal_keep_segments Has been cancelled , change to the use of sth. wal_keep_size
- Parameters wal_sender_timeout=60s Introduce
Break replication connections that are inactive for more than a specified number of milliseconds . This is useful for the sending server to detect a backup crash or network outage . Set to 0 The timeout mechanism will be disabled . This parameter can only be in postgresql.conf On the server or on the command line . The default value is 60 second .
3.2.3、 The main library creates a copy user
create role replhr login encrypted password 'lhr' replication;
To create a user, you need to add replication Options .
3.3、 Operation from the library
3.3.1、 Backup the master database from the slave database
here , We can backup from the library first .
docker exec -it lhrpg64303 bashmkdir -p /bkchown postgres:postgres /bksu - postgrespg_basebackup -h 172.72.6.2 -p 5432 -U replhr -l bk20210422 -F p -P -R -D /bk
After execution , Will produce files standby.signal, as follows :
root@lhrpg64303:/# mkdir -p /bkroot@lhrpg64303:/# chown postgres:postgres /bkroot@lhrpg64303:/# root@lhrpg64303:/# su - postgrespostgres@lhrpg64303:~$ postgres@lhrpg64303:~$ pg_basebackup -h 172.72.6.2 -p 5432 -U replhr -l bk20210422 -F p -P -R -D /postgresql/pgdata Password: 24560/24560 kB (100%), 1/1 tablespacepostgres@lhrpg64303:~$ cd /postgresql/pgdata/postgres@lhrpg64303:/postgresql/pgdata$ ll-bash: ll: command not foundpostgres@lhrpg64303:/postgresql/pgdata$ ls -ltotal 116-rw------- 1 postgres postgres 3 Apr 22 10:52 PG_VERSION-rw------- 1 postgres postgres 209 Apr 22 10:52 backup_labeldrwx------ 5 postgres postgres 4096 Apr 22 10:52 basedrwx------ 2 postgres postgres 4096 Apr 22 10:52 globaldrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_commit_tsdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_dynshmem-rw-r--r-- 1 postgres postgres 243 Apr 22 10:52 pg_hba.conf-rw------- 1 postgres postgres 1636 Apr 22 10:52 pg_ident.confdrwx------ 4 postgres postgres 4096 Apr 22 10:52 pg_logicaldrwx------ 4 postgres postgres 4096 Apr 22 10:52 pg_multixactdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_notifydrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_replslotdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_serialdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_snapshotsdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_statdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_stat_tmpdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_subtransdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_tblspcdrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_twophasedrwx------ 3 postgres postgres 4096 Apr 22 10:52 pg_waldrwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_xact-rw------- 1 postgres postgres 255 Apr 22 10:52 postgresql.auto.conf-rw------- 1 postgres postgres 26756 Apr 22 10:52 postgresql.conf-rw------- 1 postgres postgres 0 Apr 22 10:52 standby.signalpostgres@lhrpg64303:/postgresql/pgdata$
stay PG12 Before ,-R After the backup is completed, it will automatically generate recovery.conf file , Information used for stream replication to judge master-slave synchronization . But from PG12 Start , This file is no longer needed . Just in the parameter file postgresql.conf Middle configuration primary_conninfo Parameters can be .
3.3.2、 Restore from library 1
-- Close slave Library 1, Delete the data file from the library , And overwrite the backup file with the data file from the library docker stop lhrpg64303rm -rf /docker_data/pg/lhrpg64303/data/*cp -r /docker_data/pg/lhrpg64303/bk/* /docker_data/pg/lhrpg64303/data/
3.3.3、 Restore from library 2
-- Close slave Library 2, Delete the data file from the library , And overwrite the backup file with the data file from the library docker stop lhrpg64304rm -rf /docker_data/pg/lhrpg64304/data/*cp -r /docker_data/pg/lhrpg64303/bk/* /docker_data/pg/lhrpg64304/data/
3.3.4、 modify 2 From the library primary_conninfo Parameters
-- Slave Library 1cat >> /docker_data/pg/lhrpg64303/data/postgresql.conf <<"EOF"primary_conninfo = 'host=172.72.6.2 port=5432 user=replhr password=lhr'EOF-- Slave Library 2cat >> /docker_data/pg/lhrpg64304/data/postgresql.conf <<"EOF"primary_conninfo = 'host=172.72.6.2 port=5432 user=replhr password=lhr'EOF
3.3.5、 Start from library
docker start lhrpg64303 lhrpg64304
Main library process :
root@lhrpg64302:/# ps -ef|grep postpostgres 1 0 0 11:35 ? 00:00:00 postgrespostgres 26 1 0 11:35 ? 00:00:00 postgres: checkpointer postgres 27 1 0 11:35 ? 00:00:00 postgres: background writer postgres 28 1 0 11:35 ? 00:00:00 postgres: walwriter postgres 29 1 0 11:35 ? 00:00:00 postgres: autovacuum launcher postgres 30 1 0 11:35 ? 00:00:00 postgres: archiver last was 000000010000000000000006.00000028.backuppostgres 31 1 0 11:35 ? 00:00:00 postgres: stats collector postgres 32 1 0 11:35 ? 00:00:00 postgres: logical replication launcher postgres 33 1 0 11:35 ? 00:00:00 postgres: postgres postgres 172.72.6.1(52776) idlepostgres 129 1 0 11:48 ? 00:00:00 postgres: walsender replhr 172.72.6.3(40056) streaming 0/7000148
From the library process :
root@lhrpg64303:/# ps -ef|grep postpostgres 1 0 0 11:48 ? 00:00:00 postgrespostgres 26 1 0 11:48 ? 00:00:00 postgres: startup recovering 000000010000000000000007postgres 27 1 0 11:48 ? 00:00:00 postgres: checkpointer postgres 28 1 0 11:48 ? 00:00:00 postgres: background writer postgres 29 1 0 11:48 ? 00:00:00 postgres: stats collector postgres 30 1 0 11:48 ? 00:00:00 postgres: walreceiver streaming 0/7000148postgres 31 1 0 11:48 ? 00:00:00 postgres: postgres postgres 172.72.6.1(54413) idle
Four 、 Deploy and use pgpool-II and pgpoolAdmin Tools
[root@lhrpgpool /]# systemctl enable httpdCreated symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.[root@lhrpgpool /]# [root@lhrpgpool /]# systemctl start httpd[root@lhrpgpool /]# systemctl status httpd● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2021-06-24 15:11:58 CST; 10s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 602 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /docker/d45b808bb68bd3fa21db1881b6fc82a1ae194abc88fcbb6b8667875d9257ac54/system.slice/httpd.service ├─602 /usr/sbin/httpd -DFOREGROUND ├─603 /usr/sbin/httpd -DFOREGROUND ├─604 /usr/sbin/httpd -DFOREGROUND ├─605 /usr/sbin/httpd -DFOREGROUND ├─606 /usr/sbin/httpd -DFOREGROUND └─607 /usr/sbin/httpd -DFOREGROUNDJun 24 15:11:58 lhrpgpool systemd[1]: Starting The Apache HTTP Server...Jun 24 15:11:58 lhrpgpool httpd[602]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this messageJun 24 15:11:58 lhrpgpool systemd[1]: Started The Apache HTTP Server.
Web The login address :
- Host login :http://192.168.1.35:180/admin/login.php
User name and password :pgpooladmin/lhr
- Login in container :http://127.0.0.1/admin/login.php
To log in the container , You need to log in to Linux In my desktop , We log in via remote desktop :
User name and password :root/lhr
open Firefox browser , Enter the following address :http://127.0.0.1/admin/login.php
You can also log in .
The interface you can see after logging in :
Each parameter has a detailed description , You can also refer to :
4.4、 test pgpool-II Separation of reading and writing + Load balancing + Memory query cache function
4.4.1、 Close the memory query cache first
Let's turn off the memory query cache function first , Turn on this function later .
vi /postgresql/pgpool/etc/pgpool.confmemory_cache_enabled = off
When the configuration is complete , Restart pgpool service :
systemctl restart pgpool
4.4.2、 Test read-write separation + Load balancing
Testing process :
-- open 3 A window , The password for lhrpsql -U postgres -h 192.168.66.35 -p 19999 -d sbtestcreate table test(id int);insert into test values(1);select * from test;show pool_nodes;show pool_backend_stats;
– obtain pgPool_II Version information
show pool_version;– View the configuration file
show pool_status;– Get node information
show pool_nodes;– obtain pgPool-II Process information
show pool_processes;– obtain pgPool-II All connection pool information
show pool_pools;– Command execution statistics
show pool_backend_stats;– Health Statistics
show pool_health_check_stats;– Cache statistics
show pool_cache;
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -p 19999 -d sbtestPassword for user postgres:psql (13.3, server 12.2 (Debian 12.2-2.pgdg100+1))Type "help" for help.sbtest=#sbtest=# 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-06-24 15:38:35 1 | 172.72.6.3 | 5432 | up | 0.333333 | standby | 0 | false | 0 | | | 2021-06-24 15:38:35 2 | 172.72.6.4 | 5432 | up | 0.333333 | standby | 0 | true | 0 | | | 2021-06-24 15:38:35(3 rows)sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0(3 rows)sbtest=#sbtest=# create table test(id int);CREATE TABLEsbtest=# insert into test values(1);INSERT 0 1sbtest=# select * from test; id---- 1(1 row)sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0(3 rows)sbtest=# select * from test; id---- 1(1 row)sbtest=# select * from test; id---- 1(1 row)sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0(3 rows)
Use shell To test load balancing :
[pgsql@lhrpgpool ~]$ for i in $(seq 1 20); do psql -U postgres -h 127.0.0.1 -p 9999 -d sbtest -c 'SELECT inet_server_addr()'; done | egrep '172.' 172.72.6.4 172.72.6.2 172.72.6.4 172.72.6.4 172.72.6.4 172.72.6.3 172.72.6.3 172.72.6.3 172.72.6.4 172.72.6.3 172.72.6.2 172.72.6.4 172.72.6.3 172.72.6.4 172.72.6.4 172.72.6.2 172.72.6.3 172.72.6.4 172.72.6.2 172.72.6.2 sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 23 | 1 | 0 | 0 | 1 | 61 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 18 | 0 | 0 | 0 | 0 | 18 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 28 | 0 | 0 | 0 | 0 | 26 | 0 | 0 | 1(3 rows)
You can see ,172.72.6.2、172.72.6.3 and 172.72.6.4 The server is balanced read .
Next, the parameter file /postgresql/pgpool/etc/pgpool.conf Medium backend_weight0 It is amended as follows 0, Restart again pgpool After the test :
[pgsql@lhrpgpool ~]$ for i in $(seq 1 50); do psql -U postgres -h 127.0.0.1 -p 9999 -d sbtest -c 'SELECT inet_server_addr()'; done | egrep '172.' 172.72.6.3 172.72.6.3 172.72.6.4.............. 172.72.6.3 172.72.6.3 172.72.6.3 172.72.6.4 172.72.6.4 172.72.6.4 sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 0 | 0 | 0 | 0 | 50 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 30 | 0 | 0 | 0 | 0 | 30 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 20 | 0 | 0 | 0 | 0 | 20 | 0 | 0 | 0(3 rows)
You can see , All reads are sent to 172.72.6.3 and 172.72.6.4 Yes .
4.4.3、 Open the memory query cache
https://www.pgpool.net/docs/latest/en/html/runtime-in-memory-query-cache.html
https://www.pgpool.net/docs/pgpool-II-3.2.5/pgpool-zh_cn.html#memqcache
You can use memory based query caching in any mode . It is different from the above query cache , Because memory based query caching is much faster , Because the cache is stored in memory . in addition , If the cache is small , You don't need to restart pgpool-II Because the related tables have been updated .
Memory based cache save SELECT sentence ( And the parameters it binds , If SELECT Is an extended query ) And the corresponding data . If it's the same SELECT sentence , Then directly return the cached value . Because there are no more SQL Analysis or to PostgreSQL Call to , In fact, it will be very fast .
other aspects , It will be slower , Because it adds some load to the cache . in addition , When a table is updated ,pgpool Automatically delete the cache of related tables . therefore , In a system with many updates , Performance will be reduced . If cache_hit_ratio lower than 70%( You can query show pool_cache;), It is recommended that you turn off memory based caching .
Modify the parameters memory_cache_enabled=on The query cache function will be enabled . in addition , Need to set up memqcache_oiddir route , Create directory /var/log/pgpool/oiddir, And empowering .
vi /postgresql/pgpool/etc/pgpool.confmemory_cache_enabled = onmkdir -p /var/log/pgpool/oiddirchown -R pgsql.pgsql /var/log/pgpool/oiddir
When the configuration is complete , Restart pgpool service :
systemctl restart pgpool
Next , Test the cache function :
sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0(3 rows)[pgsql@lhrpgpool ~]$ for i in $(seq 1 50); do psql -U postgres -h 127.0.0.1 -p 9999 -d sbtest -c 'SELECT * from test'; done | egrep 'row' | wc -l50sbtest=# show pool_backend_stats; node_id | hostname | port | status | role | select_cnt | insert_cnt | update_cnt | delete_cnt | ddl_cnt | other_cnt | panic_cnt | fatal_cnt | error_cnt---------+------------+------+--------+---------+------------+------------+------------+------------+---------+-----------+-----------+-----------+----------- 0 | 172.72.6.2 | 5432 | up | primary | 0 | 0 | 0 | 0 | 0 | 50 | 0 | 0 | 0 1 | 172.72.6.3 | 5432 | up | standby | 0 | 0 | 0 | 0 | 0 | 22 | 0 | 0 | 0 2 | 172.72.6.4 | 5432 | up | standby | 1 | 0 | 0 | 0 | 0 | 28 | 0 | 0 | 0(3 rows)sbtest=# delete from test;DELETE 1sbtest=# select * from test; id----(0 rows)sbtest=# show pool_health_check_stats; node_id | hostname | port | status | role | last_status_change | total_count | success_count | fail_count | skip_count | retry_count | average_retry_count | max_retry_count | max_duration | min_duration | average_duration | last_health_check | last_successful_health_check | last_skip_health_check | last_failed_health_check---------+------------+------+--------+---------+---------------------+-------------+---------------+------------+------------+-------------+---------------------+-----------------+--------------+--------------+------------------+---------------------+------------------------------+------------------------+-------------------------- 0 | 172.72.6.2 | 5432 | up | primary | 2021-06-24 16:20:08 | 57 | 57 | 0 | 0 | 0 | 0.000000 | 0 | 8 | 7 | 7.035088 | 2021-06-24 16:29:29 | 2021-06-24 16:29:29 | | 1 | 172.72.6.3 | 5432 | up | standby | 2021-06-24 16:20:08 | 57 | 57 | 0 | 0 | 0 | 0.000000 | 0 | 7 | 7 | 7.000000 | 2021-06-24 16:29:29 | 2021-06-24 16:29:29 | | 2 | 172.72.6.4 | 5432 | up | standby | 2021-06-24 16:20:08 | 57 | 57 | 0 | 0 | 0 | 0.000000 | 0 | 8 | 7 | 7.017544 | 2021-06-24 16:29:29 | 2021-06-24 16:29:29 | |(3 rows)
You can see , I did 50 Time of SELECT * from test
, But in fact, only 1 strip (select_cnt), In fact, the data is obtained from the cache .
边栏推荐
猜你喜欢
Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄
阿里云易立:云原生如何破解企业降本提效难题?
Blackfly s usb3 industrial camera: buffer processing
Flir Blackfly S USB3 工业相机:白平衡设置方法
老板被隔离了
Blackfly S USB3工业相机:缓冲区处理
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
Integrated navigation: product description and interface description of zhonghaida inav2
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
随机推荐
Input and output of C language pointer to two-dimensional array
Word wrap when flex exceeds width
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
What to do when encountering slow SQL? (next)
go swagger使用
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
A new path for enterprise mid Platform Construction -- low code platform
Redis tool class redisutil (tool class III)
企业中台建设新路径——低代码平台
传感器:DS1302时钟芯片及驱动代码
Sensor: DS1302 clock chip and driver code
[server data recovery] data recovery case of a Dell server crash caused by raid damage
How can reinforcement learning be used in medical imaging? A review of Emory University's latest "reinforcement learning medical image analysis", which expounds the latest RL medical image analysis co
postgresql 之 数据目录内部结构 简介
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
3D激光SLAM:Livox激光雷达硬件时间同步
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
freeswitch拨打分机号源代码跟踪
[paper reading | deep reading] dngr:deep neural networks for learning graph representations