Online upgrade using
logical replication
Florin Irion
8 December 2020
#postgresbuild2020
Whoami?
florin.irion@enterprisedb.com
@irionr
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.3
Agenda
• PostgreSQL releases
• Upgrade options
• What is Pglogical
• Major upgrades
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.4
Why
Upgrade? ● Security
● Features
● Dba/management
● Performance
● SQL standard
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.5
Release
Cadence
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.6
EOL
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.7
About
Minor
Updates
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.8
About
Major
Upgrades
● Logical dump/restore
● Trigger-based replication (not anymore) - e.g.
Londiste
● pg_upgrade
● Native logical streaming replication
○ publisher/subscriber
○ Pglogical extension
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.9
About
Major
Upgrades
● Logical dump/restore
● Trigger-based replication (not anymore) - e.g.
Londiste
● pg_upgrade
● Native logical streaming replication
○ publisher/subscriber
○ Pglogical extension
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.10
Pglogical
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.11
Pglogical
vs
Logical
Replication
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.12
Upgrading
with
pglogical
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.13
What are we
missing by
using
PostgreSQL 9.5?
https://why-upgrade.depesz.com/
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.14
Missing
Features
● Parallel Aggregates
● Parallel sequential scans
● Declarative partitioning
● SCRAM Authentication
● Just In Time (JIT) compilation
● Parallel creation of index
● Stored Procedures
● Reindex concurrently
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.15
Nomenclature
and
conventions
● Node -- Postgresql database instance
● Provider -- sending node
● Subscriber -- receiver node
● Replication Set -- rule
● Subscription -- one subscriber makes to the
provider.
● pg95 pg13 -- my hostnames
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.16
Requirements
● Primary key
● Table schema
● Table definition
● Constraints
● Global objects
● UNLOGGED and TEMPORARY
● DDL
○ replicate_ddl_command()
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.17
Installation
PostgreSQL 9.5: yum install postgresql95-pglogical
PostgreSQL 13: yum install postgresql13-pglogical
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.18
Configuration Postgresql.conf
shared_preload_libraries = 'pglogical'
wal_level = 'logical'
max_worker_processes = 10
max_wal_senders = 10
max_replication_slots = 10
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.19
Pg_hba.conf
Local replication pglogical md5
Local dbname pglogical md5
Host replication pglogical pg13_ip_add/0 md5
Host dbname pglogical pg13_ip_add/0 md5
Authentication
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.20
Create
extension
and nodes
CREATE EXTENSION pglogical;
SELECT pglogical.create_node (
node_name: = 'provider1',
dsn: = 'host = pg95 port = 5432 dbname = db'
);
CREATE EXTENSION pglogical;
SELECT pglogical.create_node (
node_name: = 'subscriber1',
dsn: = 'host = pg13 port = 5432 dbname = db'
);
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.21
Add tables
and
sequences
SELECT pglogical.replication_set_add_all_tables (
set_name := 'default',
schema_names := ARRAY ['public']
);
SELECT pglogical.replication_set_add_all_sequences
(
set_name : = 'default',
schema_names : = ARRAY ['public']
);
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.22
Create
subscription
SELECT pglogical.create_subscription(
subscription_name := 'my_subscription',
provider_dsn := 'host = pg95
port = 5432
dbname = db',
);
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.23
pglogical.create_subscription(
subscription_name name,
provider_dsn text,
replication_sets text[],
synchronize_structure boolean,
synchronize_data boolean,
forward_origins text[],
apply_delay interval
);
Create
subscription
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.24
Check SELECT subscription_name, status
FROM pglogical.show_subscription_status();
subscription_name | status
------------------------+-------------
my_subscription | replicating
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.25
Repeat
CREATE EXTENSION pglogical;
SELECT pglogical.create_node (...'provider'...);
SELECT pglogical.create_node (...'subscriber'...);
SELECT pglogical.create_subscription(...);
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.26
Testing and
application
testing
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.27
Cutover/
Switch
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.28
Post-switch
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.29
Conclusions
• Pglogical is my preferred major upgrade method
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.30
Conclusions
• Start simple and test everything
TEST! TEST! TEST!
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.31
Conclusions
• Pglogical 3
● Replication slot failover support
● REPLICA IDENTITY FULL
● DDL
● Performance
● Kafka and Rabbitmq
● Partitions
● Conflict detection
● Conflict resolution
● No SUPERUSER
● Statistics
© Copyright EnterpriseDB Corporation, 2020. All rights reserved.32
Conclusions
• Kubernetes and Cloud Native friendly
Thank you!
Questions?
@irionr
www.enterprisedb.com/contact

