类型 json aws dms postgres 的无效输入语法

invalid input syntax for type json aws dms postgres

我是 运行 一项将所有数据从 postgres 10.4 迁移到 RDS postgres 10.4 的任务。 无法迁移具有 jsonb 列的 tables。 出错后,整个 table 变得 suspended.Table 仅包含 449 行。

我制定了以下错误政策,仍然整个 table 暂停。 "DataErrorPolicy": "IGNORE_RECORD", "DataTruncationErrorPolicy": "IGNORE_RECORD", "DataErrorEscalationPolicy": "SUSPEND_TABLE", “DataErrorEscalationCount”:1000,

我的期望是整个table应该被转移,如果有任何json错误它可以忽略记录。 我不知道为什么会出现此错误 'invalid input syntax for type json' ,我检查了所有 json 并且所有 json 都有效。

经过多次调试,这个错误已经被认为是TABLE错误,但是为什么?这就是为什么 table 被暂停,因为 TableErrorPolicy 是 'SUSPEND_TABLE'。 为什么此错误被视为 table 错误而不是记录错误?

DMS 是否不支持 JSONB 列,这就是我们出现以下错误的原因?

日志:-

2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Next table to load 'public'.'TEMP_TABLE' ID = 1, order = 0 (tasktablesmanager.c:1817)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Start loading table 'public'.'TEMP_TABLE' (Id = 1) by subtask 1. 
Start load timestamp 0005AE3F66381F0F (replicationtask_util.c:755)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: REPLICA IDENTITY information for table 'public'.'TEMP_TABLE': Query status='Success' Type='DEFAULT' 
Description='Old values of the Primary Key columns (if any) will be captured.' (postgres_endpoint_unload.c:191)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Unload finished for table 'public'.'TEMP_TABLE' (Id = 1). 449 rows sent. (streamcomponent.c:3485)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Table 'public'.'TEMP_TABLE' contains LOB columns, change working mode to default mode (odbc_endpoint_imp.c:4775)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Table 'public'.'TEMP_TABLE' has Non-Optimized Full LOB Support (odbc_endpoint_imp.c:4788)
2020-09-01T12:10:04 https://forums.aws.amazon.com/I: Load finished for table 'public'.'TEMP_TABLE' (Id = 1). 449 rows received. 0 rows skipped.
Volume transferred 190376. (streamcomponent.c:3770)
2020-09-01T12:10:04 https://forums.aws.amazon.com/E: RetCode: SQL_ERROR SqlState: 22P02 NativeError: 1 Message: ERROR: invalid input syntax for type json; 
Error while executing the query https://forums.aws.amazon.com/ (ar_odbc_stmt.c:2648)
2020-09-01T12:10:04 https://forums.aws.amazon.com/W: Table 'public'.'TEMP_TABLE' (subtask 1 thread 1) is suspended (replicationtask.c:2471)

编辑-调试多了,这个错误已经被认为是TABLE错误,但是为什么?

A​​WS DMS 将 PostgreSQL 中的 JSON 数据类型视为 LOB 数据类型列。这意味着使用受限 LOB 模式时的 LOB 大小限制适用于 JSON 数据。例如,假设有限 LOB 模式设置为 4,096 KB。在这种情况下,任何大于 4,096 KB 的 JSON 数据都会在 4,096 KB 限制处被截断,并且无法通过 PostgreSQL 中的验证测试。

参考:AWS DMS - JSON data types being truncated

更新: 您可以调整错误处理任务设置以跳过错误行,方法是将 DataErrorPolicy 的值设置为 IGNORE_RECORD 确定在记录级别出现与数据处理相关的错误时 AWS DMS 采取的操作。 数据处理错误的一些示例包括转换错误、转换错误和错误数据。默认值为 LOG_ERROR。 IGNORE_RECORD,任务继续,该记录的数据被忽略。

参考:AWS DMS - Error handling task settings

JSONB 列数据类型在目标数据库中必须可以为空。

注意 - 在我的例子中,将 JSONB 列设置为可为空后,此错误消失了。

如 AWS 文档中所述-

In this case, AWS DMS treats JSONB data as if it were a LOB column. During the full load phase of a migration, the target column must be nullable.

https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html#CHAP_Source.PostgreSQL.Prerequisites

https://aws.amazon.com/premiumsupport/knowledge-center/dms-error-null-value-column/

您提到您正在从 PostgreSQL 迁移到 PostgreSQL。使用 AWS DMS 有特定原因吗?

A​​WS 文档:https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html#CHAP_Source.PostgreSQL.Homogeneous

When you migrate from a database engine other than PostgreSQL to a PostgreSQL database, AWS DMS is almost always the best migration tool to use. But when you are migrating from a PostgreSQL database to a PostgreSQL database, PostgreSQL tools can be more effective.

...

We recommend that you use PostgreSQL database migration tools such as pg_dump under the following conditions:

  • You have a homogeneous migration, where you are migrating from a source PostgreSQL database to a target PostgreSQL database.
  • You are migrating an entire database.
  • The native tools allow you to migrate your data with minimal downtime.