SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. 1
Setup a High-Availability and Load Balancing
PostgreSQL Cluster
- New Features of Pgpool-II 4.1 -
SRA OSS, Inc. Japan
Bo Peng
pengbo@sraoss.co.jp
PGConf.ASIA 2019, Bali
2019-09-10
2Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Who am I?
• Bo Peng
• Chinese National, based in Tokyo
• Organization: SRA OSS
• Experience in using PostgreSQL since 2015
• Current work
• Open source software technical support
• Monitoring software
• Clustering software
• Installation work
• Pgpool-II developer
• Chinese documentation translation
• Committer since Pgpool-II 3.5 (2015)
• Release management, bug fix, SQL parser
Outline
◼ High-Availability Database Cluster
◼ What is Pgpool-II?
⚫ Advantages of using Pgpool-II to setup HA cluster
◼ New features of Pgpool-II 4.1
⚫ Statement level load balancing
⚫ Automatic failback
⚫ Performance improvements
⚫ Improvements of internal queries issued by Pgpool-II
⚫ Import PostgreSQL 12 new parser
3Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
4Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Part 1
High-Availability Database Cluster
Database High-Availability Cluster
Why high-availability database cluster?
5Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Web Application
Primary
Standby
Standby
Write
Read
Read
Web Application
Primary
Standby
Replication
Web Application
Primary
New Primary
Replication
Failover
• Data redundancy
• If the primary server fails, other standby
server becomes the new primary quickly
• To ensure data is always available to
your application
• Eliminate downtime
High availability
• Multiple servers return the same data
• Distribute queries between multiple
servers
• Optimize resource utilization
Load balancing
PostgreSQL Streaming Replication Issues
◼ Automatic failover
⚫ PostgreSQL doesn't provide build-in automatic failover
feature
⚫ Promotion is not automated
⚫ The required configuration is complex
✓detect PostgreSQL failure
✓promote another standby server to the new primary
✓synchronize other standby nodes with the new master
◼ Load balancing
⚫ PostgreSQL doesn't provide load balancing feature
⚫ RAED/WRITE queries distribution logic is required in
application
6Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
HA management solutions for PostgreSQL
7Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Solutions
▪ Pacemaker/Corosync + DRBD
• Automatic failover
▪ Pgpool-II
• Automatic failover
• Load balancing
8Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Part 2
What is Pgpool-II?
About Pgpool-II
◼ Cluster management tool for PostgreSQL
⚫ Support for PostgreSQL 6.4 or later
⚫ OSS, BSD license
◼ Feature-rich
⚫ Automatic failover
⚫ Watchdog (High availability for Pgpool-II)
⚫ Load balancing
⚫ Online recovery
⚫ In memory query caching
⚫ Connection pooling
9Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Basic Idea of Pgpool-II
10Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Primary
Standby
Standby
WAL
WAL
Streaming
Replication
READ / WRITE
Queries READ
Automatic failover
11Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Primary
Standby
WAL
Streaming
Replication
READ / WRITE
queries promote
New Primary
1. Primary server fails
2. Pgpool-II detects PostgreSQL failure and triggers failover
• When health check fails
• When Read/Write fails on PostgreSQL backend
• By remote Pgpool-II node (Watchdog)
3. One of the standby servers gets promoted to the new primary
4. Other standby servers are made to follow the new primary
• Pgpool-II maintains the service availability even if
PostgreSQL server fails
• But what if Pgpool-II fails … Pgpool-II could be the
single point of failure (SPOF)
12Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Problem …
SPOF
SPOF Solution: Pgpool-II with Watchdog
13Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Heartbeat
SPOF Solution
• Pgpool-II Redundancy
• Use Watchdog to coordinate multiple Pgpool-II nodes
Watchdog
Watchdog
Watchdog
Pgpool-II with Watchdog
14Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Watchdog
• One of the Pgpool-II nodes is selected as master watchdog
• Synchronize the backend status across all Pgpool-II nodes
• Perform life checking on Pgpool-II nodes (heartbeat, query)
• Coordinate the selection of master/coordinator node to ensure the quorum in the cluster
• Coordinate failover/failback requests
• Automatic Virtual-IP switching
Watchdog
Heartbeat
Primary
WAL
WAL
Standby
Standby
Watchdog Watchdog
VIP
master
standby standby
SQL
Pgpool-II fails
15Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Watchdog
Heartbeat
Primary
WAL
WAL
Standby
Standby
Watchdog Watchdog
VIP
master standby
SQL
If master Pgpool-II node fails,
• Release VIP from old master Pgpool-II node
• Promote standby Pgpool-II node to the new master
• Assign VIP to the new master Pgpool-II node
• Ensure service availability and continuity
◼ Distribution of database workloads across multiple backend servers
⚫ Send READ queries to any backend server
⚫ Send WRITE queries to primary only
◼ Load balancing works best when a lot of users execute many read-only queries at the same time
◼ Load balancing node is selected at the beginning of a session (Default)
◼ Possible to select load balancing node per statement
(From Pgpool-II 4.1: statement_level_load_balance)
◼ Parameters related to load balancing:
⚫ white_function_list/black_function_list
⚫ black_query_pattern_list
⚫ database_redirect_preference_list
⚫ app_name_redirect_preference_list
⚫ etc.
Load Balancing
16Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Primary
Standby
Standby
WALWAL
Streaming
Replication
READ / WRITE
Queries
READ
Advantages of using Pgpool-II to setup HA Cluster
◼ Automatic failover
⚫ In case primary fails, standby can become the new primary automatically
◼ Load balancing
⚫ Distribute READ queries across PostgreSQL primary/standby servers to
distribute database load
◼ High availability for Pgpool-II
⚫ Use Watchdog to avoid Single Point of Failure (SPOF)
◼ Online recovery
⚫ Synchronize and attach PostgreSQL standby server
◼ In memory query caching
⚫ Allow to save a pair of SELECT statement and its result in cache
⚫ If an identical SELECT comes in, Pgpool-II fetches the result from cache
◼ Connection pooling
⚫ Maintain established connections to PostgreSQL so that the connections can
be reused whenever a new connection with the same properties
⚫ Reduce the connection overhead
17Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
18Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Part 3
What's New in Pgpool-II 4.1.
Pgpool-II 4.1 Major Features
• Statement level load balancing
• Automatic failback
• Performance enhance
▪ Shared relation cache
▪ Speed up the large INSERT and UPDATE statements
• Improvements of internal queries issued by Pgpool-II
• Modify temporary table checking method
• Reduce internal queries against system catalogs
• Routing relcache queries to load balance node
• Import PostgreSQL 12 new parser
19Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Statement Level Load Balancing
Session level load balancing
• The load balancing node is decided at the session start time
• The load balancing node will not be changed until the session ends
• Applications that use connection pooling remain connections open to the
backend server. Because the session may be held for a long time, the load
balancing node does not change until the session ends
Statement level load balancing
• Allow to select load balancing node per statement
• statement_level_load_balance = on
20Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
New in Pgpool-II 4.1
Automatic Failback
Until Pgpool-II 4.0
◼ If a standby node is removed from Pgpool-II due to a temporary network
problem, it will stay down status, even if the node has resumed replication
with primary server and is up to date
◼ Perform a manual failback (such as pcp_attach_node) or restart Pgpool-II
21Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Automatic Failback
◼ Long awaited feature
◼ Safe way to automatically attach "healthy" standby servers
◼ Use pg_stat_replication to check if the standby server is connected to primary
server
◼ If pg_stat_replication.state is "streaming" and node status is DOWN, then
attach the node
◼ PostgreSQL 9.1 or later is required
New in Pgpool-II 4.1
# pgpool.conf
auto_failback = on # enable auto failback
auto_failback_interval = 60 # perform failback in specified interval
22Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Performance Improvements (1)
Shared Relation Cache
Shared Relation Cache (1)
◼ Why relation cache for system catalogs?
⚫ Pgpool-II issues queries to PostgreSQL's system catalog, when a table or
function appears in client's query
✓ To determine whether a table in client's query is a temporary table or not
✓ To determine whether a table in client's query is an unlogged table or not
✓ To determine whether a function in client's query is "immutable" or not
⚫ Store the results in local relation cache
⚫ When the same object appears in the subsequent queries, Pgpool-II obtains
information from the local cache
23Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Local Relation Cache
SELECT … FROM t1
SELECT … FROM t1
t1
…
…
obtain information
from local cache asceses to system catalog and
store the results in local relation
cache
Primary
Shared Relation Cache(2)
24Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
◼ Problem in the existing relation cache
⚫ Pgpool-II child process stores the relation cache in private
memory
⚫ Other child process has to access system catalogs, even if same
table information is stored in other child process's local relation
cache
Shared Relation Cache
◼ Share the relation cache information among Pgpool-II child
processes
◼ Reduce accesses to PostgreSQL system catalogs
# pgpool.conf
enable_shared_relcache = on
New in Pgpool-II 4.1
Shared Relation Cache (3)
25Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
◼ Shared relation cache
1. If the table/function info is not found in the local relation cache, then Pgpool-II checks the
shared relation cache
2. If the table/function info is already in the shared relation cache, just copy the info to the
local cache
3. If it is not in the shared relation cache, Pgpool-II accesses the system catalogs and stores
the result in the local cache. Also copy the result to the shared relation cache
New in Pgpool-II 4.1
# pgpool.conf
enable_shared_relcache = on
Local Relation Cache
t1
Local Relation Cache
Shared Relation Cache
t1t1
t1?
t1 info
no table t1 info in local cache,
check the shared relation cache
copy table t1 info to the local cache
Shared Relation Cache (4)
26Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Benchmarking Results
1. Create 1, 10, 20, 30, 40, 50, 60, 70, 80, 90 and 100 tables
2. Access tables using pgbench
# pgpool.conf
enable_shared_relcache = on
# pgbench -C -T 30 -c 30 –p 9999 -n -f script_file.sql
0
0.5
1
1.5
2
2.5
3
3.5
1 10 20 30 40 50 60 70 80 90 100
SPEEDUP
NUMBER OF TABLES
PGBENCH RESULTS
enable_shared_relcache = off enable_shared_relcache = on
27Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Performance Improvements (2)
Speed Up the Large INSERT and UPDATE Statements
Speed Up the Large INSERT and UPDATE Statements
◼ Pgpool-II has imported PostgreSQL raw parser
◼ In master-slave mode, Pgpool-II only needs very little information to decide
where it needs to send the query, especially for the INSERT and UPDATE
statements
◼ However, the parser taken from PostgreSQL source parses the complete
query including the value lists
28Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
◼ Use two parsers
⚫ src/parser/gram.y : the standard parser taken from PostgreSQL source
⚫ src/parser/gram_minimal.y : the minimal parser
◼ Short circuit the INSERT and UPDATE statement parsing as soon as we
have the required information
New in Pgpool-II 4.1
Speed up the large INSERT and UPDATE statements
Test results for large binary INSERT
29Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
postgres=# ¥i sample.sql
id
—
1
(1 row)
INSERT 0 1
Time: 4218.450 ms
1. test with Pgpool-II 4.0
postgres=# ¥i sample.sql
id
—-
1
(1 row)
INSERT 0 1
Time: 1014.142 ms
2. test with PostgreSQL
postgres=# ¥i sample.sql
id
—
1
(1 row)
INSERT 0 1
Time: 1395.559 ms
3. test with Pgpool-II 4.1
3 times faster
# sample.sql 27MB
INSERT INTO "t1" ("content", "checksum")
VALUES
('¥x303030303 ... '::bytea, ...
30Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Improvements of Internal Queries Issued by Pgpool-II
• Modify Temporary Table Checking Method
• Reduce Internal Queries against System Catalogs
• Routing relcache Queries to Load Balance Node
Modify Temporary Table Checking Method
◼ Pgpool-II issues queries to PostgreSQL's system catalog, to determine whether a
table in client's query is a temporary table or not
◼ From Pgpool-II 4.1 the temporary table checking method is configurable
◼ new parameter: check_temp_table
⚫ catalog : existing method (catalog lookup, same as check_temp_table = on)
⚫ trace : Trace "CREATE TEMP TABLE/DROP TABLE"
⚫ none : no temp table checking (same as check_temp_table = off)
31Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
New in Pgpool-II 4.1
◼ Completely eliminate system catalog look up
◼ faster and able to reduce the load on the primary server
◼ Implementation
1. Trace CREATE TEMP TABLE. If new temp table is created (and committed), memorize it in a list.
2. To know whether it's temp table or not, search the list.
3. Trace DROP TABLE. If a table is dropped (and committed), remove the table from the list.
4. When a transaction aborts, remove tables from the list if any.
◼ Note : Impossible to trace inside functions or triggers
# pgpool.conf
check_temp_table = trace
Reduce internal queries against system catalogs
◼ Pgpool-II issues 7 queries or more to obtain various
information from PostgreSQL system catalogs
◼ Because Pgpool-II works with multiple version of PostgreSQL,
the queries below are issued to know if the object exists
⚫ Query to know if pg_namespace exists
⚫ Query to know if to_regclass exists
◼ Pgpool-II 4.1
⚫ Reduce such internal queries
⚫ Determine PostgreSQL version to know what kind of queries are
needed
32Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
SELECT count(*) from (SELECT has_function_privilege('pengbo', 'pg_catalog.to_regclass(cstring)', 'execute') WHERE ...
SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.relname = 'pg_namespace'
SELECT count(*) FROM pg_class AS c, pg_namespace AS n WHERE c.oid = pg_catalog.to_regclass('"t1"') AND c.relnamespace = ...
SELECT count(*) FROM pg_catalog.pg_class AS c, pg_attribute AS a WHERE c.relname = 'pg_class' AND a.attrelid = c.oid ...
SELECT count(*) FROM pg_catalog.pg_class AS c, pg_namespace AS n WHERE c.relname = 't1' AND c.relnamespace = n.oid AND ...
SELECT count(*) FROM pg_catalog.pg_class AS c, pg_catalog.pg_attribute AS a WHERE c.relname = 'pg_class' AND a.attrelid ...
SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.oid = pg_catalog.to_regclass('"t1"') AND c.relpersistence = 'u' ...
New in Pgpool-II 4.1
Routing relcache Queries to Load Balance Node (1)
◼ Until 4.0, Pgpool-II issues relcache related queries to primary server
◼ Pgpool-II 4.1 allows to send relcache related queries against standby
server, rather than primary server
◼ relcache_query_target = master/load_balance_node
⚫ load_balance_node : relcache queries will be routed to load balance node
⚫ master : relcache queries will be routed to master node
◼ Note: if you send query to the standby node, recently created tables and
rows might not be available on the standby server yet because of
replication delay. To get the latest information, the default value master is
recommended
◼ Setting to load_balance_node is especially useful for such a system
where primary PostgreSQL server is geographically distant
33Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
# pgpool.conf
relcache_query_target = master/load_balance_node
Routing relcache Queries to Load Balance Node (2)
34Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
# pgpool.conf
relcache_query_target = load_balance_node
backend_weight0 = 0
Pgpool-II 4.0 Pgpool-II 4.1
Import PostgreSQL 12 New Parser
◼ Pgpool-II has SQL parser
⚫ To accurately parse the SQLs
⚫ To rewrite the query
◼ In every major release, we import the latest version of
PostgreSQL's SQL parser to Pgpool-II
◼ Import PostgreSQL 12 parser to Pgpool-II 4.1
⚫ Add new VACUUM options: SKIP_LOCKED, INDEX_CLEANUP and TRUNCATE
⚫ Add COMMIT AND CHAIN and ROLLBACK AND CHAIN commands
⚫ Add a WHERE clause to COPY FROM
⚫ Allow to use CREATE OR REPLACE AGGREGATE command
⚫ Allow to use mcv (most-common-value) in CREATE STATISTICS
⚫ ADD REINDEX option CONCURRENTLY
⚫ Add EXPLAIN option SETTINGS
35Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Future Work
◼ Make Pgpool-II more user-friendly
⚫ Easy to configure
⚫ Enhance documentation
◼ Improve regression test
◼ Implementation the logger process
36Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Summary
◼ High-Availability database cluster
◼ Advantages of using Pgpool-II to setup HA cluster
⚫ Automatic failover
⚫ Load balancing
⚫ Online recovery
⚫ Watchdog
◼ New Features of Pgpool-II 4.1
⚫ Statement level load balancing
⚫ Automatic failback
⚫ Performance improvements
⚫ Improvements of internal queries issued by Pgpool-II
⚫ Import PostgreSQL 12 new parser
37Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Links
◼ Wiki
⚫ https://pgpool.net/mediawiki/index.php/Main_Page
◼ Documentation
⚫ http://www.pgpool.net/docs/latest/en/html/
◼ Repository
⚫ https://git.postgresql.org/gitweb/?p=pgpool2.git;a=summary
◼ ML
⚫ https://pgpool.net/mediawiki/index.php/Mailing_lists
◼ Bug report
⚫ https://www.pgpool.net/mantisbt/
38Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Welcome Volunteers!
Please join Pgpool-II development community!
39Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
Thank you!
Terima Kasih!

Contenu connexe

Tendances

pgpool-II demonstration
pgpool-II demonstrationpgpool-II demonstration
pgpool-II demonstration
elliando dias
 

Tendances (20)

PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
NGINX Installation and Tuning
NGINX Installation and TuningNGINX Installation and Tuning
NGINX Installation and Tuning
 
The Current State of Table API in 2022
The Current State of Table API in 2022The Current State of Table API in 2022
The Current State of Table API in 2022
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Introducing Apache Airflow and how we are using it
Introducing Apache Airflow and how we are using itIntroducing Apache Airflow and how we are using it
Introducing Apache Airflow and how we are using it
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
 
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
 
Apache Airflow Architecture
Apache Airflow ArchitectureApache Airflow Architecture
Apache Airflow Architecture
 
Data Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UI
Data Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UIData Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UI
Data Warehouses in Kubernetes Visualized: the ClickHouse Kubernetes Operator UI
 
Apache Airflow
Apache AirflowApache Airflow
Apache Airflow
 
High Availability and Disaster Recovery in PostgreSQL - EQUNIX
High Availability and Disaster Recovery in PostgreSQL - EQUNIXHigh Availability and Disaster Recovery in PostgreSQL - EQUNIX
High Availability and Disaster Recovery in PostgreSQL - EQUNIX
 
Apache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native EraApache Flink in the Cloud-Native Era
Apache Flink in the Cloud-Native Era
 
Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security Achieving compliance With MongoDB Security
Achieving compliance With MongoDB Security
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in Flink
 
pgpool-II demonstration
pgpool-II demonstrationpgpool-II demonstration
pgpool-II demonstration
 
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
[135] 오픈소스 데이터베이스, 은행 서비스에 첫발을 내밀다.
 
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
 
NGINX: Basics and Best Practices
NGINX: Basics and Best PracticesNGINX: Basics and Best Practices
NGINX: Basics and Best Practices
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
Using the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production DeploymentUsing the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production Deployment
 

Similaire à PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreSQL Cluster - Bo Peng

The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
Geir Høydalsvik
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
Dave Stokes
 

Similaire à PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreSQL Cluster - Bo Peng (20)

Oracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret InternalsOracle RAC 19c: Best Practices and Secret Internals
Oracle RAC 19c: Best Practices and Secret Internals
 
Running Stateful Apps on Kubernetes
Running Stateful Apps on KubernetesRunning Stateful Apps on Kubernetes
Running Stateful Apps on Kubernetes
 
Postgres Point-in-Time Recovery
Postgres Point-in-Time RecoveryPostgres Point-in-Time Recovery
Postgres Point-in-Time Recovery
 
Why oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cWhy oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19c
 
less08.ppt
less08.pptless08.ppt
less08.ppt
 
Key considerations in productionizing streaming applications
Key considerations in productionizing streaming applicationsKey considerations in productionizing streaming applications
Key considerations in productionizing streaming applications
 
Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7
 
200850 oracle primavera p6 eppm performance tuning, testing, and monitoring
200850 oracle primavera p6 eppm performance tuning, testing, and monitoring200850 oracle primavera p6 eppm performance tuning, testing, and monitoring
200850 oracle primavera p6 eppm performance tuning, testing, and monitoring
 
PGConf.ASIA 2019 Bali - How did PostgreSQL Write Load Balancing of Queries Us...
PGConf.ASIA 2019 Bali - How did PostgreSQL Write Load Balancing of Queries Us...PGConf.ASIA 2019 Bali - How did PostgreSQL Write Load Balancing of Queries Us...
PGConf.ASIA 2019 Bali - How did PostgreSQL Write Load Balancing of Queries Us...
 
Pivotal Cloud Foundry 2.6: A First Look
Pivotal Cloud Foundry 2.6: A First LookPivotal Cloud Foundry 2.6: A First Look
Pivotal Cloud Foundry 2.6: A First Look
 
My sql cluster case study apr16
My sql cluster case study apr16My sql cluster case study apr16
My sql cluster case study apr16
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
How to use postgresql.conf to configure and tune the PostgreSQL server
How to use postgresql.conf to configure and tune the PostgreSQL serverHow to use postgresql.conf to configure and tune the PostgreSQL server
How to use postgresql.conf to configure and tune the PostgreSQL server
 
Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
OpenDataPlane Project
OpenDataPlane ProjectOpenDataPlane Project
OpenDataPlane Project
 
Die pacman nomaden opnfv summit 2016 berlin
Die pacman nomaden opnfv summit 2016 berlinDie pacman nomaden opnfv summit 2016 berlin
Die pacman nomaden opnfv summit 2016 berlin
 
MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014MySQL 5.7 -- SCaLE Feb 2014
MySQL 5.7 -- SCaLE Feb 2014
 
CI/CD Pipeline to Deploy and Maintain an OpenStack IaaS Cloud
CI/CD Pipeline to Deploy and Maintain an OpenStack IaaS CloudCI/CD Pipeline to Deploy and Maintain an OpenStack IaaS Cloud
CI/CD Pipeline to Deploy and Maintain an OpenStack IaaS Cloud
 

Plus de Equnix Business Solutions

Plus de Equnix Business Solutions (20)

Yang perlu kita ketahui Untuk memahami aspek utama IT dalam bisnis_.pdf
Yang perlu kita ketahui Untuk memahami aspek utama IT dalam bisnis_.pdfYang perlu kita ketahui Untuk memahami aspek utama IT dalam bisnis_.pdf
Yang perlu kita ketahui Untuk memahami aspek utama IT dalam bisnis_.pdf
 
Kebocoran Data_ Tindakan Hacker atau Kriminal_ Bagaimana kita mengantisipasi...
Kebocoran Data_  Tindakan Hacker atau Kriminal_ Bagaimana kita mengantisipasi...Kebocoran Data_  Tindakan Hacker atau Kriminal_ Bagaimana kita mengantisipasi...
Kebocoran Data_ Tindakan Hacker atau Kriminal_ Bagaimana kita mengantisipasi...
 
Kuliah Tamu - Dari Proses Bisnis Menuju Struktur Data.pdf
Kuliah Tamu - Dari Proses Bisnis Menuju Struktur Data.pdfKuliah Tamu - Dari Proses Bisnis Menuju Struktur Data.pdf
Kuliah Tamu - Dari Proses Bisnis Menuju Struktur Data.pdf
 
EWTT22_ Apakah Open Source Cocok digunakan dalam Korporasi_.pdf
EWTT22_ Apakah Open Source Cocok digunakan dalam Korporasi_.pdfEWTT22_ Apakah Open Source Cocok digunakan dalam Korporasi_.pdf
EWTT22_ Apakah Open Source Cocok digunakan dalam Korporasi_.pdf
 
Oracle to PostgreSQL, Challenges to Opportunity.pdf
Oracle to PostgreSQL, Challenges to Opportunity.pdfOracle to PostgreSQL, Challenges to Opportunity.pdf
Oracle to PostgreSQL, Challenges to Opportunity.pdf
 
[EWTT2022] Strategi Implementasi Database dalam Microservice Architecture.pdf
[EWTT2022] Strategi Implementasi Database dalam Microservice Architecture.pdf[EWTT2022] Strategi Implementasi Database dalam Microservice Architecture.pdf
[EWTT2022] Strategi Implementasi Database dalam Microservice Architecture.pdf
 
PostgreSQL as Enterprise Solution v1.1.pdf
PostgreSQL as Enterprise Solution v1.1.pdfPostgreSQL as Enterprise Solution v1.1.pdf
PostgreSQL as Enterprise Solution v1.1.pdf
 
Webinar2021 - Does HA Can Help You Balance Your Load-.pdf
Webinar2021 - Does HA Can Help You Balance Your Load-.pdfWebinar2021 - Does HA Can Help You Balance Your Load-.pdf
Webinar2021 - Does HA Can Help You Balance Your Load-.pdf
 
Webinar2021 - In-Memory Database, is it really faster-.pdf
Webinar2021 - In-Memory Database, is it really faster-.pdfWebinar2021 - In-Memory Database, is it really faster-.pdf
Webinar2021 - In-Memory Database, is it really faster-.pdf
 
EQUNIX - PPT 11DB-Postgres™.pdf
EQUNIX - PPT 11DB-Postgres™.pdfEQUNIX - PPT 11DB-Postgres™.pdf
EQUNIX - PPT 11DB-Postgres™.pdf
 
equpos - General Presentation v20230420.pptx
equpos - General Presentation v20230420.pptxequpos - General Presentation v20230420.pptx
equpos - General Presentation v20230420.pptx
 
Equnix Appliance- Jawaban terbaik untuk kebutuhan komputasi yang mumpuni.pdf
Equnix Appliance- Jawaban terbaik untuk kebutuhan komputasi yang mumpuni.pdfEqunix Appliance- Jawaban terbaik untuk kebutuhan komputasi yang mumpuni.pdf
Equnix Appliance- Jawaban terbaik untuk kebutuhan komputasi yang mumpuni.pdf
 
OSPX - Professional PostgreSQL Certification Scheme v20201111.pdf
OSPX - Professional PostgreSQL Certification Scheme v20201111.pdfOSPX - Professional PostgreSQL Certification Scheme v20201111.pdf
OSPX - Professional PostgreSQL Certification Scheme v20201111.pdf
 
Equnix Company Profile v20230329.pdf
Equnix Company Profile v20230329.pdfEqunix Company Profile v20230329.pdf
Equnix Company Profile v20230329.pdf
 
PGConf.ASIA 2019 - The Future of TDEforPG - Taiki Kondo
PGConf.ASIA 2019 - The Future of TDEforPG - Taiki KondoPGConf.ASIA 2019 - The Future of TDEforPG - Taiki Kondo
PGConf.ASIA 2019 - The Future of TDEforPG - Taiki Kondo
 
PGConf.ASIA 2019 - PGSpider High Performance Cluster Engine - Shigeo Hirose
PGConf.ASIA 2019 - PGSpider High Performance Cluster Engine - Shigeo HirosePGConf.ASIA 2019 - PGSpider High Performance Cluster Engine - Shigeo Hirose
PGConf.ASIA 2019 - PGSpider High Performance Cluster Engine - Shigeo Hirose
 
PGConf.ASIA 2019 - High Availability, 10 Seconds Failover - Lucky Haryadi
PGConf.ASIA 2019 - High Availability, 10 Seconds Failover - Lucky HaryadiPGConf.ASIA 2019 - High Availability, 10 Seconds Failover - Lucky Haryadi
PGConf.ASIA 2019 - High Availability, 10 Seconds Failover - Lucky Haryadi
 
PGConf.ASIA 2019 Bali - Mission Critical Production High Availability Postgre...
PGConf.ASIA 2019 Bali - Mission Critical Production High Availability Postgre...PGConf.ASIA 2019 Bali - Mission Critical Production High Availability Postgre...
PGConf.ASIA 2019 Bali - Mission Critical Production High Availability Postgre...
 
PGConf.ASIA 2019 Bali - Keynote Speech 3 - Kohei KaiGai
PGConf.ASIA 2019 Bali - Keynote Speech 3 - Kohei KaiGaiPGConf.ASIA 2019 Bali - Keynote Speech 3 - Kohei KaiGai
PGConf.ASIA 2019 Bali - Keynote Speech 3 - Kohei KaiGai
 
PGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan Pachenko
PGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan PachenkoPGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan Pachenko
PGConf.ASIA 2019 Bali - Keynote Speech 2 - Ivan Pachenko
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

PGConf.ASIA 2019 Bali - Setup a High-Availability and Load Balancing PostgreSQL Cluster - Bo Peng

  • 1. Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. 1 Setup a High-Availability and Load Balancing PostgreSQL Cluster - New Features of Pgpool-II 4.1 - SRA OSS, Inc. Japan Bo Peng pengbo@sraoss.co.jp PGConf.ASIA 2019, Bali 2019-09-10
  • 2. 2Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Who am I? • Bo Peng • Chinese National, based in Tokyo • Organization: SRA OSS • Experience in using PostgreSQL since 2015 • Current work • Open source software technical support • Monitoring software • Clustering software • Installation work • Pgpool-II developer • Chinese documentation translation • Committer since Pgpool-II 3.5 (2015) • Release management, bug fix, SQL parser
  • 3. Outline ◼ High-Availability Database Cluster ◼ What is Pgpool-II? ⚫ Advantages of using Pgpool-II to setup HA cluster ◼ New features of Pgpool-II 4.1 ⚫ Statement level load balancing ⚫ Automatic failback ⚫ Performance improvements ⚫ Improvements of internal queries issued by Pgpool-II ⚫ Import PostgreSQL 12 new parser 3Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 4. 4Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Part 1 High-Availability Database Cluster
  • 5. Database High-Availability Cluster Why high-availability database cluster? 5Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Web Application Primary Standby Standby Write Read Read Web Application Primary Standby Replication Web Application Primary New Primary Replication Failover • Data redundancy • If the primary server fails, other standby server becomes the new primary quickly • To ensure data is always available to your application • Eliminate downtime High availability • Multiple servers return the same data • Distribute queries between multiple servers • Optimize resource utilization Load balancing
  • 6. PostgreSQL Streaming Replication Issues ◼ Automatic failover ⚫ PostgreSQL doesn't provide build-in automatic failover feature ⚫ Promotion is not automated ⚫ The required configuration is complex ✓detect PostgreSQL failure ✓promote another standby server to the new primary ✓synchronize other standby nodes with the new master ◼ Load balancing ⚫ PostgreSQL doesn't provide load balancing feature ⚫ RAED/WRITE queries distribution logic is required in application 6Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 7. HA management solutions for PostgreSQL 7Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Solutions ▪ Pacemaker/Corosync + DRBD • Automatic failover ▪ Pgpool-II • Automatic failover • Load balancing
  • 8. 8Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Part 2 What is Pgpool-II?
  • 9. About Pgpool-II ◼ Cluster management tool for PostgreSQL ⚫ Support for PostgreSQL 6.4 or later ⚫ OSS, BSD license ◼ Feature-rich ⚫ Automatic failover ⚫ Watchdog (High availability for Pgpool-II) ⚫ Load balancing ⚫ Online recovery ⚫ In memory query caching ⚫ Connection pooling 9Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 10. Basic Idea of Pgpool-II 10Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Primary Standby Standby WAL WAL Streaming Replication READ / WRITE Queries READ
  • 11. Automatic failover 11Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Primary Standby WAL Streaming Replication READ / WRITE queries promote New Primary 1. Primary server fails 2. Pgpool-II detects PostgreSQL failure and triggers failover • When health check fails • When Read/Write fails on PostgreSQL backend • By remote Pgpool-II node (Watchdog) 3. One of the standby servers gets promoted to the new primary 4. Other standby servers are made to follow the new primary
  • 12. • Pgpool-II maintains the service availability even if PostgreSQL server fails • But what if Pgpool-II fails … Pgpool-II could be the single point of failure (SPOF) 12Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Problem … SPOF
  • 13. SPOF Solution: Pgpool-II with Watchdog 13Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Heartbeat SPOF Solution • Pgpool-II Redundancy • Use Watchdog to coordinate multiple Pgpool-II nodes Watchdog Watchdog Watchdog
  • 14. Pgpool-II with Watchdog 14Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Watchdog • One of the Pgpool-II nodes is selected as master watchdog • Synchronize the backend status across all Pgpool-II nodes • Perform life checking on Pgpool-II nodes (heartbeat, query) • Coordinate the selection of master/coordinator node to ensure the quorum in the cluster • Coordinate failover/failback requests • Automatic Virtual-IP switching Watchdog Heartbeat Primary WAL WAL Standby Standby Watchdog Watchdog VIP master standby standby SQL
  • 15. Pgpool-II fails 15Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Watchdog Heartbeat Primary WAL WAL Standby Standby Watchdog Watchdog VIP master standby SQL If master Pgpool-II node fails, • Release VIP from old master Pgpool-II node • Promote standby Pgpool-II node to the new master • Assign VIP to the new master Pgpool-II node • Ensure service availability and continuity
  • 16. ◼ Distribution of database workloads across multiple backend servers ⚫ Send READ queries to any backend server ⚫ Send WRITE queries to primary only ◼ Load balancing works best when a lot of users execute many read-only queries at the same time ◼ Load balancing node is selected at the beginning of a session (Default) ◼ Possible to select load balancing node per statement (From Pgpool-II 4.1: statement_level_load_balance) ◼ Parameters related to load balancing: ⚫ white_function_list/black_function_list ⚫ black_query_pattern_list ⚫ database_redirect_preference_list ⚫ app_name_redirect_preference_list ⚫ etc. Load Balancing 16Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Primary Standby Standby WALWAL Streaming Replication READ / WRITE Queries READ
  • 17. Advantages of using Pgpool-II to setup HA Cluster ◼ Automatic failover ⚫ In case primary fails, standby can become the new primary automatically ◼ Load balancing ⚫ Distribute READ queries across PostgreSQL primary/standby servers to distribute database load ◼ High availability for Pgpool-II ⚫ Use Watchdog to avoid Single Point of Failure (SPOF) ◼ Online recovery ⚫ Synchronize and attach PostgreSQL standby server ◼ In memory query caching ⚫ Allow to save a pair of SELECT statement and its result in cache ⚫ If an identical SELECT comes in, Pgpool-II fetches the result from cache ◼ Connection pooling ⚫ Maintain established connections to PostgreSQL so that the connections can be reused whenever a new connection with the same properties ⚫ Reduce the connection overhead 17Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 18. 18Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Part 3 What's New in Pgpool-II 4.1.
  • 19. Pgpool-II 4.1 Major Features • Statement level load balancing • Automatic failback • Performance enhance ▪ Shared relation cache ▪ Speed up the large INSERT and UPDATE statements • Improvements of internal queries issued by Pgpool-II • Modify temporary table checking method • Reduce internal queries against system catalogs • Routing relcache queries to load balance node • Import PostgreSQL 12 new parser 19Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 20. Statement Level Load Balancing Session level load balancing • The load balancing node is decided at the session start time • The load balancing node will not be changed until the session ends • Applications that use connection pooling remain connections open to the backend server. Because the session may be held for a long time, the load balancing node does not change until the session ends Statement level load balancing • Allow to select load balancing node per statement • statement_level_load_balance = on 20Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. New in Pgpool-II 4.1
  • 21. Automatic Failback Until Pgpool-II 4.0 ◼ If a standby node is removed from Pgpool-II due to a temporary network problem, it will stay down status, even if the node has resumed replication with primary server and is up to date ◼ Perform a manual failback (such as pcp_attach_node) or restart Pgpool-II 21Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Automatic Failback ◼ Long awaited feature ◼ Safe way to automatically attach "healthy" standby servers ◼ Use pg_stat_replication to check if the standby server is connected to primary server ◼ If pg_stat_replication.state is "streaming" and node status is DOWN, then attach the node ◼ PostgreSQL 9.1 or later is required New in Pgpool-II 4.1 # pgpool.conf auto_failback = on # enable auto failback auto_failback_interval = 60 # perform failback in specified interval
  • 22. 22Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Performance Improvements (1) Shared Relation Cache
  • 23. Shared Relation Cache (1) ◼ Why relation cache for system catalogs? ⚫ Pgpool-II issues queries to PostgreSQL's system catalog, when a table or function appears in client's query ✓ To determine whether a table in client's query is a temporary table or not ✓ To determine whether a table in client's query is an unlogged table or not ✓ To determine whether a function in client's query is "immutable" or not ⚫ Store the results in local relation cache ⚫ When the same object appears in the subsequent queries, Pgpool-II obtains information from the local cache 23Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Local Relation Cache SELECT … FROM t1 SELECT … FROM t1 t1 … … obtain information from local cache asceses to system catalog and store the results in local relation cache Primary
  • 24. Shared Relation Cache(2) 24Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. ◼ Problem in the existing relation cache ⚫ Pgpool-II child process stores the relation cache in private memory ⚫ Other child process has to access system catalogs, even if same table information is stored in other child process's local relation cache Shared Relation Cache ◼ Share the relation cache information among Pgpool-II child processes ◼ Reduce accesses to PostgreSQL system catalogs # pgpool.conf enable_shared_relcache = on New in Pgpool-II 4.1
  • 25. Shared Relation Cache (3) 25Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. ◼ Shared relation cache 1. If the table/function info is not found in the local relation cache, then Pgpool-II checks the shared relation cache 2. If the table/function info is already in the shared relation cache, just copy the info to the local cache 3. If it is not in the shared relation cache, Pgpool-II accesses the system catalogs and stores the result in the local cache. Also copy the result to the shared relation cache New in Pgpool-II 4.1 # pgpool.conf enable_shared_relcache = on Local Relation Cache t1 Local Relation Cache Shared Relation Cache t1t1 t1? t1 info no table t1 info in local cache, check the shared relation cache copy table t1 info to the local cache
  • 26. Shared Relation Cache (4) 26Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Benchmarking Results 1. Create 1, 10, 20, 30, 40, 50, 60, 70, 80, 90 and 100 tables 2. Access tables using pgbench # pgpool.conf enable_shared_relcache = on # pgbench -C -T 30 -c 30 –p 9999 -n -f script_file.sql 0 0.5 1 1.5 2 2.5 3 3.5 1 10 20 30 40 50 60 70 80 90 100 SPEEDUP NUMBER OF TABLES PGBENCH RESULTS enable_shared_relcache = off enable_shared_relcache = on
  • 27. 27Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Performance Improvements (2) Speed Up the Large INSERT and UPDATE Statements
  • 28. Speed Up the Large INSERT and UPDATE Statements ◼ Pgpool-II has imported PostgreSQL raw parser ◼ In master-slave mode, Pgpool-II only needs very little information to decide where it needs to send the query, especially for the INSERT and UPDATE statements ◼ However, the parser taken from PostgreSQL source parses the complete query including the value lists 28Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. ◼ Use two parsers ⚫ src/parser/gram.y : the standard parser taken from PostgreSQL source ⚫ src/parser/gram_minimal.y : the minimal parser ◼ Short circuit the INSERT and UPDATE statement parsing as soon as we have the required information New in Pgpool-II 4.1
  • 29. Speed up the large INSERT and UPDATE statements Test results for large binary INSERT 29Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. postgres=# ¥i sample.sql id — 1 (1 row) INSERT 0 1 Time: 4218.450 ms 1. test with Pgpool-II 4.0 postgres=# ¥i sample.sql id —- 1 (1 row) INSERT 0 1 Time: 1014.142 ms 2. test with PostgreSQL postgres=# ¥i sample.sql id — 1 (1 row) INSERT 0 1 Time: 1395.559 ms 3. test with Pgpool-II 4.1 3 times faster # sample.sql 27MB INSERT INTO "t1" ("content", "checksum") VALUES ('¥x303030303 ... '::bytea, ...
  • 30. 30Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Improvements of Internal Queries Issued by Pgpool-II • Modify Temporary Table Checking Method • Reduce Internal Queries against System Catalogs • Routing relcache Queries to Load Balance Node
  • 31. Modify Temporary Table Checking Method ◼ Pgpool-II issues queries to PostgreSQL's system catalog, to determine whether a table in client's query is a temporary table or not ◼ From Pgpool-II 4.1 the temporary table checking method is configurable ◼ new parameter: check_temp_table ⚫ catalog : existing method (catalog lookup, same as check_temp_table = on) ⚫ trace : Trace "CREATE TEMP TABLE/DROP TABLE" ⚫ none : no temp table checking (same as check_temp_table = off) 31Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. New in Pgpool-II 4.1 ◼ Completely eliminate system catalog look up ◼ faster and able to reduce the load on the primary server ◼ Implementation 1. Trace CREATE TEMP TABLE. If new temp table is created (and committed), memorize it in a list. 2. To know whether it's temp table or not, search the list. 3. Trace DROP TABLE. If a table is dropped (and committed), remove the table from the list. 4. When a transaction aborts, remove tables from the list if any. ◼ Note : Impossible to trace inside functions or triggers # pgpool.conf check_temp_table = trace
  • 32. Reduce internal queries against system catalogs ◼ Pgpool-II issues 7 queries or more to obtain various information from PostgreSQL system catalogs ◼ Because Pgpool-II works with multiple version of PostgreSQL, the queries below are issued to know if the object exists ⚫ Query to know if pg_namespace exists ⚫ Query to know if to_regclass exists ◼ Pgpool-II 4.1 ⚫ Reduce such internal queries ⚫ Determine PostgreSQL version to know what kind of queries are needed 32Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. SELECT count(*) from (SELECT has_function_privilege('pengbo', 'pg_catalog.to_regclass(cstring)', 'execute') WHERE ... SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.relname = 'pg_namespace' SELECT count(*) FROM pg_class AS c, pg_namespace AS n WHERE c.oid = pg_catalog.to_regclass('"t1"') AND c.relnamespace = ... SELECT count(*) FROM pg_catalog.pg_class AS c, pg_attribute AS a WHERE c.relname = 'pg_class' AND a.attrelid = c.oid ... SELECT count(*) FROM pg_catalog.pg_class AS c, pg_namespace AS n WHERE c.relname = 't1' AND c.relnamespace = n.oid AND ... SELECT count(*) FROM pg_catalog.pg_class AS c, pg_catalog.pg_attribute AS a WHERE c.relname = 'pg_class' AND a.attrelid ... SELECT count(*) FROM pg_catalog.pg_class AS c WHERE c.oid = pg_catalog.to_regclass('"t1"') AND c.relpersistence = 'u' ... New in Pgpool-II 4.1
  • 33. Routing relcache Queries to Load Balance Node (1) ◼ Until 4.0, Pgpool-II issues relcache related queries to primary server ◼ Pgpool-II 4.1 allows to send relcache related queries against standby server, rather than primary server ◼ relcache_query_target = master/load_balance_node ⚫ load_balance_node : relcache queries will be routed to load balance node ⚫ master : relcache queries will be routed to master node ◼ Note: if you send query to the standby node, recently created tables and rows might not be available on the standby server yet because of replication delay. To get the latest information, the default value master is recommended ◼ Setting to load_balance_node is especially useful for such a system where primary PostgreSQL server is geographically distant 33Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. # pgpool.conf relcache_query_target = master/load_balance_node
  • 34. Routing relcache Queries to Load Balance Node (2) 34Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. # pgpool.conf relcache_query_target = load_balance_node backend_weight0 = 0 Pgpool-II 4.0 Pgpool-II 4.1
  • 35. Import PostgreSQL 12 New Parser ◼ Pgpool-II has SQL parser ⚫ To accurately parse the SQLs ⚫ To rewrite the query ◼ In every major release, we import the latest version of PostgreSQL's SQL parser to Pgpool-II ◼ Import PostgreSQL 12 parser to Pgpool-II 4.1 ⚫ Add new VACUUM options: SKIP_LOCKED, INDEX_CLEANUP and TRUNCATE ⚫ Add COMMIT AND CHAIN and ROLLBACK AND CHAIN commands ⚫ Add a WHERE clause to COPY FROM ⚫ Allow to use CREATE OR REPLACE AGGREGATE command ⚫ Allow to use mcv (most-common-value) in CREATE STATISTICS ⚫ ADD REINDEX option CONCURRENTLY ⚫ Add EXPLAIN option SETTINGS 35Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 36. Future Work ◼ Make Pgpool-II more user-friendly ⚫ Easy to configure ⚫ Enhance documentation ◼ Improve regression test ◼ Implementation the logger process 36Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 37. Summary ◼ High-Availability database cluster ◼ Advantages of using Pgpool-II to setup HA cluster ⚫ Automatic failover ⚫ Load balancing ⚫ Online recovery ⚫ Watchdog ◼ New Features of Pgpool-II 4.1 ⚫ Statement level load balancing ⚫ Automatic failback ⚫ Performance improvements ⚫ Improvements of internal queries issued by Pgpool-II ⚫ Import PostgreSQL 12 new parser 37Copyright © 2019 SRA OSS, Inc. Japan All rights reserved.
  • 38. Links ◼ Wiki ⚫ https://pgpool.net/mediawiki/index.php/Main_Page ◼ Documentation ⚫ http://www.pgpool.net/docs/latest/en/html/ ◼ Repository ⚫ https://git.postgresql.org/gitweb/?p=pgpool2.git;a=summary ◼ ML ⚫ https://pgpool.net/mediawiki/index.php/Mailing_lists ◼ Bug report ⚫ https://www.pgpool.net/mantisbt/ 38Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Welcome Volunteers! Please join Pgpool-II development community!
  • 39. 39Copyright © 2019 SRA OSS, Inc. Japan All rights reserved. Thank you! Terima Kasih!