mysql - AWS DMS - MYSQL 上的 CDC 作为源端点的微秒级精度

标签 mysql database amazon-web-services amazon-s3 aws-dms

我正在使用 AWS DMS 从作为源端点的 MYSQL 和作为目标端点的 S3 迁移数据。
我想跟踪来自源的更新,所以在配置期间,我启用了 TimestampColumnName 属性(列名称:event_timestamp)。
在结果(如下所列)中,我得到了记录/事件的时间戳,但不是微秒精度。

我希望微秒级精度在此基础上构建序列逻辑。
我已经调查了源端点和目标的属性,但没有得到想要的结果。这是示例输出:

enter image description here .

如果我缺少任何属性,有人可以看一下并提出建议吗?
输出格式:我在 S3 中的文件是 Parquet 。

最佳答案

不幸的是,AWS DMS S3 TimestampColumnName从 MySQL 源加载更改数据捕获 (CDC) 添加的 DATETIME 列将有 strong>只有秒精度

因为 MySQL 二进制日志中的事务时间戳只有几秒


最简单的解决方案是向 MySQL 表添加新列 - timestamp with microsecond precision在插入或/和更新时设置默认值 automatically并将此列用作 event_timestamp

ts TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

另外,在 AWS DMS 中检查到 S3 setting ParquetTimestampInMillisecondFalse(或不存在/未设置,默认为 false)。


AWS DMS S3 TimestampColumnName 设置将带有时间戳的列添加到输出。

在“静态”读取中 - 它将生成当前时间戳:

For a full load, each row of this timestamp column contains a timestamp for when the data was transferred from the source to the target by DMS.

对于 CDC,它将从数据库事务日志中读取事务时间:

For a change data capture (CDC) load, each row of the timestamp column contains the timestamp for the commit of that row in the source database.

其精度将是数据库事务日志中的时间戳之一:

...the rounding of the precision depends on the commit timestamp supported by DMS for the source database.

CDC 模式本质上是 replication .应适当配置源数据库以写入此类事务日志。数据库写入此日志事务信息以及事务/提交时间戳。

对于 MySQL,这是 the binary log .和 MySQL binlog timestamp只有 32 位 - 只需几秒钟。


此外,此交易时间戳可能并不总是与交易的实际顺序一致,或者订单更改实际提交于(link 1link 2)。

关于mysql - AWS DMS - MYSQL 上的 CDC 作为源端点的微秒级精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59638242/

相关文章:

php - 使用 php 和 mysql 的登录页面无法正常工作

php - 从地址获取州和县

python - AWS 将 MQTT 消息存储到 DynamoDB

mysql - ComboBox 未填充 MySQL 查询结果 - 如何解决该问题?

java - SQL "missing in or out parameter at index"

python - 对 python 变量进行排序以匹配另一个变量

php - 比较两个字符串时解码符号

amazon-web-services - 如何在 CloudFormation 脚本中获取当前日期?

amazon-web-services - 在 aws ECS 集群中显示 docker 容器日志

php - 无法在 MySQL PHP 表单中显示记录字段更新结果