All Products
Search
Document Center

PolarDB:Overview of upgrading an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster

Last Updated:Jul 03, 2024

You can upgrade an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster. This topic provides an overview of the upgrade, introducing the available upgrade methods and benefits and the prerequisites, limits, and billing rules for the upgrade.

About the upgrade

PolarDB allows you to upgrade an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster. The destination PolarDB cluster uses the accounts, databases, and IP address whitelists of the source ApsaraDB RDS for PostgreSQL instance.

You can upgrade an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster that runs the same or a different PostgreSQL version. For example, you can upgrade an ApsaraDB RDS for PostgreSQL 11 instance to a PolarDB for PostgreSQL 14 cluster.

Note

You can perform logical migration by using Data Transmission Service (DTS) to upgrade an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster.

Logical migration

Create a data synchronization task in the DTS console to migrate the schemas and full data of the source ApsaraDB RDS for PostgreSQL instance to the destination PolarDB for PostgreSQL cluster. Then, make sure that incremental data is synchronized to the destination cluster.

Benefits

The upgrade provides the following benefits:

  • The upgrade supports switchover with endpoints. Your applications can seamlessly connect to the destination PolarDB cluster without changes to the connection settings.

  • The migration is free of charge. You are charged only for the destination PolarDB cluster.

  • No data loss occurs during the migration.

  • Incremental data migration is supported. The service downtime is no more than 10 minutes.

  • Hot migration is supported. Only one transient disconnection occurs during the data migration process. The transient disconnection occurs when business is switched over from the ApsaraDB RDS for PostgreSQL instance to the PolarDB cluster.

  • Migration rollbacks are supported. If a migration fails, the migration can be rolled back within 10 minutes.

Prerequisites

  • You can upgrade an ApsaraDB RDS for PostgreSQL instance only to a PolarDB for PostgreSQL 14 cluster.

  • If a trigger is created in the source ApsaraDB RDS for MySQL instance, delete the trigger and then click Continue. Alternatively, you can click Cancel and then manually create a data synchronization task in the DTS console. For more information, see Synchronize data from an ApsaraDB RDS for PostgreSQL instance to a PolarDB for PostgreSQL cluster.

  • If Secure Sockets Layer (SSL) or transparent data encryption (TDE) is enabled for the endpoints of the source ApsaraDB RDS for PostgreSQL instance, you cannot upgrade the instance to a PolarDB cluster.

  • The source ApsaraDB RDS for PostgreSQL instance must also meet the following conditions for the upgrade. If a condition is not met, the condition is displayed on the PolarDB upgrade page.

    • Databases must be created in the ApsaraDB RDS for PostgreSQL instance.

    • The account names of the ApsaraDB RDS for PostgreSQL instance cannot use formats that are not supported by the PolarDB for PostgreSQL cluster.

    • The AliyunServiceRoleForPolarDB service-linked role must be created.

    • The value of the max_replication_slots parameter must be greater than the total number of two-way DTS links required, as indicated by the number of databases involved.

    • The value of the max_wal_senders parameter must be greater than the total number of two-way DTS links required, as indicated by the number of databases involved.

    • The number of databases must be less than or equal to 30. You can create up to 30 two-way DTS links.

    • The value of the wal_level kernel parameter must be logical.

