Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Managed Service for PostgreSQL
  • Getting started
    • All tutorials
    • Creating a PostgreSQL cluster for 1C
    • Creating a cluster of 1C:Enterprise Linux servers with a Managed Service for PostgreSQL cluster
    • Exporting a database to Yandex Data Processing
    • Searching for cluster performance issues
    • Performance analysis and tuning
    • Setting up a connection from a Serverless Containers container
    • Delivering data to Yandex Managed Service for Apache Kafka® using Yandex Data Transfer
    • Delivering data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Delivering data to Yandex Managed Service for Apache Kafka® using Debezium
    • PostgreSQL change data capture and delivery to YDS
    • Delivering data from Yandex Managed Service for Apache Kafka® using Yandex Data Transfer
    • Transferring data from Yandex Object Storage using Yandex Data Transfer
    • Configuring a fault-tolerant architecture in Yandex Cloud
    • Status monitoring of geographically distributed devices
    • Writing load balancer logs to PostgreSQL
    • Creating an MLFlow server for logging experiments and artifacts
    • Working with data using Query
    • Federated data queries using Query
    • Fixing string sorting issues after upgrading _glibc_
    • Writing data from a device into a database
      • Logical replication PostgreSQL
      • Migrating a database to Managed Service for PostgreSQL
      • Migrating a database from Managed Service for PostgreSQL
      • Creating a logical replica of Amazon RDS for PostgreSQL in Managed Service for PostgreSQL
      • Migrating a database from Yandex Managed Service for PostgreSQL to Yandex Object Storage
      • Migrating data from Yandex Managed Service for MySQL® to Managed Service for PostgreSQL using Yandex Data Transfer
      • Migrating data from Managed Service for PostgreSQL to Yandex Managed Service for MySQL® using Yandex Data Transfer
      • Migrating data from AWS RDS for PostgreSQL to Managed Service for PostgreSQL using Yandex Data Transfer
      • Migrating a database from Greenplum® to PostgreSQL
      • Migrating data from Managed Service for PostgreSQL to Managed Service for OpenSearch using Yandex Data Transfer
      • Asynchronously replicating data from PostgreSQL to ClickHouse®
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Required paid resources
  • Features of using logical replication
  • Getting started
  • Configure Amazon RDS
  • Configure the target cluster and create a subscription
  • Migrate sequences
  • Delete the subscription and transfer the load to the target cluster
  1. Tutorials
  2. Replication and migration
  3. Creating a logical replica of Amazon RDS for PostgreSQL in Managed Service for PostgreSQL

Creating a logical replica of Amazon RDS for PostgreSQL in Managed Service for PostgreSQL

Written by
Yandex Cloud
Updated at May 5, 2025
  • Required paid resources
  • Features of using logical replication
  • Getting started
  • Configure Amazon RDS
  • Configure the target cluster and create a subscription
    • Migrate sequences
    • Delete the subscription and transfer the load to the target cluster

You can use logical replication to migrate a database from an Amazon RDS for PostgreSQL source cluster to a Managed Service for PostgreSQL target cluster.

Logical replication uses the subscription mechanism. It allows you to migrate data to the target cluster with minimal downtime. Logical replication is available in Amazon RDS for PostgreSQL version 10.4 and higher.

Use logical replication if data migration using Yandex Data Transfer is not possible for any reason.

To migrate a database from an Amazon RDS source cluster for PostgreSQL to a Managed Service for PostgreSQL target cluster:

  1. Configure Amazon RDS.
  2. Configure the target cluster and create a subscription.
  3. Migrate sequences.
  4. Delete the subscription and transfer the load to the target cluster.

Required paid resourcesRequired paid resources

The support cost includes:

  • Managed Service for PostgreSQL cluster fee: Using computing resources allocated to hosts and disk space (see Managed Service for PostgreSQL pricing).
  • Fee for using public IP addresses for cluster hosts (see Virtual Private Cloud pricing).

Features of using logical replicationFeatures of using logical replication

  • Changes to the database schema and DDL are not replicated.

    First apply the new schema changes on the subscription side and then on the publication side.

  • Sequences (SEQUENCES) are not replicated.

    When a table is replicated, the data in the serial columns or ID columns generated by sequences is also replicated. However, the sequence on the subscriber side will preserve its starting value.

    If you switch to the subscriber database, restart the sequence using the latest value:

    ALTER SEQUENCE serial RESTART WITH <new_value>;
    
  • When you create a subscription, data from the source tables is fully copied.

    To accelerate the copying process, create only the primary key (PRIMARY KEY). Create all the other indexes after the copying is complete.

  • If a table does not have a primary key, errors will occur during replication:

    ERROR: 55000: cannot update table "<table_name>" because it does not have a replica identity and publishes updates
    HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
    

    To run the UPDATE and DELETE replications in tables without the primary key, change REPLICA IDENTITY:

    ALTER TABLE <table_name> REPLICA IDENTITY FULL;
    
  • External tables are not replicated.

  • If you need to recreate the subscription, clear the tables in the target cluster to prevent primary key constraint errors.

  • To view errors relating to logical replication, see the Managed Service for PostgreSQL logs.

