PostgreSQL
UDTS supports PostgreSQL as a data transfer source/target, supporting versions 9.4 to 16.x.
Prerequisites
- For incremental synchronization, users need to enable the data log, set
wal_leveltological, andmax_replication_slotsshould be greater than 1. - The tables to be migrated must have a primary key or a unique index, otherwise, duplicate data may occur. Refer to Handling Incremental Synchronization for Tables without Primary Key or Unique Index for more details.
Required Permissions
| Type | Source Database | Target Database |
|---|---|---|
| Full | SELECT | Owner permission of the database to be migrated, or rolcreatedb permission |
| Full+Incremental | SELECT,REPLICATION | Owner permission of the database to be migrated, or rolcreatedb permission |
Function Limitations
- A “Full+Incremental” task can only synchronize one database. If multiple databases need synchronization, a separate task must be created for each database.
- Synchronization objects only support data tables and do not currently support DDL statement synchronization. If synchronization of DDL statements is needed, manually execute the corresponding DDL operations on the target database and then restart the data synchronization task.
- Incremental synchronization does not support the synchronization of GEOMETRY, TSQUERY, TSVECTOR, TXID_SNAPSHOT data types.
- Due to database characteristics, migration from a higher version to a lower version is not supported.
Notes
Handling Incremental Synchronization for Tables without Primary Key or Unique Index
- If the table to be migrated has neither a primary key nor a unique index, execute
ALTER TABLE tb_xxx REPLICA IDENTITY FULL, otherwise incremental migration cannot be performed. - If the table to be migrated has no primary key but has a unique index such as
idx_unq_name, there are two methods:
1. Similar to handling tables without a primary key, execute ALTER TABLE tb_xxx REPLICA IDENTITY FULL. This method is less efficient for replication.
2. Manually specify the unique index for replication, ALTER TABLE tb_xxx REPLICA IDENTITY USING INDEX idx_unq_name, which is more efficient for replication.- If the table to be migrated has no primary key but has a unique index, and the unique index used for replication changes during the task’s operation, the task needs to be restarted, or it may fail.
Incremental Synchronization Progress Saving and Replication Slot Explanation
- During incremental synchronization, UDTS will create a
public.udts_pgsync_progressdata table in the target database to record synchronization progress and other information. Do not delete it during synchronization, or the task may fail. - During incremental synchronization, UDTS will create a
replication slotwith the prefixudts_in the source database for data replication. - After clients pause the synchronization task, due to the existence of the prefix
udts_replication slot in the source database for data replication, the WAL cannot be cleaned, causing continuous disk usage. If the task needs to be stopped for a long time, it is recommended to delete this slot and the task. - After a client deletes a task, the corresponding slot needs to be manually deleted in the source database. The steps are as follows:
Steps:
1. For example, the database migrated by UDTS incrementally is db_service_car.
2. Execute select * from pg_replication_slots, and the results are as follows:
-------------------------------------------------------------------------------------------------------------------------------
| slot_name | plugin | slot_type | datoid | database | active |
-------------------------------------------------------------------------------------------------------------------------------
| udts_dd27ef9195294b49a5d424eda8f399f7 | test_decoding | logical | 4839920 | db_service_car | f |
| udts_050a1f4b1cc84b4bb6460e5477ec3d79 | test_decoding | logical | 2695822 | db_service_xxx | t |
-------------------------------------------------------------------------------------------------------------------------------
3. Find the slot_name with the database as db_service_car and prefix udts.
4. Execute select pg_drop_replication_slot('udts_dd27ef9195294b49a5d424eda8f399f7');
5. Execute select * from pg_replication_slots again to confirm deletion.PostgreSQL Form Filling
Data Source Form
| Parameter Name | Description |
|---|---|
| Address Type | Provides three types of addresses: Intranet, Internet, and Dedicated Line. Intranet requires VPC and subnet information. Internet supports both IP and domain name. |
| Port | PostgreSQL connection port |
| Username | PostgreSQL connection username |
| Password | Password for the corresponding PostgreSQL database user |
| Database Name | The name of the PostgreSQL database to be migrated |
| Table Name | Optional. Name of the PostgreSQL table to be transferred. If not filled, the entire database is migrated. If filled, the specified table is migrated. Refer to Table Name Filling Rules for details. |
| Maximum Rate | For Internet/Dedicated Line, the rate range is 1-256 MB/s, default 40 MBps (i.e., 320 Mbps); for Intranet, the rate range is 1-1024 MB/s, default 80 MBps (i.e., 640 Mbps) |
Transfer Target Form
| Parameter Name | Description |
|---|---|
| Address Type | Currently only supports Intranet |
| Port | PostgreSQL connection port |
| Username | PostgreSQL connection username |
| Password | Password for the corresponding PostgreSQL database user |
| Maximum Rate | For Intranet, the rate range is 1-1024 MB/s, default 80 MBps (i.e., 640 Mbps) |
Table Name Filling Rules
-
- Table names only support characters from [a-z][A-Z][0-9] and _.
-
- Multiple table names are separated by commas.
-
- If no schema is added to the table name, the default
public.schema is appended.
- If no schema is added to the table name, the default
-
- Filling in table names as
public.tb_test01,schema01.tb_test02indicates only migrating these two tables:public.tb_test01,schema01.tb_test02.
- Filling in table names as