Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 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 container in Serverless Containers
    • 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
    • Monitoring the status 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 to a database
    • Connecting to Managed Service for PostgreSQL from a PySpark job in Yandex Managed Service for Apache Spark™ using a Yandex Lockbox secret
    • Configuring permissions for access to a secret created by Connection Manager for a Managed Service for PostgreSQL user
      • Logical replication in PostgreSQL
      • Migrating a database to Managed Service for PostgreSQL
      • Migrating a database from Managed Service for PostgreSQL
      • Migrating a Managed Service for PostgreSQL cluster to another version
      • Creating an Amazon RDS logical replica 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
  • Logical replication specifics
  • Getting started
  • Configure Amazon RDS
  • Configure the target cluster and create a subscription
  • Migrate sequences
  • Delete the subscription and switch the workload to the target cluster.
  1. Tutorials
  2. Replication and migration
  3. Creating an Amazon RDS logical replica for PostgreSQL in Managed Service for PostgreSQL

Creating an Amazon RDS logical replica for PostgreSQL in Managed Service for PostgreSQL

Written by
Yandex Cloud
Updated at April 13, 2026
  • Required paid resources
  • Logical replication specifics
  • Getting started
  • Configure Amazon RDS
  • Configure the target cluster and create a subscription
    • Migrate sequences
    • Delete the subscription and switch the workload 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, allowing you to migrate data to the target cluster with minimal downtime. Logical replication is supported in Amazon RDS for PostgreSQL, starting from version 10.4.

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

To migrate a database from an Amazon RDS for PostgreSQL source cluster 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 switch the workload to the target cluster.

Required paid resourcesRequired paid resources

  • Managed Service for PostgreSQL cluster: computing resources allocated to hosts, storage and backup size (see Managed Service for PostgreSQL pricing).
  • Public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).

Logical replication specificsLogical replication specifics

  • Database schema and DDL changes are not replicated.

    Always apply schema changes on the subscription side first, and only then on the publication side.

  • SEQUENCES are not replicated.

    Data replication for a table includes serial columns and identity columns generated by sequences. However, the sequence on the subscriber side will retain its original starting value.

    Therefore, when switching to the subscriber database, update the sequence to the latest value:

    ALTER SEQUENCE serial RESTART WITH <new_value>;
    
  • By default, when you create a subscription, the system makes a full copy of data from the source tables.

    To speed up the copy process, create only the PRIMARY KEY first, postponing the creation of all other indexes until the copying is complete.

  • If a table has no primary key, replication will produce errors:

    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 enable the UPDATE and DELETE replication on tables with no primary key, change the REPLICA IDENTITY:

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

  • To prevent primary key violations when recreating a subscription, clear the tables in the target cluster first.

  • Check Managed Service for PostgreSQL logs for logical replication errors.

Getting startedGetting started

Create the required resources:

Manually
Terraform

Create a Managed Service for PostgreSQL cluster with public access to its hosts. For this operation, the following requirements apply:

  • The PostgreSQL version must be the same or higher than the version in the source cluster. Migration to an earlier PostgreSQL version is not supported.
  • The database name 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 your current working directory.

    This file describes:

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

    • pg_version: PostgreSQL version. This version must be the same or higher than the Amazon RDS version.
    • db_name: Database name in the target cluster. It must be the same as the source database name.
    • username and password: Database owner username and password.
    • Names and versions of PostgreSQL extensions used in Amazon RDS. To list all required extensions, uncomment and copy the extension section.
  7. Validate your Terraform configuration files using this command:

    terraform validate
    

    Terraform will display any configuration errors detected in your files.

  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 database instance must be publicly accessible: Public accessibility = yes.

  1. Set up logical replication.

    1. In the parameter group section of your database instance, specify the following setting:

      rds.logical_replication = 1
      
    2. Restart the cluster for the changes to take effect.

  2. Create a user with the rds_replication role. To do this, execute the following as the user with the rds_superuser role:

    CREATE ROLE <username> WITH LOGIN PASSWORD <password>;
    GRANT rds_replication TO <username>;
    
  3. Grant the SELECT privilege on all the tables included 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 it prevents editing the table list in the future.

  5. Add an ingress rule to the 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, i.e., a user created alongside the cluster, and users with the mdb_admin role for that cluster.

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

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

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

    Tip

    If you cannot create a subscription using this query, add sslrootcert=none to it.

    For details on creating subscriptions, see this PostgreSQL article.

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

    SELECT * FROM pg_subscription_rel;
    

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

Migrate sequencesMigrate sequences

To complete synchronization between the source and target clusters:

  1. Set the source cluster to read-only mode.

  2. Create a database dump including sequences:

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

    Note the *.*_seq pattern we use. If your source database has sequences that do not match this pattern, use a different pattern to export them.

    To learn more about patterns, see this PostgreSQL article.

  3. Restore the dump containing database sequences into your 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 switch the workload to the target cluster.Delete the subscription and switch the workload to the target cluster.

  1. Delete the subscription in the target cluster:

    DROP SUBSCRIPTION s_data_migration;
    
  2. Switch the workload to the target cluster.

Was the article helpful?

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