Limits

  • You can upgrade an ApsaraDB RDS for PostgreSQL instance only to a PolarDB for PostgreSQL cluster of the same version or a later version. You cannot downgrade an ApsaraDB RDS for PostgreSQL instance. For example, you cannot upgrade an ApsaraDB RDS for PostgreSQL 14 instance to a PolarDB for PostgreSQL 11 cluster.

  • The upgrade is subject to the following limits:

    • Cross-region data migration is not supported.

    • You cannot configure the parameters of the source ApsaraDB RDS for PostgreSQL instance during data migration.

    • The source ApsaraDB RDS for PostgreSQL instance is subject to the limits described in the following table.

      Item

      Description

      Limits on the source instance

      • The tables that you want to synchronize must have PRIMARY KEY or UNIQUE constraints, and all fields must be unique. Otherwise, the destination database may contain duplicate data records.

      • If you select tables as the objects to be synchronized and you want to modify the tables, such as renaming tables or columns in the destination database, you can synchronize up to 5,000 tables in a single data synchronization task. If you run a task to synchronize more than 5,000 tables, a request error occurs. In this case, we recommend that you configure multiple tasks to synchronize the tables or configure a task to synchronize the entire database.

      • The following requirements for write-ahead logging (WAL) logs must be met:

        • The wal_level parameter must be set to logical.

        • If you perform only incremental data synchronization, the WAL logs of the source database must be stored for more than 24 hours. If you perform full data synchronization and incremental data synchronization, the WAL logs of the source database must be stored for at least seven days. Otherwise, DTS may fail to obtain the WAL logs and the task may fail. In special cases, data inconsistency or loss may occur. After full data synchronization is complete, you can set the retention period to more than 24 hours. Make sure that you specify the retention period of WAL logs based on the preceding requirements. Otherwise, the service reliability or performance in the Service Level Agreement (SLA) of DTS may not be guaranteed.

      • During data synchronization, do not modify the endpoints or zone of the ApsaraDB RDS for PostgreSQL instance. Otherwise, the data synchronization task fails.

      • If the source database has long-running transactions and incremental data is synchronized in the data synchronization task, the WAL logs generated before the long-running transactions in the source database are committed may be accumulated. As a result, the disk space of the source database may become insufficient.

    • Limits on SQL statements:

      Type

      SQL statement

      DML

      INSERT, UPDATE, and DELETE

      DDL

      • DDL operations can be synchronized only by data synchronization tasks that are created after October 1, 2020.

        Important
      • If you use a privileged account for the ApsaraDB RDS for PostgreSQL instance and the instance runs a minor engine version of 20210228 or later, you can synchronize the following DDL statements. For information about how to update the minor engine version, see Update the minor engine version.

        • CREATE TABLE and DROP TABLE

        • ALTER TABLE (including RENAME TABLE, ADD COLUMN, ADD COLUMN DEFAULT, ALTER COLUMN TYPE, DROP COLUMN, ADD CONSTRAINT, ADD CONSTRAINT CHECK, and ALTER COLUMN DROP DEFAULT)

        • TRUNCATE TABLE (the source database runs PostgreSQL 11 or later)

        • CREATE INDEX ON TABLE

        Important
        • You cannot synchronize additional information in DDL statements, such as CASCADE or RESTRICT.

        • You cannot synchronize DDL statements from a session that executes the SET session_replication_role = replica statement.

        • If multiple SQL statements committed by the source database at the same time contain both DML and DDL statements, DTS does not synchronize the DDL statements.

        • If multiple SQL statements committed by the source database at the same time contain DDL statements for objects that are not synchronized, the DDL statements are not synchronized.

    • Other limits:

      Item

      Description

      Other limits

      • Each data synchronization task can synchronize only one database. For multiple databases, a separate data synchronization task is configured for each database.

      • If you create a table in the schema or execute the RENAME statement to recreate a table during a schema-level synchronization, you must execute the ALTER TABLE schema.table REPLICA IDENTITY FULL; statement before you write data to the table to ensure data consistency. When you execute this statement, we recommend that you do not lock the table. Otherwise, a deadlock occurs.

        Note
        • Replace schema and table in the preceding statement with the actual schema name and table name when you perform the operation.

        • We recommend that you perform the operation during off-peak hours.

      • DTS creates the following temporary tables in the source database to obtain the DDL statements of incremental data, the schemas of incremental tables, and the heartbeat information. During data synchronization, do not delete temporary tables in the source database. Otherwise, exceptions occur. After the DTS instance is released, temporary tables are automatically deleted.

        public.dts_pg_class, public.dts_pg_attribute, public.dts_pg_type, public.dts_pg_enum, public.dts_postgres_heartbeat, public.dts_ddl_command, and public.dts_args_session.

      • To ensure that the latency of data synchronization is accurate, DTS adds a heartbeat table named dts_postgres_heartbeat to the source database.

      • During data synchronization, DTS creates a replication slot in the source database to replicate data. The replication slot is prefixed with dts_sync_. DTS automatically clears historical replication slots every 120 minutes to reduce storage usage.

        Note
        • DTS automatically deletes the replication slot after the instance is released. If you change the password of the database or delete the IP address whitelists of DTS during synchronization, the replication slot cannot be automatically deleted. In this case, you must manually delete the replication slot from the source database. If you do not delete the replication slot, the replication slot continues to accumulate storage usage. This may result in the unavailability of the ApsaraDB RDS for PostgreSQL instance.

        • If the data synchronization task is released or fails, DTS automatically clears the replication slot. If a primary/secondary switchover is performed in the source PostgreSQL database, you must log on to the secondary database to clear the replication slot.

      • Before you synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours. During initial full data synchronization, DTS uses read and write resources of the source and destination databases. This may increase the loads on the database servers.

      • During full data synchronization, concurrent INSERT operations cause fragmentation in the tables of the destination database. After full data synchronization is complete, the tablespace of the destination database is larger than that of the source database.

      • For table-level data synchronization, if data is written to the destination database by using only DTS, you can use Data Management (DMS) to perform online DDL operations. For more information, see Perform lock-free DDL operations.

      • During data synchronization, we recommend that you use only DTS to write data to the destination. This prevents data inconsistency between the source and destination databases. For example, if you use tools other than DTS to write data to the destination database, data loss may occur in the destination database when you use DMS to perform online DDL operations.

      • DTS does not check the validity of metadata such as sequences. You must manually check the validity of metadata.

      • After your workloads are switched to the destination database, new sequences do not increment from the maximum value of the sequences in the source database. Therefore, you must query the maximum value of the sequences in the source database before you switch your workloads to the destination database. Then, you must specify the queried maximum value as the initial value of the sequences in the destination database. You can execute the following statements to query the maximum value of the sequences in the source database:

        do language plpgsql $$
        declare
          nsp name;
          rel name;
          val int8;
        begin
          for nsp,rel in select nspname,relname from pg_class t2 , pg_namespace t3 where t2.relnamespace=t3.oid and t2.relkind='S'
          loop
            execute format($_$select last_value from %I.%I$_$, nsp, rel) into val;
            raise notice '%',
            format($_$select setval('%I.%I'::regclass, %s);$_$, nsp, rel, val+1);
          end loop;
        end;
        $$;

