我已经从Oracle到Postgres建立了AWS DMS CDC任务。选中创建恢复表复选框,并且我在设置文件中有Users
+----+------+
| Id | Name |
+----+------+
| 1 | John |
+----+------+
Subscriptions
+----+--------+-----------+
| Id | userId | data |
+----+--------+-----------+
| 1 | 1 | some data |
+----+--------+-----------+
| 2 | 1 | some data |
+----+--------+-----------+
Payments
+----+----------------+--------+
| Id | subscriptionId | amount |
+----+----------------+--------+
| 1 | 1 | 30 |
+----+----------------+--------+
| 2 | 2 | 50 |
+----+----------------+--------+
它通过以下设置在目标数据库上创建"TaskRecoveryTableEnabled": true
表
awsdms_txn_state
请注意,存在some_user@db => \d awsdms_txn_state
Table "some_user.awsdms_txn_state"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+---------
SERVER_NAME | character varying(384) | | not null |
TASK_NAME | character varying(384) | | not null |
STATE_TIME | timestamp without time zone | | not null |
CHECKPOINT | character varying(3072) | | not null |
Indexes:
"awsdms_txn_state_task_recovery_index" UNIQUE, btree ("SERVER_NAME", "TASK_NAME")
个唯一索引
现在,在CDC任务运行期间,它连续失败并出现以下错误:
awsdms_txn_state_task_recovery_index
原因显而易见。它尝试将记录插入到该表中,而该记录在此英国索引上失败
删除索引可以“解决”问题,并开始向该表添加新行
[TARGET_APPLY ]E: Failed to execute statement: '' [1022502] (ar_odbc_stmt.c:2478)
[TARGET_APPLY ]E: RetCode: SQL_ERROR SqlState: 23505 NativeError: 1 Message: ERROR: duplicate key value violates unique constraint "awsdms_txn_state_task_recovery_index";, Error while executing the query [1022510] (ar_odbc_stmt.c:2484)
[TARGET_APPLY ]E: Error executing command [1022502] (streamcomponent.c:1676)
问题:
some_user@db => select * from awsdms_txn_state;
SERVER_NAME | TASK_NAME | STATE_TIME | CHECKPOINT
-----------------------+----------------------------+---------------------+--------------------------------------------------------------------------------------------------
localhost.localdomain | NM6KQWHZQL5RLONADKKONM5MCA | 2019-01-28 15:44:48 | checkpoint:V1#318064#0000002D0ABC5EB5010000010001458E00099A29016C00000000002D0ABC5D2B#0#0#*#0#73
some_user@db => drop index awsdms_txn_state_task_recovery_index;
DROP INDEX
some_user@db => \d awsdms_txn_state
Table "some_user.awsdms_txn_state"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+---------
SERVER_NAME | character varying(384) | | not null |
TASK_NAME | character varying(384) | | not null |
STATE_TIME | timestamp without time zone | | not null |
CHECKPOINT | character varying(3072) | | not null |
some_user@db => select * from awsdms_txn_state;
SERVER_NAME | TASK_NAME | STATE_TIME | CHECKPOINT
-----------------------+----------------------------+---------------------+--------------------------------------------------------------------------------------------------
localhost.localdomain | NM6KQWHZQL5RLONADKKONM5MCA | 2019-01-28 15:44:48 | checkpoint:V1#318064#0000002D0ABC5EB5010000010001458E00099A29016C00000000002D0ABC5D2B#0#0#*#0#73
localhost.localdomain | NM6KQWHZQL5RLONADKKONM5MCA | 2019-02-05 11:24:02 |
localhost.localdomain | NM6KQWHZQL5RLONADKKONM5MCA | 2019-02-05 11:24:09 |
(3 rows)
表的正确状态是什么?
它是否应该始终包含单个记录,而CDC现在有一个试图插入新行而不是UPDATE的错误?
还是表ddl中存在错误,并且不应定义任何唯一索引?