Online Upgrade Using Logical Replication

  • 1.
    Online upgrade using logicalreplication Florin Irion 8 December 2020 #postgresbuild2020
  • 2.
  • 3.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.3 Agenda • PostgreSQL releases • Upgrade options • What is Pglogical • Major upgrades
  • 4.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.4 Why Upgrade? ● Security ● Features ● Dba/management ● Performance ● SQL standard
  • 5.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.5 Release Cadence
  • 6.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.6 EOL
  • 7.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.7 About Minor Updates
  • 8.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.8 About Major Upgrades ● Logical dump/restore ● Trigger-based replication (not anymore) - e.g. Londiste ● pg_upgrade ● Native logical streaming replication ○ publisher/subscriber ○ Pglogical extension
  • 9.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.9 About Major Upgrades ● Logical dump/restore ● Trigger-based replication (not anymore) - e.g. Londiste ● pg_upgrade ● Native logical streaming replication ○ publisher/subscriber ○ Pglogical extension
  • 10.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.10 Pglogical
  • 11.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.11 Pglogical vs Logical Replication
  • 12.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.12 Upgrading with pglogical
  • 13.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.13 What are we missing by using PostgreSQL 9.5? https://why-upgrade.depesz.com/
  • 14.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.14 Missing Features ● Parallel Aggregates ● Parallel sequential scans ● Declarative partitioning ● SCRAM Authentication ● Just In Time (JIT) compilation ● Parallel creation of index ● Stored Procedures ● Reindex concurrently
  • 15.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.15 Nomenclature and conventions ● Node -- Postgresql database instance ● Provider -- sending node ● Subscriber -- receiver node ● Replication Set -- rule ● Subscription -- one subscriber makes to the provider. ● pg95 pg13 -- my hostnames
  • 16.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.16 Requirements ● Primary key ● Table schema ● Table definition ● Constraints ● Global objects ● UNLOGGED and TEMPORARY ● DDL ○ replicate_ddl_command()
  • 17.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.17 Installation PostgreSQL 9.5: yum install postgresql95-pglogical PostgreSQL 13: yum install postgresql13-pglogical
  • 18.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.18 Configuration Postgresql.conf shared_preload_libraries = 'pglogical' wal_level = 'logical' max_worker_processes = 10 max_wal_senders = 10 max_replication_slots = 10
  • 19.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.19 Pg_hba.conf Local replication pglogical md5 Local dbname pglogical md5 Host replication pglogical pg13_ip_add/0 md5 Host dbname pglogical pg13_ip_add/0 md5 Authentication
  • 20.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.20 Create extension and nodes CREATE EXTENSION pglogical; SELECT pglogical.create_node ( node_name: = 'provider1', dsn: = 'host = pg95 port = 5432 dbname = db' ); CREATE EXTENSION pglogical; SELECT pglogical.create_node ( node_name: = 'subscriber1', dsn: = 'host = pg13 port = 5432 dbname = db' );
  • 21.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.21 Add tables and sequences SELECT pglogical.replication_set_add_all_tables ( set_name := 'default', schema_names := ARRAY ['public'] ); SELECT pglogical.replication_set_add_all_sequences ( set_name : = 'default', schema_names : = ARRAY ['public'] );
  • 22.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.22 Create subscription SELECT pglogical.create_subscription( subscription_name := 'my_subscription', provider_dsn := 'host = pg95 port = 5432 dbname = db', );
  • 23.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.23 pglogical.create_subscription( subscription_name name, provider_dsn text, replication_sets text[], synchronize_structure boolean, synchronize_data boolean, forward_origins text[], apply_delay interval ); Create subscription
  • 24.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.24 Check SELECT subscription_name, status FROM pglogical.show_subscription_status(); subscription_name | status ------------------------+------------- my_subscription | replicating
  • 25.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.25 Repeat CREATE EXTENSION pglogical; SELECT pglogical.create_node (...'provider'...); SELECT pglogical.create_node (...'subscriber'...); SELECT pglogical.create_subscription(...);
  • 26.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.26 Testing and application testing
  • 27.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.27 Cutover/ Switch
  • 28.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.28 Post-switch
  • 29.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.29 Conclusions • Pglogical is my preferred major upgrade method
  • 30.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.30 Conclusions • Start simple and test everything TEST! TEST! TEST!
  • 31.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.31 Conclusions • Pglogical 3 ● Replication slot failover support ● REPLICA IDENTITY FULL ● DDL ● Performance ● Kafka and Rabbitmq ● Partitions ● Conflict detection ● Conflict resolution ● No SUPERUSER ● Statistics
  • 32.
    © Copyright EnterpriseDBCorporation, 2020. All rights reserved.32 Conclusions • Kubernetes and Cloud Native friendly
  • 33.