Billing rules

The following billing rules apply to the upgrade:

You are charged for the PolarDB cluster and the data synchronization tasks on DTS. However, the upgrade feature is in the free-trial phase. No fees are generated for a synchronization task within 30 days after the task is created. The following table describes the billing rules.

Synchronization type

Billing rule

Schema synchronization and full data synchronization

No fees are generated for a synchronization task within 30 days after the task is created.

After 30 days, the task is cancelled. No fees are generated.

Note

You can log on to the PolarDB console and view the remaining validity period of the synchronization task in the RDS Migration section of the Basic Information page.

Incremental data synchronization

Switchover with endpoints (connection changes not required)

When you upgrade an ApsaraDB RDS for PostgreSQL instance to a PolarDB cluster, you can select Switch with Endpoints (Connection Changes Not Required). Then, the system exchanges the endpoints between the ApsaraDB RDS for PostgreSQL instance and the PolarDB cluster. In this case, you do not need to modify the configurations of your applications to connect to the PolarDB cluster. The following figure shows the rules for exchanging endpoints between the RDS instance and the PolarDB cluster.

image

To switch with endpoints, take note of the following points:

  • Only the endpoints of the ApsaraDB RDS for PostgreSQL instance and the PolarDB cluster are exchanged. The other configurations such as the vSwitches and virtual IP addresses are not exchanged.

  • Endpoints can be exchanged only if the source ApsaraDB RDS for PostgreSQL instance and the destination PolarDB cluster have the endpoints. By default, only the primary endpoints in the internal network can be exchanged.

  • The primary endpoints of the ApsaraDB RDS for PostgreSQL instance and the PolarDB cluster are exchanged during the switchover with endpoints. You can choose whether to exchange the dedicated proxy endpoints of the ApsaraDB RDS for PostgreSQL instance with the default cluster endpoints of the PolarDB cluster, and the read-only endpoints of the ApsaraDB RDS for PostgreSQL instance with the custom endpoints of the PolarDB cluster based on your business requirements. A PolarDB cluster can have up to seven cluster endpoints. Therefore, up to seven dedicated proxy endpoints or read-only endpoints of the ApsaraDB RDS for PostgreSQL instance can be exchanged with the cluster endpoints of the PolarDB cluster.

  • If you want to use other endpoints, create the endpoints before the switchover. For information about how to create endpoints for a PolarDB cluster, see View or apply for an endpoint. For more information about how to create endpoints for an ApsaraDB RDS for PostgreSQL instance, see Configure endpoints for an RDS instance.

  • The ports are not exchanged between the ApsaraDB RDS for PostgreSQL instance and the PolarDB cluster during the switchover with endpoints. Make sure that the ports of the ApsaraDB RDS for PostgreSQL instance are the same as the ports of the PolarDB cluster except for custom endpoint ports. For information about how to modify a port, see View and manage instance endpoints and ports.

  • After the endpoints are exchanged, issues may occur due to the expiration of the Domain Name System (DNS) cache data. The databases in the PolarDB cluster may fail to be connected or support only read operations. We recommend that you refresh the DNS cache data of your server to fix this issue.

  • If you want to use DMS to log on to the PolarDB database after the endpoints are exchanged, use the latest version of DMS and the cluster ID to log on to the database.