Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
如何识别 Amazon Redshift 中的数据 API 查询错误?
我想确定我的 Amazon Redshift 数据 API 查询失败的原因。
解决方法
Amazon Redshift 数据 API 是异步的。您无需等待查询完成即可运行长时间运行的查询。
当查询失败时,查询的状态不会立即显示。使用 DescribeStatement API 操作来确定单个或多个查询失败的原因。
单个查询
识别语句 ID
要对 Amazon Redshift 集群运行单个查询,请先获取语句 ID。
要获取语句 ID,请运行 ExecuteStatement API 操作。以下示例命令通过 AWS Secrets Manager 进行身份验证,并对集群执行您的 SQL 语句:
aws redshift-data execute-statement --region us-east-1 --secret arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn --cluster-identifier redshift-cluster-1 --sql "select * from test_table;" --database dev
输出示例:
{ "ClusterIdentifier": "redshift-cluster-1", "CreatedAt": "2022-09-16T12:22:31.894000+05:30", "Database": "dev", "Id": "458c568d-717b-4f36-90bd-e642bfb06cbf", "SecretArn": "arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn" }
输出中的 Id 部分显示了语句 ID。
检查状态
要检查查询的状态,请使用 DescribeStatement 并输入语句 ID。
aws redshift-data describe-statement --id 458c568d-717b-4f36-90bd-e642bfb06cbf
输出示例:
{ "ClusterIdentifier": "redshift-cluster-1", "CreatedAt": "2022-09-16T12:22:31.894000+05:30", "Duration": -1, "Error": "ERROR: relation "test_table" does not exist", "HasResultSet": false, "Id": "458c568d-717b-4f36-90bd-e642bfb06cbf", "QueryString": "select * from test_table;", "RedshiftPid": 1074727629, "RedshiftQueryId": -1, "ResultRows": -1,< "ResultSize": -1, "SecretArn": "arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn", "Status": "FAILED", "UpdatedAt": "2022-09-16T12:22:32.365000+05:30" }
输出中的 Error(错误)部分显示以下错误: “ERROR: relation "test_table" does not exist”。
多个查询
识别语句 ID
要对 Amazon Redshift 集群运行多个查询,请先获取语句 ID。
要获取语句 ID,请使用 BatchExecuteStatement API 操作。请参阅以下示例:
aws redshift-data batch-execute-statement --region us-east-1 --secret-arn arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn --cluster-identifier redshift-cluster-1 --database dev --sqls "select * from test_table;" "select * from another_table;"
输出示例:
{ "ClusterIdentifier": "redshift-cluster-1", "CreatedAt": "2022-09-16T12:37:16.707000+05:30", "Database": "dev", "Id": "08b4b917-9faf-498a-964f-e82a5959d1cb", "SecretArn": "arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn" }
输出中的 Id 部分显示了语句 ID。
检查状态
要检查查询的状态,请使用 DescribeStatement 并输入语句 ID:
aws redshift-data describe-statement --id 08b4b917-9faf-498a-964f-e82a5959d1cb
输出示例:
{ "ClusterIdentifier ": "redshift-cluster-1 ", "CreatedAt ": "2022-09-16T12:37:16.707000+05:30 ", "Duration ": 0, "Error ": "Query #1 failed with ERROR: relation \ "test_table\" does not exist ", "HasResultSet ": false, "Id ": "08b4b917-9faf-498a-964f-e82a5959d1cb ", "RedshiftPid ": 1074705048, "RedshiftQueryId ": 0, "ResultRows ":-1, "ResultSize ": -1, "SecretArn ": "arn:aws:secretsmanager:us-east-1:123456789012:secret:myuser-secret-hKgPWn ", "Status ": "FAILED ", "SubStatements ": [ { "CreatedAt ": "2022-09-16T12:37:16.905000+05:30 ", "Duration ": -1, "Error ": "ERROR: relation \ "test_table\" does not exist ", "HasResultSet ": false, "Id ": "08b4b917-9faf-498a-964f-e82a5959d1cb:1", "QueryString ": "select * from test_table; ", "RedshiftQueryId ": -1, "ResultRows ": -1, "ResultSize ": -1, "Status ": "FAILED ", "UpdatedAt ": "2022-09-16T12:37:17.263000+05:30 " }, { "CreatedAt ": "2022-09-16T12:37:16.905000+05:30", "Duration ": -1, "Error ": "Connection or an prior query failed. ", "HasResultSet ": false, "Id ": "08b4b917-9faf-498a-964f-e82a5959d1cb:2 ", "QueryString ": "select * from another_table;", "RedshiftQueryId ": 0, "ResultRows ": -1, "ResultSize": -1, "Status ": "ABORTED ", "UpdatedAt ": "2022-09-16T12:37:17.263000+05:30 " } ], "UpdatedAt ": "2022-09-16T12:37:17.288000+05:30 " }
输出显示了多语句查询中每条单独 SQL 语句的状态。输出中的 Error(错误)部分显示了每条语句的错误。
要对数据 API 相关问题进行故障排除,请参阅 Amazon Redshift 数据 API 的问题排查。
**注意:**拥有与 ExecuteStatement 或 BatchExecuteStatement API 操作的运行者相同的 AWS Identity and Access Management (IAM) 角色或 IAM 权限的用户,可使用 DescribeStatement 对同一语句执行操作。如果其他用户想对同一 SQL 语句执行操作,则他们必须代入运行该 SQL 语句的用户的 IAM 角色。
有关详细信息,请参阅调用 Amazon Redshift 数据 API 时的注意事项。
监控数据 API 事件
Amazon EventBridge 会监控数据 API 事件。如果您将此信息发送到 AWS Lambda 函数,则该函数将连接到 Amazon Simple Notification Service (Amazon SNS) 以发送通知。
- 语言
- 中文 (简体)

相关内容
AWS 官方已更新 8 个月前