Getting startedGetting started

Create the required resources:

Manually
Terraform

Create a Managed Service for PostgreSQL cluster with public host access. In this case, the following applies:

  • The PostgreSQL version must be the same or higher than in the source cluster. You cannot perform migration while downgrading PostgreSQL version.
  • The name of the database must be the same as in the source cluster.
  • Enable the same PostgreSQL extensions as in the source database.
  1. If you do not have Terraform yet, install it.

  2. Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.

  3. Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it.

  4. Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.

  5. Download the logical-replica-amazon-rds-to-postgresql.tf configuration file to the same working directory.

    This file describes:

    • Network.
    • Subnet.
    • Security group and rule enabling cluster connections.
    • Managed Service for PostgreSQL cluster with public internet access.
  6. Specify the infrastructure parameters in the logical-replica-amazon-rds-to-postgresql.tf configuration file under locals:

    • pg_version: PostgreSQL version. It must be not lower than the Amazon RDS version.
    • db_name: Target cluster database name. It must be the same as the source database name.
    • username and password: Name and user password of the database owner.
    • Names and versions of PostgreSQL extensions used in Amazon RDS. Uncomment and multiply the extension section.
  7. Make sure the Terraform configuration files are correct using this command:

    terraform validate
    

    If there are any errors in the configuration files, Terraform will point them out.

  8. Create the required infrastructure:

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console.

Configure Amazon RDSConfigure Amazon RDS

Warning

The DB instance must have public access enabled: Public accessibility = yes.

  1. Set up logical replication.

    1. In the parameter group of your DB instance, set the parameter as follows:

      rds.logical_replication = 1
      
    2. Restart the cluster to apply the changes.

  2. Create a separate user with the rds_replication role. To do this, execute the following on behalf of the user with the rds_superuser role:

    CREATE ROLE <username> WITH LOGIN PASSWORD <password>;
    GRANT rds_replication TO <username>;
    
  3. Grant the SELECT privilege for all the tables involved in the replication:

    GRANT SELECT ON <table_1>, <table_2>, ..., <table_n> TO <username>;
    
  4. Create a publication:

    CREATE PUBLICATION pub FOR TABLE <table_1>, <table_2>, ..., <table_n>;
    

    Note

    We do not recommend using the FOR ALL TABLES publications as you will not be able to edit the table list later.

  5. Add a rule for incoming traffic in VPC security groups. For example:

    protocol: tcp, port: 5432, source: 84.201.175.90/32
    

    Where 84.201.175.90 is a public IP address.

Configure the target cluster and create a subscriptionConfigure the target cluster and create a subscription

In Managed Service for PostgreSQL clusters, subscriptions can be used by the database owner (a user created together with the cluster) and users with the mdb_admin or mdb_superuser role for the cluster.

  1. Optionally, assign the mdb_admin or mdb_superuser role to the Managed Service for PostgreSQL cluster user.

  2. Create a subscription with the source cluster connection string:

    CREATE SUBSCRIPTION s_data_migration CONNECTION 'host=<source_cluster_address> port=<port> user=<username> sslmode=prefer dbname=<DB_name>' PUBLICATION pub;
    

    To learn more about creating subscriptions, see the PostgreSQL documentation.

  3. To get the replication status, check the pg_subscription_rel folders.

    SELECT * FROM pg_subscription_rel;
    

    r in the srsubstate field means that the replication is over.

Migrate sequencesMigrate sequences

To complete synchronization of the source cluster and the target cluster:

  1. Switch the source cluster to read-only.

  2. Create a dump with sequences:

    pg_dump --host=<source_cluster_address> \
            --username=<username> \
            --port=<port> \
            --dbname=<DB_name> \
            --data-only \
            --table='*.*_seq' > /tmp/seq-data.sql
    

    Pay attention to the used pattern, *.*_seq. If the database you are migrating has sequences that do not match this pattern, enter a different pattern to export them.

    For more information about patterns, see the PostgreSQL documentation.

  3. Restore the dump with sequences in the target cluster:

    psql \
        --host=<master_host_FQDN_of_target_cluster> \
        --username=<username> \
        --port=6432 \
        --dbname=<DB_name> < /tmp/seq-data.sql
    

Delete the subscription and transfer the load to the target clusterDelete the subscription and transfer the load to the target cluster

  1. Delete the subscription in the target cluster:

    DROP SUBSCRIPTION s_data_migration;
    
  2. Transfer the load to the target cluster.

Was the article helpful?

Previous
Migrating a database from Managed Service for PostgreSQL
Next
Migrating a database from Yandex Managed Service for PostgreSQL to Yandex Object Storage
© 2025 Direct Cursus Technology L.L.C.