Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

pglogical

Updated on 2024-10-14 GMT+08:00

Introduction

The pglogical extension provides logical streaming replication for PostgreSQL using a publish/subscribe model.

pglogical is a logical replication system implemented entirely as a PostgreSQL extension. It is fully integrated and does not require triggers or external programs. It provides an efficient way to selectively replicate data.

For more information, see the official pglogical documentation.

Supported Versions

This extension is available to the latest minor versions of RDS for PostgreSQL 12 and later versions. You can run the following SQL statement to check whether your DB instance supports this extension:

SELECT * FROM pg_available_extension_versions WHERE name = 'pglogical';

If this extension is not supported, upgrade the minor version of your DB instance or upgrade the major version using dump and restore.

For details about the extensions supported by RDS for PostgreSQL, see Supported Extensions.

Features

Use cases supported are:

  • Upgrades between major versions (given the above restrictions)
  • Full database replication
  • Selective replication of sets of tables using replication sets
  • Data gather/merge from multiple upstream servers

Requirements:

  • The pglogical extension must be installed on both the provider and subscriber.
  • Tables on the provider and subscriber must have the same names and be in the same schema.
  • Tables on the provider and subscriber must have the same columns, with the same data types in each column.
  • Tables must have the same primary key. It is not recommended to add additional unique constraints other than the primary key.
  • To replicate multiple databases, you must set up individual provider/subscriber relationships for each. There is no way to configure replication for all databases in a PostgreSQL install at once.

Extension Installation and Uninstallation

  • Installing the extension
    select control_extension('create', 'pglogical');
  • Deleting the extension
    select control_extension('drop', 'pglogical');

For more information, see Installing and Uninstalling an Extension on the RDS Console and Installing and Uninstalling an Extension Using SQL Commands.

Basic Usage

To use the pglogical extension, you need to modify the configuration parameters.

wal_level = 'logical'

shared_preload_libraries = 'pglogical'

For details about how to modify the shared_preload_libraries parameter, see Modifying the shared_preload_libraries Parameter.

  1. To configure a logical streaming replication, create a provider node.
    SELECT pglogical.create_node(
        node_name := 'provider',
        dsn := 'host=127.0.0.1 port=5432 dbname=test user=provider_user'
    );
  2. To configure a replication set, add all tables in public to the default replication set.
    SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
    NOTE:

    Replication sets provide a mechanism to control which tables in the database will be replicated and which actions on those tables will be replicated.

    default indicates that all tables and all operations on these tables will be replicated.

    For more information about replication sets, see official pglogical documentation.

  3. Create a subscriber node. Once the provider node is configured, the subscriber can subscribe to it.
    SELECT pglogical.create_node(
        node_name := 'subscriber',
        dsn := 'host=127.0.0.1 port=5432 dbname=test user=subscriber_user'
    );
  4. Create a subscription on the subscriber. After the subscription is created, the synchronization and replication processes are started.
    SELECT pglogical.create_subscription(
        subscription_name := 'subscription',
        provider_dsn := 'host=providerhost port=5432 dbname=test user=provider_user'
    );
    SELECT pglogical.wait_for_subscription_sync_complete('subscription');

Advanced Usage

  1. Create a table to be replicated on the provider and subscriber, respectively.
    create table test(id int primary key, name text, reg_time timestamp);
    NOTE:

    The names and structures of the tables on the provider and subscriber must be the same.

  2. Insert data to the table on the provider.
    insert into test select generate_series(1,10000),'test',now();
  3. Add the table to the replication set on the provider.
    -- Adding all tables to the replication set
    SELECT pglogical.replication_set_add_all_tables('default', ARRAY['public']);
    -- Adding specified tables to the replication set
    SELECT pglogical.replication_set_add_table( set_name := 'default', relation := 'test',synchronize_data := true);
    NOTE:

    If you add all tables to the replication set, run the following statement on the subscriber to synchronize data. Otherwise, data cannot reach the subscriber and the subscription status is unknown.

    select pglogical.alter_subscription_synchronize('subscription1');

    If you add specified tables to the replication set, the tables are automatically synchronized by default.

  4. Verify that the table has been added to the replication set.
    select * from pglogical.replication_set_table ;
  5. Query the subscription status on the subscriber.
    select * from pglogical.show_subscription_table('subscription1','test');
  6. Check whether the table data is synchronized on the subscriber.
    select count(*) from test;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback